diff --git a/programs/dtwm/WmMcdePanel.c b/programs/dtwm/WmMcdePanel.c index 402a46a6..7cb10b5c 100644 --- a/programs/dtwm/WmMcdePanel.c +++ b/programs/dtwm/WmMcdePanel.c @@ -35,6 +35,8 @@ #include #include #include +#include +#include #include "WmGlobal.h" #include "WmFunction.h" @@ -55,6 +57,7 @@ #include
#include
#include
+#include
#include
/* The icon of a program class. CDE names them with a capital (Dtterm, @@ -718,6 +721,52 @@ KeepClass(const char *cls, const char *cmd) McdePanelChanged(); } +/* A file or folder dropped on the panel: a program goes into the dock (the + * list the Dock pane edits, ~/.dt/panel-apps), a folder opens dtfile, a + * plain file is not a program and is ignored. The drop site is the panel + * shell, so a drop on an icon still goes to the icon's own site (which runs + * its action with the file), and a drop on empty panel space lands here, as + * on the Dock of Mac OS X 10.4. */ +static void +McdePanelDropCB(Widget w, XtPointer client_data, XtPointer call_data) +{ + DtDndTransferCallbackStruct *t = + (DtDndTransferCallbackStruct *) call_data; + Cardinal i; + int added = 0; + + (void) w; + (void) client_data; + if (t->dropData == NULL || + t->dropData->protocol != DtDND_FILENAME_TRANSFER) { + t->status = DtDND_FAILURE; + return; + } + for (i = 0; i < t->dropData->numItems; i++) { + const char *path = t->dropData->data.files[i]; + struct stat st; + char cmd[1200]; + const char *base; + + if (path == NULL || path[0] != '/' || stat(path, &st) != 0) + continue; + if (S_ISDIR(st.st_mode)) + snprintf(cmd, sizeof cmd, "dtfile -dir \"%s\"", path); + else if (access(path, X_OK) == 0) + snprintf(cmd, sizeof cmd, "\"%s\"", path); + else + continue; + base = strrchr(path, '/'); + base = base != NULL ? base + 1 : path; + if (*base == '\0') + continue; + KeepClass(base, cmd); + added++; + } + t->status = added > 0 ? DtDND_SUCCESS : DtDND_FAILURE; + t->completeMove = False; +} + static void KeepClient(ClientData *pCD) { @@ -1335,4 +1384,17 @@ McdePanelCreate(void) } Update(); + + /* the panel background takes file drops for the dock (WmMcdePanel.c) */ + { + static XtCallbackRec dropCB[] = { + { (XtCallbackProc) McdePanelDropCB, NULL }, + { NULL, NULL } + }; + Arg dal[1]; + + XtSetArg(dal[0], DtNpreserveRegistration, True); + DtDndDropRegister(panel.form, DtDND_FILENAME_TRANSFER, + XmDROP_COPY, dropCB, dal, 1); + } }