Thanks for the reponses; I wasn't aware of the 'xlib' package (there
is no mention of it in any of the XEmacs documentation that I've
read...) but it may well be possible to use this library here.
Zajcev's example will certainly replace x-current-desktop, but at the
moment I'm not sure how to code x-on-desktop since that still needs to
get the top level window ID for a frame (i.e. there seems to be no
access or equivalent to FRAME_X_SHELL_WIDGET in Lisp).
Anyway, here's the patch - adapted to return the result as a string,
as suggested by Aidan Kehoe. My first venture into the source at this
level, so I hope that my use of the various integer types is correct!
If acceptable it may still be a useful addition, as xlib is a large
package to pull in for just a simple use such as this.
--- frame-x.c.orig 2006-05-06 18:56:00.000000000 +0100
+++ frame-x.c 2008-11-20 12:38:58.000000000 +0000
@@ -92,6 +92,8 @@
#endif /* not NEW_GC */
EXFUN (Fx_window_id, 1);
+EXFUN (Fx_on_desktop, 1);
+EXFUN (Fx_current_desktop, 1);
/************************************************************************/
@@ -590,6 +592,10 @@
return make_int (w->emacs_frame.interline);
if (EQ (Qwindow_id, property))
return Fx_window_id (wrap_frame (f));
+ if (EQ (Qon_desktop, property))
+ return Fx_on_desktop (wrap_frame (f));
+ if (EQ (Qcurrent_desktop, property))
+ return Fx_current_desktop (wrap_frame (f));
return Qunbound;
}
@@ -617,6 +623,8 @@
Position x, y;
props = cons3 (Qwindow_id, Fx_window_id (wrap_frame (f)), props);
+ props = cons3 (Qon_desktop, Fx_on_desktop (wrap_frame (f)), props);
+ props = cons3 (Qcurrent_desktop, Fx_current_desktop (wrap_frame (f)), props);
props = cons3 (Qinter_line_space, make_int (w->emacs_frame.interline), props);
props = cons3 (Qborder_color,
@@ -2241,6 +2249,96 @@
return build_intstring (str);
}
+DEFUN ("x-on-desktop", Fx_on_desktop, 0, 1, 0, /*
+Get the ID of the desktop on which the FRAME is displayed, by reading
+the _NET_WM_DESKTOP property of its top level window.
+
+The format of this depends on the desktop system and window manager
+in use. With an ICCCM-compliant window manager the result returned
+is an integer value (returned as a string) representing the desktop
+("0" being the first), t for all desktops, or nil if the desktop
+cannot be determined.
+*/
+ (frame))
+{
+ struct frame *f = decode_x_frame (frame);
+ Widget w = FRAME_X_SHELL_WIDGET(f);
+ Display *dpy = XtDisplay(w);
+ Window win = XtWindow(w);
+
+ Atom desk = XInternAtom(dpy,"_NET_WM_DESKTOP",False);
+
+ Atom actual_type; /* results from XGetWindowProperty
*/
+ int actual_format;
+ unsigned long nitems;
+ unsigned long bytes_after;
+ unsigned char *prop;
+
+ INT_32_BIT result = -2;
+
+ if (XGetWindowProperty(dpy,win,desk,0,1,False,XA_CARDINAL,
+ &actual_type,&actual_format,
+ &nitems,&bytes_after,&prop)==Success &&
+ actual_type==XA_CARDINAL)
+ {
+ result = *((INT_32_BIT *) prop); /* get returned result */
+ XFree(prop); /* free result memory */
+ }
+
+ if (result==-1) return Qt; /* all desktops */
+ else if (result!=-2)
+ {
+ Ibyte buf[255];
+ qxesprintf (buf, "%lu", (unsigned long) result);
+ return build_intstring (buf); /* desktop number as a string */
+ }
+ else return Qnil; /* could not identify */
+}
+
+DEFUN ("x-current-desktop", Fx_current_desktop, 0, 1, 0, /*
+Get the ID of the current desktop for the display on which the FRAME
+appears, by reading the _NET_CURRENT_DESKTOP property of the root window.
+
+The format of this depends on the desktop system and window manager
+in use. With an ICCCM-compliant window manager the result returned
+is an integer value (returned as a string) representing the desktop
+("0" being the first), or nil if the desktop cannot be determined.
+*/
+ (frame))
+{
+ struct frame *f = decode_x_frame (frame);
+ Widget w = FRAME_X_SHELL_WIDGET(f);
+ Display *dpy = XtDisplay(w);
+ Window win = RootWindow(dpy,DefaultScreen(dpy));
+
+ Atom desk = XInternAtom(dpy,"_NET_CURRENT_DESKTOP",False);
+
+ Atom actual_type; /* results from XGetWindowProperty
*/
+ int actual_format;
+ unsigned long nitems;
+ unsigned long bytes_after;
+ unsigned char *prop;
+
+ INT_32_BIT result = -2;
+
+ if (XGetWindowProperty(dpy,win,desk,0,1,False,XA_CARDINAL,
+ &actual_type,&actual_format,
+ &nitems,&bytes_after,&prop)==Success &&
+ actual_type==XA_CARDINAL)
+ {
+ result = *((INT_32_BIT *) prop); /* get returned result */
+ XFree(prop); /* free result memory */
+ }
+
+ if (result!=-2)
+ {
+ Ibyte buf[255];
+ qxesprintf (buf, "%lu", (unsigned long) result);
+ return build_intstring (buf); /* desktop number as a string */
+ }
+ else return Qnil; /* could not identify */
+}
+
/************************************************************************/
/* manipulating the X window */
@@ -2786,6 +2884,8 @@
DEFSYMBOL (Qx_resource_name);
DEFSUBR (Fx_window_id);
+ DEFSUBR (Fx_on_desktop);
+ DEFSUBR (Fx_current_desktop);
#ifdef HAVE_CDE
DEFSUBR (Fcde_start_drag_internal);
#endif
--- general-slots.h.orig 2005-07-03 22:48:01.000000000 +0100
+++ general-slots.h 2008-06-19 12:26:14.000000000 +0100
@@ -92,6 +92,7 @@
SYMBOL_MODULE_API (Qcritical);
SYMBOL (Qctext);
SYMBOL (Qcurrent);
+SYMBOL (Qcurrent_desktop);
SYMBOL (Qcursor);
SYMBOL (Qdata);
SYMBOL (Qdde);
@@ -214,6 +215,7 @@
SYMBOL (Qold_rassoc);
SYMBOL (Qold_rassq);
SYMBOL (Qonly);
+SYMBOL (Qon_desktop);
SYMBOL (Qor);
SYMBOL (Qorientation);
SYMBOL_KEYWORD (Q_orientation);
--
Jonathan Marten
http://www.keelhaul.demon.co.uk
Twickenham, UK jjm2(a)keelhaul.demon.co.uk
_______________________________________________
XEmacs-Beta mailing list
XEmacs-Beta(a)xemacs.org
http://calypso.tux.org/cgi-bin/mailman/listinfo/xemacs-beta