Guest User

Untitled

a guest
Jan 23rd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <X11/Xlib.h>
  4.  
  5. int main(int argc, char **argv) {
  6. Display *display = XOpenDisplay("");
  7. Window rootwin = XDefaultRootWindow(display);
  8. if (argc < 2)
  9. {
  10. printf("usage: %s windowidn", argv[0]);
  11. return 0;
  12. }
  13. Window window = (Window)strtoul(argv[1], NULL, 0);
  14. printf("switch to window: 0x%lxn", window);
  15. Atom ActiveWindowAtom = XInternAtom(display, "_NET_ACTIVE_WINDOW", False);
  16. XEvent xev;
  17. xev.xclient.type = ClientMessage;
  18. xev.xclient.window = window;
  19. xev.xclient.message_type = ActiveWindowAtom;
  20. xev.xclient.format = 32;
  21. xev.xclient.data.l[0] = 1U;
  22. xev.xclient.data.l[1] = 1U;
  23. xev.xclient.data.l[2] = 0U;
  24. xev.xclient.data.l[3] = 0U;
  25. xev.xclient.data.l[4] = 0U;
  26. XSendEvent(display, rootwin, False, SubstructureRedirectMask, &xev);
  27. XMapRaised(display, window);
  28. XCloseDisplay(display);
  29. return 0;
  30. }
  31.  
  32. #include <stdlib.h>
  33. #include <stdio.h>
  34. #include <xcb/xcb.h>
  35. #include "atom_cache.h"
  36.  
  37. int main(int argc, char **argv) {
  38. xcb_connection_t *connection;
  39. const xcb_setup_t *setup;
  40. xcb_screen_iterator_t screen_iter;
  41. xcb_screen_t *screen;
  42. xcb_window_t rootwin, window;
  43. xcb_void_cookie_t void_cookie;
  44. xcb_client_message_event_t client_message_event;
  45.  
  46. if (argc < 2)
  47. {
  48. printf("usage: %s windowidn", argv[0]);
  49. return 0;
  50. }
  51.  
  52. window = (xcb_window_t)strtoul(argv[1], NULL, 0);
  53. printf("switch to window: 0x%xn", window);
  54.  
  55. connection = xcb_connect(NULL, NULL);
  56. setup = xcb_get_setup(connection);
  57. screen_iter = xcb_setup_roots_iterator(setup);
  58. screen = screen_iter.data;
  59. rootwin = screen->root;
  60.  
  61. // send _net_active_window request
  62. client_message_event.response_type = XCB_CLIENT_MESSAGE;
  63. client_message_event.format = 32;
  64. client_message_event.sequence = 0;
  65. client_message_event.window = window;
  66. client_message_event.type = get_atom(connection, "_NET_ACTIVE_WINDOW");
  67. client_message_event.data.data32[0] = 1UL; // source: 1=application 2=pager
  68. client_message_event.data.data32[1] = 1UL; // timestamp
  69. client_message_event.data.data32[2] = 0UL; // my currently active window?
  70. client_message_event.data.data32[3] = 0UL;
  71. client_message_event.data.data32[4] = 0UL;
  72.  
  73. void_cookie = xcb_send_event(connection, 1, rootwin, XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (const char *)&client_message_event);
  74.  
  75. uint32_t values[] = { XCB_STACK_MODE_ABOVE };
  76. xcb_configure_window(connection, window, XCB_CONFIG_WINDOW_STACK_MODE, values);
  77. xcb_map_window(connection, window);
  78.  
  79. xcb_flush(connection);
  80. xcb_disconnect(connection);
  81. return 0;
  82. }
Add Comment
Please, Sign In to add comment