Hi Sanel,

many thanks for your example. I'll try it and let you know.

Best regards


> Hi,
>
> > >Does the FLTK library directly provide any functionalities to
> > >minimize the application onto the KDE/GNOME system tray. If not, is
> > >there a VERY minimal example showing how to do this from an fltk
> > >application?
> >
> > Fltk doesn't provide systray support. The various different systray
> > implementations are too different to be covered by a single minimal
> > example, I think. I have a working example for win32 but not for KDE
> > or Gnome, I'm afraid. Perhaps someone else here does?
>
> AFAIK most implementors follows freedeskop.org specification
> (http://www.freedesktop.org/wiki/Specifications/systemtray-spec) these
> days.
>
> Below is minimal sample how to do it and is far away from complete. You
> still have to define:
>  * icon via _NET_WM_ICON property
>  * name via _NET_WM_NAME property
>  * and class via WM_CLASS property
>
> ....and handle messages when dock send to your window. I would suggest
> you to check in gaim/xchat/psi implementation, just to fill out the
> missing parts.
>
> #include <FL/Fl_Window.h>
> #include <FL/Fl.h>
> #include <FL/x.h>
> #include <FL/Fl_Button.h>
> #include <string.h>
> #include <stdio.h>
>
> #define SYSTEM_TRAY_REQUEST_DOCK    0
>
> Fl_Window* win;
>
> Window get_dock(void) {
>   char atom_tray_name[128];
>   sprintf(atom_tray_name, "_NET_SYSTEM_TRAY_S%i", fl_screen);
>   Atom sys_tray_atom = XInternAtom(fl_display, atom_tray_name, False);
>
>   Window owner = XGetSelectionOwner(fl_display, sys_tray_atom);
>   return owner;
> }
>
> void dock_window(Fl_Window* client) {
>   Window dock = get_dock();
>   if(!dock)
>     return;
>
>   XEvent ev;
>
>   memset(&ev, 0, sizeof(ev));
>   ev.xclient.type = ClientMessage;
>   ev.xclient.window = dock;
>   ev.xclient.message_type = XInternAtom (fl_display, 
> "_NET_SYSTEM_TRAY_OPCODE", False);
>   ev.xclient.format = 32;
>   ev.xclient.data.l[0] = fl_event_time;
>   ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
>   ev.xclient.data.l[2] = fl_xid(client); // window to be docked
>   ev.xclient.data.l[3] = 0;
>   ev.xclient.data.l[4] = 0;
>
>   // here add code to trap X11 errors
>
>   XSendEvent(fl_display, dock, False, NoEventMask, &ev);
>   XSync(fl_display, False);
>
>   // here add code to untrap X11 errors and handle them
> }
>
> void tray_cb(Fl_Widget*, void*) {
>   dock_window(win);
> }
>
> int main() {
>   win = new Fl_Window(200, 200, "Tray sample");
>   win->begin();
>   Fl_Button* b = new Fl_Button(10, 10, 120, 25, "Minimize to tray");
>   b->callback(tray_cb);
>   win->end();
>   win->show();
>
>   return Fl::run();
> }
>
> Best,
> --
> Sanel

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to