dtwm: the panel takes dropped programs into the dock
Dropping a file or folder on the front panel's background adds it to the dock: an executable as itself, a folder as `dtfile -dir`, a plain file is ignored. The site is the panel form (Motif DnD, FILENAME transfer, COPY), so a drop on a control still goes to the control's own site and runs its action with the file; the form only sees the empty panel. KeepClass writes ~/.dt/panel-apps and redraws the dock at once, the same list the Dock pane edits. dtfile is the source already: DtDndDragStart in File.c with DtDND_FILENAME_TRANSFER, started by button 1 or 2. Measured: make -C programs/dtwm rc=0, 0 errors; make -C programs/dtfile rc=0, 0 errors (the MacBook build of this tree).
This commit is contained in:
1 parent
da3f2019ae
commit
d651db9306
1 file changed
+62
@@ -35,6 +35,8 @@
|
||||
#include <strings.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "WmGlobal.h"
|
||||
#include "WmFunction.h"
|
||||
@@ -55,6 +57,7 @@
|
||||
#include <Dt/DtStrDefs.h>
|
||||
#include <Dt/Icon.h>
|
||||
#include <Dt/Control.h>
|
||||
#include <Dt/Dnd.h>
|
||||
#include <Dt/IconFile.h>
|
||||
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user