getinfo.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * getinfo.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. /* Global variables for each XGetWindowProperty
  34. * of each getinfo functions.
  35. */
  36. Atom rt;
  37. int rf;
  38. ulong ir, il;
  39. uchar *ret;
  40. /** Get information about tag (current, list, names)
  41. */
  42. void
  43. getinfo_tag(void)
  44. {
  45. int tag = 0;
  46. char *tag_name = NULL;
  47. char *tag_list = NULL;
  48. if(XGetWindowProperty(dpy, ROOT, ATOM("_NET_CURRENT_DESKTOP"), 0L, 4096,
  49. False, XA_CARDINAL, &rt, &rf, &ir, &il, &ret) == Success && ret)
  50. {
  51. tag = (int)*ret + 1;
  52. XFree(ret);
  53. }
  54. if(XGetWindowProperty(dpy, ROOT, ATOM("_WMFS_CURRENT_TAG"), 0L, 4096,
  55. False, ATOM("UTF8_STRING"), &rt, &rf, &ir, &il, &ret) == Success && ret)
  56. {
  57. tag_name = _strdup((char*)ret);
  58. XFree(ret);
  59. }
  60. if(XGetWindowProperty(dpy, ROOT, ATOM("_WMFS_TAG_LIST"), 0L, 4096,
  61. False, ATOM("UTF8_STRING"), &rt, &rf, &ir, &il, &ret) == Success && ret)
  62. {
  63. tag_list = _strdup((char*)ret);
  64. XFree(ret);
  65. }
  66. printf("Current tag: %d - %s\n", tag, tag_name);
  67. printf("Tag list: %s\n", tag_list);
  68. IFREE(tag_name);
  69. IFREE(tag_list);
  70. return;
  71. }
  72. /** Get information about screens
  73. */
  74. void
  75. getinfo_screen(void)
  76. {
  77. int screen = 1;
  78. int screen_num = 1;
  79. if(XGetWindowProperty(dpy, ROOT, ATOM("_WMFS_CURRENT_SCREEN"), 0L, 4096,
  80. False, XA_CARDINAL, &rt, &rf, &ir, &il, &ret) == Success && ret)
  81. {
  82. screen = (int)*ret + 1;
  83. XFree(ret);
  84. }
  85. if(XGetWindowProperty(dpy, ROOT, ATOM("_WMFS_SCREEN_COUNT"), 0L, 4096,
  86. False, XA_CARDINAL, &rt, &rf, &ir, &il, &ret) == Success && ret)
  87. {
  88. screen_num = (int)*ret;
  89. XFree(ret);
  90. }
  91. printf("Current screen: %d\nScreen number: %d\n", screen, screen_num);
  92. return;
  93. }
  94. /** Get current layout name
  95. */
  96. void
  97. getinfo_layout(void)
  98. {
  99. char *layout = NULL;
  100. if(XGetWindowProperty(dpy, ROOT, ATOM("_WMFS_CURRENT_LAYOUT"), 0L, 4096,
  101. False, ATOM("UTF8_STRING"), &rt, &rf, &ir, &il, &ret) == Success && ret)
  102. {
  103. layout = _strdup((char*)ret);
  104. XFree(ret);
  105. }
  106. printf("Current layout: %s\n", layout);
  107. IFREE(layout);
  108. return;
  109. }
  110. /** Get information about current mwfact
  111. */
  112. void
  113. getinfo_mwfact(void)
  114. {
  115. char *mwfact = NULL;
  116. if(XGetWindowProperty(dpy, ROOT, ATOM("_WMFS_MWFACT"), 0L, 4096,
  117. False, XA_STRING, &rt, &rf, &ir, &il, &ret) == Success && ret)
  118. {
  119. mwfact = _strdup((char*)ret);
  120. XFree(ret);
  121. }
  122. printf("Current mwfact: %s\n", mwfact);
  123. IFREE(mwfact);
  124. return;
  125. }
  126. /** Get information about current nmaster
  127. */
  128. void
  129. getinfo_nmaster(void)
  130. {
  131. int nmaster = 1;
  132. if(XGetWindowProperty(dpy, ROOT, ATOM("_WMFS_NMASTER"), 0L, 4096,
  133. False, XA_CARDINAL, &rt, &rf, &ir, &il, &ret) == Success && ret)
  134. {
  135. nmaster = (int)*ret;
  136. XFree(ret);
  137. }
  138. printf("Current nmaster: %d\n", nmaster);
  139. return;
  140. }
  141. /** Get information about wmfs
  142. *\param info Type of information in a string
  143. */
  144. void
  145. getinfo(char *info)
  146. {
  147. long data[5];
  148. if(!check_wmfs_running())
  149. return;
  150. data[4] = True;
  151. send_client_event(data, "_WMFS_UPDATE_HINTS");
  152. if(!strcmp(info, "tag"))
  153. getinfo_tag();
  154. else if(!strcmp(info, "screen"))
  155. getinfo_screen();
  156. else if(!strcmp(info, "layout"))
  157. getinfo_layout();
  158. else if(!strcmp(info, "mwfact"))
  159. getinfo_mwfact();
  160. else if(!strcmp(info, "nmaster"))
  161. getinfo_nmaster();
  162. else if(!strcmp(info, "help"))
  163. printf("Argument list for wmfs -g options:\n"
  164. " tag Show current tag number and name, and tag list.\n"
  165. " screen Show current screen and screens number.\n"
  166. " layout Show current layout name.\n"
  167. " mwfact Show mwfact of current tag.\n"
  168. " nmaster Show nmaster of current tag.\n");
  169. else
  170. warnx("Unknow info argument '%s'\nTry 'wmfs -g help'", info);
  171. return;
  172. }