DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L1981
Version: 1.3-feature


Hi, 

Ian asked me to repost my patch as an STR.
Here it is:

I've written a little patch which adds 
a stay_on_top method to the Fl_Window class.
This allows you to set a window above all other
windows that are visible on the screen.
If I see it correctly fltk is lacking such a feature.

To set the window on top call:
   win->stay_on_top(1);
To set the window to normal behaviour call:
   win->stay_on_top(0);

I have to admit that I'm not very familiar with the
fltk sources.
So I hope this patch wont't break anything. 

Would be great if you like the idea of adding the
"stay on top"-feature to fltk.

Regards,
Daniel


Link: http://www.fltk.org/str.php?L1981
Version: 1.3-feature
diff -ru fltk-1.1.9/FL/Fl_Window.H fltk-1.1.9_ontop/FL/Fl_Window.H
--- fltk-1.1.9/FL/Fl_Window.H   2005-07-15 11:34:53.000000000 +0200
+++ fltk-1.1.9_ontop/FL/Fl_Window.H     2008-06-11 19:18:35.000000000 +0200
@@ -88,6 +88,7 @@
   int modal() const    {return flags() & FL_MODAL;}
   void set_non_modal() {set_flag(FL_NON_MODAL);}
   int non_modal() const {return flags() & (FL_NON_MODAL|FL_MODAL);}
+  void stay_on_top(int ontop);
 
   void hotspot(int x, int y, int offscreen = 0);
   void hotspot(const Fl_Widget*, int offscreen = 0);
diff -ru fltk-1.1.9/src/Fl_mac.cxx fltk-1.1.9_ontop/src/Fl_mac.cxx
--- fltk-1.1.9/src/Fl_mac.cxx   2008-02-20 19:17:34.000000000 +0100
+++ fltk-1.1.9_ontop/src/Fl_mac.cxx     2008-06-12 17:09:03.000000000 +0200
@@ -2091,6 +2091,19 @@
   }
 }
 
+/**
+ * activate/deactivate stay on top
+ */
+void Fl_Window::stay_on_top(int ontop) {
+    WindowClass win_class;
+
+    GetWindowClass(i->xid, &win_class);
+
+    if(ontop && win_class == kDocumentWindowClass)
+        SetWindowClass(i->xid, kUtilityWindowClass);
+    if(!ontop && win_class == kUtilityWindowClass)
+        SetWindowClass(i->xid, kDocumentWindowClass);
+}
 
 /**
  * resize a window
diff -ru fltk-1.1.9/src/Fl_win32.cxx fltk-1.1.9_ontop/src/Fl_win32.cxx
--- fltk-1.1.9/src/Fl_win32.cxx 2008-01-10 22:53:34.000000000 +0100
+++ fltk-1.1.9_ontop/src/Fl_win32.cxx   2008-06-11 19:22:15.000000000 +0200
@@ -1551,6 +1551,12 @@
   }
 }
 
+// activate/deactivate stay on top
+void Fl_Window::stay_on_top(int ontop) {
+  SetWindowPos(i->xid, ontop ? HWND_TOPMOST : HWND_NOTOPMOST,
+          0,0,0,0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOOWNERZORDER);
+}
+
 Fl_Window *Fl_Window::current_;
 // the current context
 HDC fl_gc = 0;
diff -ru fltk-1.1.9/src/Fl_x.cxx fltk-1.1.9_ontop/src/Fl_x.cxx
--- fltk-1.1.9/src/Fl_x.cxx     2007-06-18 15:08:57.000000000 +0200
+++ fltk-1.1.9_ontop/src/Fl_x.cxx       2008-06-11 19:19:38.000000000 +0200
@@ -1392,6 +1392,28 @@
   }
 }
 
+// activate/deactivate stay on top
+void Fl_Window::stay_on_top(int ontop) {
+    XEvent e;
+
+    Atom WM_STATE = XInternAtom(fl_display, "_NET_WM_STATE", 0);
+    Atom WM_STATE_ABOVE = XInternAtom(fl_display, "_NET_WM_STATE_ABOVE", 0);
+
+    e.xclient.type = ClientMessage;
+    e.xclient.window = i->xid;
+    e.xclient.message_type = WM_STATE;
+    e.xclient.format = 32;
+    e.xclient.data.l[0] = (long)ontop;
+    e.xclient.data.l[1] = (long)WM_STATE_ABOVE;
+    e.xclient.data.l[2] = (long)0;
+    e.xclient.data.l[3] = (long)0;
+    e.xclient.data.l[4] = (long)0;
+
+    XSendEvent(fl_display, RootWindow(fl_display, fl_screen), 0,
+            SubstructureNotifyMask|SubstructureRedirectMask, &e);
+    XFlush(fl_display);
+}
+
 Window fl_window;
 Fl_Window *Fl_Window::current_;
 GC fl_gc;
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to