viwmfs.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * viwmfs.c
  3. * Copyright © 2008, 2009 Martin Duquesnoy <xorg62@gmail.com>
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above
  13. * copyright notice, this list of conditions and the following disclaimer
  14. * in the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the name of the nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #include "wmfs.h"
  33. vicmd_to_uicb vicmd[] =
  34. {
  35. {"r", "reload"},
  36. {"q", "quit"},
  37. {"t", "tag"},
  38. {"tn", "tag_next"},
  39. {"tp", "tag_prev"},
  40. {"l", "set_layout"},
  41. {"layout", "set_layout"},
  42. {"ln", "layout_next"},
  43. {"lp", "layout_prev"},
  44. {"s", "screen_select"},
  45. {"screen", "screen_select"},
  46. {"sn", "screen_next"},
  47. {"sp", "screen_prev"},
  48. {"cc", "client_kill"},
  49. {"ct", "tag_transfert"},
  50. {"cn", "client_next"},
  51. {"cp", "client_prev"},
  52. {"csn", "client_swap_next"},
  53. {"csp", "client_swap_prev"},
  54. {"mwf", "set_mwfact"},
  55. {"mwfact", "set_mwfact"},
  56. {"nmaster", "set_nmaster"},
  57. {"tm", "toggle_max"},
  58. {"tf", "toggle_free"},
  59. };
  60. void
  61. viwmfs_help(void)
  62. {
  63. int i;
  64. char s[20];
  65. printf("ViWMFS commands list:\n");
  66. for(i = 0; i < LEN(vicmd); ++i)
  67. {
  68. memset(s, ' ', sizeof(s));
  69. s[15 - strlen(vicmd[i].cmd)] = '\0';
  70. printf(" :%s%s %s\n", vicmd[i].cmd, s, vicmd[i].uicb);
  71. }
  72. return;
  73. }
  74. void
  75. viwmfs(int argc, char **argv)
  76. {
  77. int i;
  78. char *cmd, str[256] = { 0 };
  79. Bool e;
  80. if(!argc)
  81. return;
  82. if(argc > 3)
  83. {
  84. for(i = 2; i < argc; ++i)
  85. {
  86. strcat(str, argv[i]);
  87. if(*(str + strlen(str) - 1) != ':')
  88. strcat(str, " ");
  89. }
  90. }
  91. else
  92. strcpy(str, argv[2]);
  93. if(!strcmp(str, "help"))
  94. {
  95. viwmfs_help();
  96. return;
  97. }
  98. if(*str == ':')
  99. {
  100. for(i = 0; i < strlen(str); str[i] = str[i + 1], ++i);
  101. cmd = _strdup(str);
  102. for(i = 0; cmd[i] && cmd[i] != ' '; ++i);
  103. cmd[i] = '\0';
  104. for(i = 0; i < LEN(vicmd); ++i)
  105. if(!strncmp(cmd, vicmd[i].cmd, strlen(cmd)))
  106. {
  107. exec_uicb_function(vicmd[i].uicb, clean_value(str + strlen(cmd)));
  108. e = True;
  109. break;
  110. }
  111. /* For uicb function with normal name specified */
  112. if(!e)
  113. {
  114. if(!strcmp(str, "h") || !strcmp(str, "help"))
  115. viwmfs_help();
  116. else
  117. exec_uicb_function(cmd, str + strlen(cmd));
  118. }
  119. }
  120. return;
  121. }