Guest User

Untitled

a guest
Aug 15th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. class tray_window : public Fl_Double_Window
  2. {
  3. public:
  4. tray_window(int W, int H, const char *L=0)
  5. : Fl_Double_Window(W, H, L) { }
  6.  
  7. int handle(int event) {
  8. int rv = Fl_Double_Window::handle(event);
  9. switch (event) {
  10. case FL_PUSH:
  11. //case FL_RELEASE:
  12. do_callback();
  13. rv = 1;
  14. break;
  15. }
  16. return rv;
  17. }
  18. };
  19.  
  20. static tray_window *win;
  21. static const char *command = NULL;
  22.  
  23. static void callback(Fl_Widget *, void *);
  24. static void close_cb(Fl_Widget *, void *);
  25.  
  26. static Fl_Menu_Item menu[] = {
  27. { "Launch", 0, callback, 0,0, FL_NORMAL_LABEL, 0, 14, 0 },
  28. { "Quit", 0, close_cb, 0,0, FL_NORMAL_LABEL, 0, 14, 0 },
  29. { 0,0,0,0,0,0,0,0,0 }
  30. };
  31.  
  32. static void callback(Fl_Widget *, void *) {
  33. win->hide();
  34. execl("/bin/sh", "sh", "-c", command, NULL);
  35. _exit(127);
  36. }
  37.  
  38. static void show_menu_cb(Fl_Widget *) {
  39. menu->popup(1,1);
  40. }
  41.  
  42. static void close_cb(Fl_Widget *, void *) {
  43. win->hide();
  44. }
  45.  
  46. static bool create_tray_entry(const char *)
  47. {
  48. Window dock;
  49. XColor c;
  50. XImage *image;
  51. XEvent ev;
  52. char atom_tray_name[128];
  53. char buf[16];
  54.  
  55. snprintf(atom_tray_name, sizeof(atom_tray_name), "_NET_SYSTEM_TRAY_S%i", fl_screen);
  56. dock = XGetSelectionOwner(fl_display, XInternAtom(fl_display, atom_tray_name, False));
  57. if (!dock) {
  58. return false;
  59. }
  60.  
  61. win = new tray_window(32, 32);
  62. {
  63. Fl_Box *o = new Fl_Box(0, 0, 32, 32);
  64. o->type(FL_NO_BOX);
  65. o->image(new Fl_PNG_Image(NULL, src_default_tray_icon_png, src_default_tray_icon_png_len));
  66. }
  67. win->callback(callback);
  68. //win->callback(show_menu_cb);
  69. win->clear_border();
  70. win->end();
  71. win->show();
  72.  
  73. memset(&ev, 0, sizeof(ev));
  74. ev.xclient.type = ClientMessage;
  75. ev.xclient.window = dock;
  76. ev.xclient.message_type = XInternAtom(fl_display, "_NET_SYSTEM_TRAY_OPCODE", False);
  77. ev.xclient.format = 32;
  78. ev.xclient.data.l[0] = fl_event_time;
  79. ev.xclient.data.l[1] = 0; // SYSTEM_TRAY_REQUEST_DOCK
  80. ev.xclient.data.l[2] = fl_xid(win);
  81. ev.xclient.data.l[3] = 0;
  82. ev.xclient.data.l[4] = 0;
  83. XSendEvent(fl_display, dock, False, NoEventMask, &ev);
  84. XSync(fl_display, False);
  85. //trap_errors();
  86.  
  87. image = XGetImage(fl_display, RootWindow(fl_display, DefaultScreen(fl_display)),
  88. win->x() + 1, win->y() + 1, 1, 1, AllPlanes, XYPixmap);
  89. c.pixel = XGetPixel(image, 0, 0);
  90. XFree(image);
  91.  
  92. XQueryColor(fl_display, DefaultColormap(fl_display, DefaultScreen(fl_display)), &c);
  93. snprintf(buf, sizeof(buf), "0x%02x%02x%02x00",
  94. static_cast<int>(c.red >> 8),
  95. static_cast<int>(c.green >> 8),
  96. static_cast<int>(c.blue >> 8));
  97. win->color(strtoul(buf, 0, 16));
  98. win->redraw();
  99. //if (untrap_errors()) {
  100. /* Handle failure */
  101. //}
  102.  
  103. return true;
  104. }
Add Comment
Please, Sign In to add comment