diff --git a/include/Dt/WsmP.h b/include/Dt/WsmP.h index ab5c8aae..a06956e6 100644 --- a/include/Dt/WsmP.h +++ b/include/Dt/WsmP.h @@ -209,6 +209,8 @@ typedef void (*DtWsmMarqueeSelectionProc) (); * window manager f.* functions! **********************************************************************/ #define DTWM_REQ_CHANGE_BACKDROP "f.change_backdrop" +/* MCDE: the same for one workspace: "f.change_backdrop_ws INDEX PATH PIXMAP STYLE" */ +#define MCDE_REQ_CHANGE_BACKDROP_WS "f.change_backdrop_ws" #define DTWM_REQ_RESTART "f.restart" /********************************************************************** diff --git a/programs/dtsystemsettings/desktop.c b/programs/dtsystemsettings/desktop.c index 1786a4ea..ee928650 100644 --- a/programs/dtsystemsettings/desktop.c +++ b/programs/dtsystemsettings/desktop.c @@ -76,6 +76,13 @@ static Widget pageDesktop, pageSaver, tabDesktop, tabSaver; +/* the workspace the next backdrop choice goes to; -1 is the active one */ +#define MAX_WORKSPACES 16 +static char *wsNames[MAX_WORKSPACES + 1]; +static Widget wsButtons[MAX_WORKSPACES + 1]; +static int wsCount; +static int targetWorkspace = -1; + /* ---- pictures, small ---------------------------------------------------- */ static int @@ -409,6 +416,76 @@ Slideshow(void) } } +/* append one request to dtwm's _DT_WM_REQUEST property */ +static void +SendWmRequest(Display *dpy, const char *request) +{ + Window wmWindow; + Atom prop = XInternAtom(dpy, "_DT_WM_REQUEST", False); + + if (_DtGetMwmWindow(dpy, DefaultRootWindow(dpy), &wmWindow) != + Success) + return; + XChangeProperty(dpy, wmWindow, prop, XA_STRING, 8, PropModeAppend, + (unsigned char *) request, (int) strlen(request) + 1); + XFlush(dpy); +} + +/* the backdrop for TARGETWORKSPACE (the active one when it is -1) */ +static void +ApplyBackdrop(Display *dpy, const char *path, int imageStyle) +{ + if (targetWorkspace < 0) { + (void) _DtWsmChangeBackdrop(dpy, DefaultRootWindow(dpy), + (char *) path, None, + (DtWsmBackdropImageType) imageStyle); + XFlush(dpy); + } else { + char request[1600]; + + snprintf(request, sizeof request, + "f.change_backdrop_ws %d %s 0 %d", targetWorkspace, path, + imageStyle); + SendWmRequest(dpy, request); + } +} + +/* the workspaces of this screen, by title; the first entry is the active + * one ("This Workspace") */ +static void +ReadWorkspaces(Display *dpy) +{ + Atom *list = NULL; + int n = 0, i; + + wsCount = 0; + wsNames[0] = strdup("This Workspace"); + if (DtWsmGetWorkspaceList(dpy, DefaultRootWindow(dpy), &list, &n) != + Success || list == NULL) + return; + for (i = 0; i < n && wsCount < MAX_WORKSPACES; i++) { + DtWsmWorkspaceInfo *info = NULL; + + if (DtWsmGetWorkspaceInfo(dpy, DefaultRootWindow(dpy), + list[i], &info) == Success && info != NULL) { + wsNames[wsCount + 1] = strdup(info->pchTitle != NULL ? + info->pchTitle : "Workspace"); + DtWsmFreeWorkspaceInfo(info); + } else + wsNames[wsCount + 1] = strdup("Workspace"); + wsCount++; + } + XFree(list); +} + +static void +WorkspaceChosen(Widget w, XtPointer data, XtPointer call) +{ + (void) w; + (void) call; + targetWorkspace = (int) (size_t) data - 1; +} + static void PictureChosen(Widget w, XtPointer data, XtPointer call) { @@ -428,9 +505,7 @@ PictureChosen(Widget w, XtPointer data, XtPointer call) XmToggleButtonSetState(changeToggle, False, False); SendSlideshow(dpy, "0"); } - (void) _DtWsmChangeBackdrop(dpy, DefaultRootWindow(dpy), path, None, - (DtWsmBackdropImageType) style); - XFlush(dpy); + ApplyBackdrop(dpy, path, style); SetPreview(path, pictures[i]); } @@ -548,9 +623,7 @@ StyleChosen(Widget w, XtPointer data, XtPointer call) snprintf(path, sizeof path, "%s/%s", places[place].dir, pictures[k]); - (void) _DtWsmChangeBackdrop(dpy, DefaultRootWindow(dpy), - path, None, (DtWsmBackdropImageType) style); - XFlush(dpy); + ApplyBackdrop(dpy, path, style); break; } } @@ -700,6 +773,20 @@ MakeDesktopPage(Widget parent) page = XtVaCreateWidget("desktopPage", xmRowColumnWidgetClass, parent, XmNspacing, 8, NULL); + /* the workspace the next choice belongs to: "This Workspace" (the + * active one) or one of the named workspaces */ + targetWorkspace = -1; + ReadWorkspaces(dpy); + row = XtVaCreateManagedWidget("workspaceRow", xmRowColumnWidgetClass, + page, XmNorientation, XmHORIZONTAL, XmNspacing, 8, NULL); + { + Widget menu = OptionMenu(row, "workspaceMenu", "Workspace:", + (const char *const *) wsNames, wsCount + 1, wsButtons, + WorkspaceChosen); + + XtVaSetValues(menu, XmNmenuHistory, wsButtons[0], NULL); + } + top = XtVaCreateManagedWidget("current", xmFormWidgetClass, page, NULL); /* the frame gets the size: the drawing area alone was laid out 0 high * (measured) */ diff --git a/programs/dtwm/WmEvent.c b/programs/dtwm/WmEvent.c index 8ec39ba8..023c7a32 100644 --- a/programs/dtwm/WmEvent.c +++ b/programs/dtwm/WmEvent.c @@ -1996,6 +1996,54 @@ HandleDtWmRequest (WmScreenData *pSD, XEvent *pev) } } } + else if (!strncmp (pchReq, MCDE_REQ_CHANGE_BACKDROP_WS, + strlen(MCDE_REQ_CHANGE_BACKDROP_WS))) + { + /* + * MCDE: "f.change_backdrop_ws INDEX PATH PIXMAP STYLE", + * the same as below for one workspace (0-based). + */ + Pixmap pixmap = None; + int imageType = DtWSM_BACKDROP_IMAGETYPE_TILED; + char *pchPath, *pchPix, *pchType, *end; + int ws = -1; + + pchPath = pchReq + strlen(MCDE_REQ_CHANGE_BACKDROP_WS); + while (*pchPath == ' ') + pchPath++; + ws = (int) strtol(pchPath, &end, 10); + if (end == pchPath) + ws = -1; + pchPath = end; + while (*pchPath == ' ') + pchPath++; + pchType = strrchr (pchPath, ' '); + if (pchType) + *pchType++ = '\0'; + pchPix = pchType ? strrchr (pchPath, ' ') : NULL; + if (pchPix) + *pchPix++ = '\0'; + if (ws < 0 || ws >= (int) pSD->numWorkspaces || !pchPix || + !*pchPath) + { + Warning (((char *)GETMESSAGE(32, 3, "Missing path name for backdrop change request."))); + } + else + { + sscanf (pchPix, "%lx", &pixmap); + sscanf (pchType, "%d", &imageType); + if (getenv("MCDE_DESK_DEBUG") != NULL) + fprintf(stderr, "dtwm: backdrop ws=%d %s style=%d\n", + ws, pchPath, imageType); + if (pixmap == None) + McdeBackdropFromFile (&pSD->pWS[ws], pchPath, + imageType); + else + SetNewBackdrop (&pSD->pWS[ws], pixmap, + (String) pchPath, + (DtWsmBackdropImageType) imageType); + } + } else if (!strncmp (pchReq, DTWM_REQ_CHANGE_BACKDROP, strlen(DTWM_REQ_CHANGE_BACKDROP))) { diff --git a/programs/dtwm/WmMain.c b/programs/dtwm/WmMain.c index 45a8fc4a..550115de 100644 --- a/programs/dtwm/WmMain.c +++ b/programs/dtwm/WmMain.c @@ -49,6 +49,7 @@ #include "WmError.h" #include "WmIPC.h" #include "WmMcdeDisplays.h" +#include "WmFunction.h" #include "WmBackdrop.h"