Posted to tcl by patthoyts at Wed Apr 09 13:26:48 GMT 2008view pretty

? doc/man.macros
Index: unix/tkUnixWm.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/unix/tkUnixWm.c,v
retrieving revision 1.55
diff -u -r1.55 tkUnixWm.c
--- unix/tkUnixWm.c	27 Feb 2007 14:52:57 -0000	1.55
+++ unix/tkUnixWm.c	27 Apr 2007 18:06:17 -0000
@@ -350,6 +350,7 @@
 static void 		SetNetWmState(TkWindow*, const char *atomName, int on);
 static void 		CheckNetWmState(WmInfo *, Atom *atoms, int numAtoms);
 static void 		UpdateNetWmState(WmInfo *);
+static void		TkpWmSetDesktop(TkWindow *winPtr, int desktop);
 static void		WaitForConfigureNotify(TkWindow *winPtr,
 			    unsigned long serial);
 static int		WaitForEvent(Display *display,
@@ -452,6 +453,9 @@
 			    Tcl_Interp *interp, int objc,
 			    Tcl_Obj *CONST objv[]);
 static void		WmUpdateGeom(WmInfo *wmPtr, TkWindow *winPtr);
+static int		WmDesktopCmd(Tk_Window tkwin, TkWindow *winPtr,
+			    Tcl_Interp *interp, int objc,
+			    Tcl_Obj *CONST objv[]);
  
 /*
  *--------------------------------------------------------------
@@ -998,7 +1002,7 @@
     Tk_Window tkwin = (Tk_Window) clientData;
     static CONST char *optionStrings[] = {
 	"aspect", "attributes", "client", "colormapwindows",
-	"command", "deiconify", "focusmodel", "frame",
+	"command", "deiconify", "desktop", "focusmodel", "frame",
 	"geometry", "grid", "group", "iconbitmap",
 	"iconify", "iconmask", "iconname",
 	"iconphoto", "iconposition",
@@ -1008,8 +1012,8 @@
 	"withdraw", NULL };
     enum options {
 	WMOPT_ASPECT, WMOPT_ATTRIBUTES, WMOPT_CLIENT, WMOPT_COLORMAPWINDOWS,
-	WMOPT_COMMAND, WMOPT_DEICONIFY, WMOPT_FOCUSMODEL, WMOPT_FRAME,
-	WMOPT_GEOMETRY, WMOPT_GRID, WMOPT_GROUP, WMOPT_ICONBITMAP,
+	WMOPT_COMMAND, WMOPT_DEICONIFY, WMOPT_DESKTOP, WMOPT_FOCUSMODEL,
+	WMOPT_FRAME, WMOPT_GEOMETRY, WMOPT_GRID, WMOPT_GROUP, WMOPT_ICONBITMAP,
 	WMOPT_ICONIFY, WMOPT_ICONMASK, WMOPT_ICONNAME,
 	WMOPT_ICONPHOTO, WMOPT_ICONPOSITION,
 	WMOPT_ICONWINDOW, WMOPT_MAXSIZE, WMOPT_MINSIZE, WMOPT_OVERRIDEREDIRECT,
@@ -1086,6 +1090,8 @@
 	return WmCommandCmd(tkwin, winPtr, interp, objc, objv);
     case WMOPT_DEICONIFY:
 	return WmDeiconifyCmd(tkwin, winPtr, interp, objc, objv);
+    case WMOPT_DESKTOP:
+	return WmDesktopCmd(tkwin, winPtr, interp, objc, objv);
     case WMOPT_FOCUSMODEL:
 	return WmFocusmodelCmd(tkwin, winPtr, interp, objc, objv);
     case WMOPT_FRAME:
@@ -1704,6 +1710,70 @@
 /*
  *----------------------------------------------------------------------
  *
+ * WmDesktopCmd --
+ *
+ *	This function is invoked to process the "wm desktop" Tcl command.
+ *	See the user documentation for details on what it does.
+ *
+ * Results:
+ *	A standard Tcl result.
+ *
+ * Side effects:
+ *	See the user documentation.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static int
+WmDesktopCmd(
+    Tk_Window tkwin,		/* Main window of the application. */
+    TkWindow *winPtr,		/* Toplevel to work with */
+    Tcl_Interp *interp,		/* Current interpreter. */
+    int objc,			/* Number of arguments. */
+    Tcl_Obj *CONST objv[])	/* Argument objects. */
+{
+    register WmInfo *wmPtr = winPtr->wmInfoPtr;
+    int result = TCL_OK;
+
+    if (objc < 3 || objc > 4) {
+	Tcl_WrongNumArgs(interp, 2, objv, "window desktop ?value?");
+	return TCL_ERROR;
+    }
+    if (objc == 4) {
+	int desktop = 0;
+	if (Tcl_GetIntFromObj(interp, objv[3], &desktop) != TCL_OK) {
+	    return TCL_ERROR;
+	}
+	TkpWmSetDesktop(winPtr, desktop);
+    } else {
+	TkWindow *wrapperPtr = wmPtr->wrapperPtr;
+	Atom atom = Tk_InternAtom((Tk_Window)wmPtr->winPtr, "_NET_WM_DESKTOP");
+	Atom actualType;
+	int actualFormat;
+	unsigned long numItems, bytesAfter;
+	unsigned char *propertyValue = 0;
+	long maxLength = 1024;
+	
+	if (XGetWindowProperty(
+		wrapperPtr->display, wrapperPtr->window, atom,
+		0l, maxLength, False, XA_CARDINAL,
+		&actualType, &actualFormat, &numItems, &bytesAfter,
+		&propertyValue) == Success) {
+	    if ((actualType == XA_CARDINAL) && (actualFormat == 32) && (numItems == 1)) {
+		Tcl_SetObjResult(interp, Tcl_NewIntObj(*(int *)propertyValue));
+	    } else {
+		Tcl_SetResult(interp, "invalid desktop property returned", TCL_STATIC);
+		result = TCL_ERROR;
+	    }
+	    XFree(propertyValue);
+	}
+    }
+    return result;
+}
+ 
+/*
+ *----------------------------------------------------------------------
+ *
  * WmFocusmodelCmd --
  *
  *	This function is invoked to process the "wm focusmodel" Tcl command.
@@ -7020,6 +7090,48 @@
 }
  
 /*
+ *----------------------------------------------------------------------
+ *
+ * TkpWmSetDesktop --
+ *
+ *	Request the window manager to set the desktop for this window.
+ *
+ * Results:
+ *	None
+ *
+ * Side effects:
+ *	May cause the window to change desktops.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static void
+TkpWmSetDesktop(
+    TkWindow *winPtr,
+    int desktop)
+{
+    Tk_Window tkwin = (Tk_Window)winPtr;
+    Atom messageType = Tk_InternAtom(tkwin, "_NET_WM_DESKTOP");
+    XEvent e;
+
+    if (!winPtr->wmInfoPtr->wrapperPtr) {
+	return;
+    }
+
+    e.xany.type = ClientMessage;
+    e.xany.window = winPtr->wmInfoPtr->wrapperPtr->window;
+    e.xclient.message_type = messageType;
+    e.xclient.format = 32;
+    e.xclient.data.l[0] = desktop;
+    e.xclient.data.l[1] = 0l;
+    e.xclient.data.l[2] = e.xclient.data.l[3] = e.xclient.data.l[4] = 0l;
+
+    XSendEvent(winPtr->display,
+	RootWindow(winPtr->display, winPtr->screenNum), 0,
+	SubstructureNotifyMask|SubstructureRedirectMask, &e);
+}
+ 
+/*
  * Local Variables:
  * mode: c
  * c-basic-offset: 4