viwmfs.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. {"ctn", "tag_transfert_next"},
  51. {"ctp", "tag_transfert_prev"},
  52. {"cn", "client_next"},
  53. {"cp", "client_prev"},
  54. {"csn", "client_swap_next"},
  55. {"csp", "client_swap_prev"},
  56. {"mwf", "set_mwfact"},
  57. {"mwfact", "set_mwfact"},
  58. {"nmaster", "set_nmaster"},
  59. {"tm", "toggle_max"},
  60. {"tf", "toggle_free"},
  61. };
  62. void
  63. viwmfs_help(void)
  64. {
  65. int i;
  66. char s[20];
  67. printf("ViWMFS commands list:\n");
  68. for(i = 0; i < LEN(vicmd); ++i)
  69. {
  70. memset(s, ' ', sizeof(s));
  71. s[15 - strlen(vicmd[i].cmd)] = '\0';
  72. printf(" :%s%s %s\n", vicmd[i].cmd, s, vicmd[i].uicb);
  73. }
  74. return;
  75. }
  76. void
  77. viwmfs(int argc, char **argv)
  78. {
  79. int i;
  80. char *cmd, str[256] = { 0 };
  81. Bool e;
  82. if(!argc)
  83. return;
  84. if(argc > 3)
  85. {
  86. for(i = 2; i < argc; ++i)
  87. {
  88. strcat(str, argv[i]);
  89. if(*(str + strlen(str) - 1) != ':')
  90. strcat(str, " ");
  91. }
  92. }
  93. else
  94. strcpy(str, argv[2]);
  95. if(!strcmp(str, "help"))
  96. {
  97. viwmfs_help();
  98. return;
  99. }
  100. if(*str == ':')
  101. {
  102. for(i = 0; i < strlen(str); str[i] = str[i + 1], ++i);
  103. cmd = _strdup(str);
  104. for(i = 0; cmd[i] && cmd[i] != ' '; ++i);
  105. cmd[i] = '\0';
  106. for(i = 0; i < LEN(vicmd); ++i)
  107. if(!strncmp(cmd, vicmd[i].cmd, strlen(cmd)))
  108. {
  109. exec_uicb_function(vicmd[i].uicb, clean_value(str + strlen(cmd)));
  110. e = True;
  111. break;
  112. }
  113. /* For uicb function with normal name specified */
  114. if(!e)
  115. {
  116. if(!strcmp(str, "h") || !strcmp(str, "help"))
  117. viwmfs_help();
  118. else
  119. exec_uicb_function(cmd, str + strlen(cmd));
  120. }
  121. }
  122. return;
  123. }