Patch updated in accordance with Stephen J. Turnbull's comments, hopefully
also properly formatted in GNU style. There seems to be no suitable X11
typedef for INT_32_BIT, so I've left that as the explicit XEmacs 32-bit type.
--- frame-x.c.orig 2006-05-06 18:56:00.000000000 +0100
+++ frame-x.c 2008-11-24 11:42:35.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,80 @@
return build_intstring (str);
}
+static Lisp_Object
+x_get_desktop (Display *dpy, Window win, Atom property)
+{
+ Atom actual_type;
+ int actual_format;
+ unsigned long nitems;
+ unsigned long bytes_after;
+ unsigned char *propret;
+
+ INT_32_BIT result = -2; /* sentinel for 'no result available' */
+
+ if (XGetWindowProperty (dpy, win, property, 0, 1, False, XA_CARDINAL,
+ &actual_type, &actual_format,
+ &nitems, &bytes_after, &propret) == Success
&&
+ actual_type == XA_CARDINAL)
+ {
+ result = *((INT_32_BIT *) propret);
+ XFree (propret);
+ }
+
+ if (result == -2)
+ return Qnil; /* could not identify */
+ else if (result == -1)
+ return Qt; /* all desktops */
+ else if (result >= 0 && NUMBER_FITS_IN_AN_EMACS_INT(result))
+ {
+ return make_int (result); /* desktop number */
+ }
+ else
+ {
+ warn_when_safe (Qwarning, Qx, "Invalid desktop index: 0x%lx", result);
+ return Qnil;
+ }
+}
+
+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.
+
+With a NetWM-compliant window manager, the result is a small integer
+representing the desktop (0 being the first), or t for all desktops.
+If the information is not available or the desktop cannot be determined,
+then nil is returned.
+*/
+ (frame))
+{
+ struct frame *f = decode_x_frame (frame);
+ Widget w = FRAME_X_SHELL_WIDGET (f);
+ Display *dpy = XtDisplay (w);
+ Window win = XtWindow (w);
+ Atom prop = XInternAtom (dpy, "_NET_WM_DESKTOP", False);
+
+ return (x_get_desktop (dpy, win, prop));
+}
+
+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.
+
+With a NetWM-compliant window manager, the result is a small integer
+representing the desktop (0 being the first). If the information is not
+available or the desktop cannot be determined, then nil is returned.
+*/
+ (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 prop = XInternAtom (dpy, "_NET_CURRENT_DESKTOP", False);
+
+ return (x_get_desktop (dpy, win, prop));
+}
+
/************************************************************************/
/* manipulating the X window */
@@ -2786,6 +2868,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