Files
wmaker/src/dockedapp.c
T

422 lines
14 KiB
C
Raw Normal View History

1998-09-29 22:36:29 +00:00
/* dockedapp.c- docked application settings panel
*
1998-10-21 14:43:47 +00:00
* Window Maker window manager
*
2003-01-16 23:30:45 +00:00
* Copyright (c) 1998-2003 Alfredo K. Kojima
*
1998-09-29 22:36:29 +00:00
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1998-09-29 22:36:29 +00:00
*/
#include "wconfig.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdlib.h>
#include <string.h>
2013-05-15 13:07:57 +02:00
#include <stdio.h>
1998-09-29 22:36:29 +00:00
#include "WindowMaker.h"
#include "window.h"
#include "icon.h"
#include "appicon.h"
#include "dock.h"
2012-06-23 12:04:29 +01:00
#include "dockedapp.h"
1998-09-29 22:36:29 +00:00
#include "dialog.h"
2013-04-14 23:13:26 +02:00
#include "misc.h"
1998-09-29 22:36:29 +00:00
#include "defaults.h"
#include "framewin.h"
#include "xinerama.h"
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
static void updateCommand(WAppIcon * icon, char *command)
1998-09-29 22:36:29 +00:00
{
2025-09-01 21:20:22 -04:00
wAppIconSetCommand(icon, command);
2001-09-03 22:31:30 +00:00
2025-09-01 21:20:22 -04:00
if (!wAppIconGetWmClass(icon) && !wAppIconGetWmInstance(icon) && wAppIconGetCommand(icon) && strlen(wAppIconGetCommand(icon)) > 0) {
wAppIconSetForceDocked(icon, 1);
2009-08-20 00:59:40 +02:00
}
1998-09-29 22:36:29 +00:00
}
2009-08-20 00:59:40 +02:00
static void updateSettingsPanelIcon(AppSettingsPanel * panel)
1998-09-29 22:36:29 +00:00
{
2009-08-20 00:59:40 +02:00
char *file;
int size;
2009-08-20 00:59:40 +02:00
file = WMGetTextFieldText(panel->iconField);
if (!file)
WMSetLabelImage(panel->iconLabel, NULL);
else {
char *path;
path = FindImage(wPreferences.icon_path, file);
if (!path) {
wwarning(_("could not find icon %s, used in a docked application"), file);
wfree(file);
WMSetLabelImage(panel->iconLabel, NULL);
return;
} else {
WMPixmap *pixmap;
RColor color;
color.red = 0xae;
color.green = 0xaa;
color.blue = 0xae;
color.alpha = 0;
size = wPreferences.icon_size;
pixmap = WMCreateScaledBlendedPixmapFromFile(WMWidgetScreen(panel->win), path, &color, size, size);
2009-08-20 00:59:40 +02:00
if (!pixmap) {
WMSetLabelImage(panel->iconLabel, NULL);
} else {
WMSetLabelImage(panel->iconLabel, pixmap);
WMReleasePixmap(pixmap);
}
}
wfree(file);
wfree(path);
}
1998-09-29 22:36:29 +00:00
}
2009-08-20 00:59:40 +02:00
static void chooseIconCallback(WMWidget * self, void *clientData)
1998-09-29 22:36:29 +00:00
{
2009-08-20 00:59:40 +02:00
char *file;
AppSettingsPanel *panel = (AppSettingsPanel *) clientData;
int result;
/* Parameter not used, but tell the compiler that it is ok */
(void) self;
2009-08-20 00:59:40 +02:00
panel->choosingIcon = 1;
WMSetButtonEnabled(panel->browseBtn, False);
result = wIconChooserDialog(panel->wwin->screen_ptr, &file,
2025-09-01 21:20:22 -04:00
wAppIconGetWmInstance(panel->editedIcon), wAppIconGetWmClass(panel->editedIcon));
2009-08-20 00:59:40 +02:00
panel->choosingIcon = 0;
if (!panel->destroyed) {
if (result) {
WMSetTextFieldText(panel->iconField, file);
updateSettingsPanelIcon(panel);
}
WMSetButtonEnabled(panel->browseBtn, True);
} else {
/* kluge for the case, the user asked to close the panel before
* the icon chooser */
DestroyDockAppSettingsPanel(panel);
}
if (result)
wfree(file);
1998-09-29 22:36:29 +00:00
}
2009-08-20 00:59:40 +02:00
static void panelBtnCallback(WMWidget * self, void *data)
1998-09-29 22:36:29 +00:00
{
2009-08-20 00:59:40 +02:00
WMButton *btn = self;
AppSettingsPanel *panel = (AppSettingsPanel *) data;
char *text;
if (panel->okBtn == btn) {
text = WMGetTextFieldText(panel->iconField);
if (text[0] == 0) {
wfree(text);
text = NULL;
}
2012-11-10 20:25:11 +01:00
2025-09-01 21:20:22 -04:00
if (!wIconChangeImageFile(wAppIconGetIcon(panel->editedIcon), text)) {
2009-08-20 00:59:40 +02:00
char *buf;
int len = strlen(text) + 64;
buf = wmalloc(len);
snprintf(buf, len, _("Could not open specified icon file: %s"), text);
if (wMessageDialog(panel->wwin->screen_ptr, _("Error"), buf,
_("OK"), _("Ignore"), NULL) == WAPRDefault) {
wfree(text);
2009-08-20 00:59:40 +02:00
wfree(buf);
return;
}
wfree(buf);
} else {
WAppIcon *aicon = panel->editedIcon;
2013-04-12 01:42:41 +02:00
// Cf dock.c:dockIconPaint(WAppIcon *aicon)?
2025-09-01 21:20:22 -04:00
if (aicon == wAppIconGetIcon(aicon)->core->screen_ptr->clip_icon)
wClipIconPaint(aicon);
else if (wIsADrawer(aicon))
2013-04-12 01:42:41 +02:00
wDrawerIconPaint(aicon);
2009-08-20 00:59:40 +02:00
else
2012-11-10 20:25:14 +01:00
wAppIconPaint(aicon);
2009-08-20 00:59:40 +02:00
2025-09-01 21:20:22 -04:00
wDefaultChangeIcon(wAppIconGetWmInstance(aicon), wAppIconGetWmClass(aicon), text);
2009-08-20 00:59:40 +02:00
}
if (text)
wfree(text);
/* cannot free text from this, because it will be not be duplicated
* in updateCommand */
text = WMGetTextFieldText(panel->commandField);
if (text[0] == 0) {
wfree(text);
text = NULL;
}
updateCommand(panel->editedIcon, text);
#ifdef USE_DOCK_XDND
2009-08-20 00:59:40 +02:00
/* cannot free text from this, because it will be not be duplicated
2025-09-01 21:20:22 -04:00
* in wAppIconSetDnDCommand */
2009-08-20 00:59:40 +02:00
text = WMGetTextFieldText(panel->dndCommandField);
2025-09-01 21:20:22 -04:00
wAppIconSetDnDCommand(panel->editedIcon, text);
1998-09-29 22:36:29 +00:00
#endif
2009-08-20 00:59:40 +02:00
text = WMGetTextFieldText(panel->pasteCommandField);
2025-09-01 21:20:22 -04:00
wAppIconSetPasteCommand(panel->editedIcon, text);
1998-11-23 11:32:19 +00:00
2025-09-01 21:20:22 -04:00
wAppIconSetAutoLaunch(panel->editedIcon, WMGetButtonSelected(panel->autoLaunchBtn));
1999-10-20 03:25:06 +00:00
2025-09-01 21:20:22 -04:00
wAppIconSetLocked(panel->editedIcon, WMGetButtonSelected(panel->lockBtn));
2009-08-20 00:59:40 +02:00
}
1998-11-23 11:32:19 +00:00
DestroyDockAppSettingsPanel(panel);
1998-09-29 22:36:29 +00:00
}
2009-08-20 00:59:40 +02:00
void ShowDockAppSettingsPanel(WAppIcon * aicon)
1998-09-29 22:36:29 +00:00
{
2009-08-20 00:59:40 +02:00
AppSettingsPanel *panel;
2025-09-01 21:20:22 -04:00
WScreen *scr = wAppIconGetIcon(aicon)->core->screen_ptr;
2009-08-20 00:59:40 +02:00
Window parent;
WMFont *font;
int x, y;
WMBox *vbox;
int wmScaleWidth, wmScaleHeight;
int pwidth, pheight;
int iconSize;
/* get the width and height values of the system font for use with the WMScaleX/WMScaleY macros */
WMGetScaleBaseFromSystemFont(scr->wmscreen, &wmScaleWidth, &wmScaleHeight);
/* calculate the required width and height for the panel */
iconSize = wPreferences.icon_size;
pwidth = WMScaleX(300);
pheight = WMScaleY(10) /* upper margin */
+ iconSize /* icon and its label */
+ WMScaleY(10) /* padding */
+ WMScaleY(20) + WMScaleY(2) /* start option */
+ WMScaleY(20) + WMScaleY(5) /* lock option */
+ WMScaleY(50) + WMScaleY(5) /* app path and arguments */
+ WMScaleY(70) + WMScaleY(5) /* middle-click command */
+ WMScaleY(70) + WMScaleY(5) /* drag&drop command */
+ WMScaleY(50) + WMScaleY(10) /* icon file */
+ WMScaleY(24) /* buttons */
+ WMScaleY(10); /* lower margin */
2009-08-20 00:59:40 +02:00
panel = wmalloc(sizeof(AppSettingsPanel));
panel->editedIcon = aicon;
2025-09-01 21:20:22 -04:00
wAppIconSetPanel(aicon, panel);
wAppIconSetEditing(aicon, 1);
2009-08-20 00:59:40 +02:00
panel->win = WMCreateWindow(scr->wmscreen, "applicationSettings");
WMResizeWidget(panel->win, pwidth, pheight);
2009-08-20 00:59:40 +02:00
panel->iconLabel = WMCreateLabel(panel->win);
WMResizeWidget(panel->iconLabel, iconSize, iconSize);
WMMoveWidget(panel->iconLabel, WMScaleX(10), WMScaleY(10));
2009-08-20 00:59:40 +02:00
WMSetLabelImagePosition(panel->iconLabel, WIPImageOnly);
panel->nameLabel = WMCreateLabel(panel->win);
font = WMBoldSystemFontOfSize(scr->wmscreen, WMScaleY(14));
WMResizeWidget(panel->nameLabel, WMScaleX(190), WMScaleY(18));
WMMoveWidget(panel->nameLabel, 2 * WMScaleX(10) + iconSize, WMScaleY(10) + ((iconSize - WMFontHeight(font)) / 2));
2009-08-20 00:59:40 +02:00
WMSetLabelTextAlignment(panel->nameLabel, WALeft);
WMSetLabelFont(panel->nameLabel, font);
WMReleaseFont(font);
2025-09-01 21:20:22 -04:00
if (wAppIconGetWmClass(aicon) && strcmp(wAppIconGetWmClass(aicon), "DockApp") == 0)
WMSetLabelText(panel->nameLabel, wAppIconGetWmInstance(aicon));
2009-08-20 00:59:40 +02:00
else
2025-09-01 21:20:22 -04:00
WMSetLabelText(panel->nameLabel, wAppIconGetWmClass(aicon));
2009-08-20 00:59:40 +02:00
vbox = WMCreateBox(panel->win);
WMResizeWidget(vbox, pwidth - 2 * WMScaleX(10), pheight - iconSize - 3 * WMScaleY(10));
WMMoveWidget(vbox, WMScaleX(10), iconSize + 2 * WMScaleY(10));
2009-08-20 00:59:40 +02:00
panel->autoLaunchBtn = WMCreateSwitchButton(vbox);
WMAddBoxSubview(vbox, WMWidgetView(panel->autoLaunchBtn), False, True, WMScaleY(20), WMScaleY(20), WMScaleY(2));
2009-08-20 00:59:40 +02:00
WMSetButtonText(panel->autoLaunchBtn, _("Start when Window Maker is started"));
2025-09-01 21:20:22 -04:00
WMSetButtonSelected(panel->autoLaunchBtn, wAppIconIsAutoLaunch(aicon));
2009-08-20 00:59:40 +02:00
panel->lockBtn = WMCreateSwitchButton(vbox);
WMAddBoxSubview(vbox, WMWidgetView(panel->lockBtn), False, True, WMScaleY(20), WMScaleY(20), WMScaleY(5));
2009-08-20 00:59:40 +02:00
WMSetButtonText(panel->lockBtn, _("Lock (prevent accidental removal)"));
2025-09-01 21:20:22 -04:00
WMSetButtonSelected(panel->lockBtn, wAppIconIsLocked(aicon));
2009-08-20 00:59:40 +02:00
panel->commandFrame = WMCreateFrame(vbox);
WMSetFrameTitle(panel->commandFrame, _("Application path and arguments"));
WMAddBoxSubview(vbox, WMWidgetView(panel->commandFrame), False, True, WMScaleY(50), WMScaleY(50), WMScaleY(5));
2009-08-20 00:59:40 +02:00
panel->commandField = WMCreateTextField(panel->commandFrame);
WMResizeWidget(panel->commandField, WMScaleX(260), WMScaleY(20));
WMMoveWidget(panel->commandField, WMScaleX(10), WMScaleY(20));
2025-09-01 21:20:22 -04:00
WMSetTextFieldText(panel->commandField, wAppIconGetCommand(aicon));
2009-08-20 00:59:40 +02:00
WMMapSubwidgets(panel->commandFrame);
panel->pasteCommandFrame = WMCreateFrame(vbox);
WMSetFrameTitle(panel->pasteCommandFrame, _("Command for middle-click launch"));
WMAddBoxSubview(vbox, WMWidgetView(panel->pasteCommandFrame), False, True, WMScaleY(70), WMScaleY(70), WMScaleY(5));
2009-08-20 00:59:40 +02:00
panel->pasteCommandField = WMCreateTextField(panel->pasteCommandFrame);
WMResizeWidget(panel->pasteCommandField, WMScaleX(260), WMScaleY(20));
WMMoveWidget(panel->pasteCommandField, WMScaleX(10), WMScaleY(20));
2009-08-20 00:59:40 +02:00
panel->pasteCommandLabel = WMCreateLabel(panel->pasteCommandFrame);
WMResizeWidget(panel->pasteCommandLabel, WMScaleX(260), WMScaleY(18));
WMMoveWidget(panel->pasteCommandLabel, WMScaleX(10), WMScaleY(45));
2009-08-20 00:59:40 +02:00
2025-09-01 21:20:22 -04:00
WMSetTextFieldText(panel->pasteCommandField, wAppIconGetPasteCommand(aicon));
2009-08-20 00:59:40 +02:00
WMSetLabelText(panel->pasteCommandLabel, _("%s will be replaced with current selection"));
WMMapSubwidgets(panel->pasteCommandFrame);
panel->dndCommandFrame = WMCreateFrame(vbox);
2014-08-16 23:52:05 +08:00
WMSetFrameTitle(panel->dndCommandFrame, _("Command for dragged and dropped files"));
WMAddBoxSubview(vbox, WMWidgetView(panel->dndCommandFrame), False, True, WMScaleY(70), WMScaleY(70), WMScaleY(5));
2009-08-20 00:59:40 +02:00
panel->dndCommandField = WMCreateTextField(panel->dndCommandFrame);
WMResizeWidget(panel->dndCommandField, WMScaleX(260), WMScaleY(20));
WMMoveWidget(panel->dndCommandField, WMScaleX(10), WMScaleY(20));
2009-08-20 00:59:40 +02:00
panel->dndCommandLabel = WMCreateLabel(panel->dndCommandFrame);
WMResizeWidget(panel->dndCommandLabel, WMScaleX(260), WMScaleY(18));
WMMoveWidget(panel->dndCommandLabel, WMScaleX(10), WMScaleY(45));
#ifdef USE_DOCK_XDND
2025-09-01 21:20:22 -04:00
WMSetTextFieldText(panel->dndCommandField, wAppIconGetDnDCommand(aicon));
2009-08-20 00:59:40 +02:00
WMSetLabelText(panel->dndCommandLabel, _("%d will be replaced with the file name"));
1998-09-29 22:36:29 +00:00
#else
2009-08-20 00:59:40 +02:00
WMSetTextFieldEditable(panel->dndCommandField, False);
2014-08-16 23:52:05 +08:00
WMSetLabelText(panel->dndCommandLabel, _("XDnD support was not compiled in"));
WMSetFrameTitleColor(panel->dndCommandFrame, WMDarkGrayColor(scr->wmscreen));
WMSetLabelTextColor(panel->dndCommandLabel, WMDarkGrayColor(scr->wmscreen));
1998-09-29 22:36:29 +00:00
#endif
2009-08-20 00:59:40 +02:00
WMMapSubwidgets(panel->dndCommandFrame);
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
panel->iconFrame = WMCreateFrame(vbox);
WMSetFrameTitle(panel->iconFrame, _("Icon Image"));
WMAddBoxSubview(vbox, WMWidgetView(panel->iconFrame), False, True, WMScaleY(50), WMScaleY(50), WMScaleY(10));
2009-08-20 00:59:40 +02:00
panel->iconField = WMCreateTextField(panel->iconFrame);
WMResizeWidget(panel->iconField, WMScaleX(180), WMScaleY(20));
WMMoveWidget(panel->iconField, WMScaleX(10), WMScaleY(20));
2025-09-01 21:20:22 -04:00
WMSetTextFieldText(panel->iconField, wDefaultGetIconFile(wAppIconGetWmInstance(aicon), wAppIconGetWmClass(aicon), False));
2009-08-20 00:59:40 +02:00
panel->browseBtn = WMCreateCommandButton(panel->iconFrame);
WMResizeWidget(panel->browseBtn, WMScaleX(70), WMScaleY(24));
WMMoveWidget(panel->browseBtn, WMScaleX(200), WMScaleY(18));
2009-08-20 00:59:40 +02:00
WMSetButtonText(panel->browseBtn, _("Browse..."));
WMSetButtonAction(panel->browseBtn, chooseIconCallback, panel);
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
{
WMBox *hbox;
2009-08-20 00:59:40 +02:00
hbox = WMCreateBox(vbox);
WMSetBoxHorizontal(hbox, True);
WMAddBoxSubview(vbox, WMWidgetView(hbox), False, True, WMScaleY(24), WMScaleY(24), 0);
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
panel->okBtn = WMCreateCommandButton(hbox);
WMSetButtonText(panel->okBtn, _("OK"));
WMSetButtonAction(panel->okBtn, panelBtnCallback, panel);
WMAddBoxSubviewAtEnd(hbox, WMWidgetView(panel->okBtn), False, True, WMScaleX(80), WMScaleX(80), 0);
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
panel->cancelBtn = WMCreateCommandButton(hbox);
WMSetButtonText(panel->cancelBtn, _("Cancel"));
WMSetButtonAction(panel->cancelBtn, panelBtnCallback, panel);
WMAddBoxSubviewAtEnd(hbox, WMWidgetView(panel->cancelBtn), False, True, WMScaleX(80), WMScaleX(80), 5);
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
WMMapSubwidgets(hbox);
}
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
WMRealizeWidget(panel->win);
WMMapSubwidgets(panel->win);
WMMapSubwidgets(vbox);
WMMapSubwidgets(panel->iconFrame);
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
updateSettingsPanelIcon(panel);
2004-10-12 21:28:27 +00:00
parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, pwidth, pheight, 0, 0, 0);
2009-08-20 00:59:40 +02:00
XSelectInput(dpy, parent, KeyPressMask | KeyReleaseMask);
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
/*
* make things relative to head
*/
{
WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1998-09-29 22:36:29 +00:00
2025-09-01 21:20:22 -04:00
y = wAppIconGetYPos(aicon);
2009-08-20 00:59:40 +02:00
if (y < 0)
y = 0;
else if (y + pheight > rect.pos.y + rect.size.height)
y = rect.pos.y + rect.size.height - pheight - 3 * WMScaleY(10);
2025-09-01 21:20:22 -04:00
if (wAppIconGetDock(aicon) && wDockGetType(wAppIconGetDock(aicon)) == WM_DOCK) {
if (wDockIsOnRightSide(wAppIconGetDock(aicon)))
2009-08-20 00:59:40 +02:00
x = rect.pos.x + rect.size.width / 2;
else
x = rect.pos.x + rect.size.width / 2 - pwidth - WMScaleX(2);
2009-08-20 00:59:40 +02:00
} else {
x = rect.pos.x + (rect.size.width - pwidth) / 2;
2009-08-20 00:59:40 +02:00
}
}
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
panel->wwin = wManageInternalWindow(scr, parent, None,
_("Docked Application Settings"), x, y, pwidth, pheight);
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
panel->wwin->client_leader = WMWidgetXID(panel->win);
2009-08-20 00:59:40 +02:00
panel->parent = parent;
2009-08-20 00:59:40 +02:00
WMMapWidget(panel->win);
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
wWindowMap(panel->wwin);
1998-09-29 22:36:29 +00:00
}
2009-08-20 00:59:40 +02:00
void DestroyDockAppSettingsPanel(AppSettingsPanel * panel)
1998-09-29 22:36:29 +00:00
{
2009-08-20 00:59:40 +02:00
if (!panel->destroyed) {
XUnmapWindow(dpy, panel->wwin->client_win);
XReparentWindow(dpy, panel->wwin->client_win, panel->wwin->screen_ptr->root_win, 0, 0);
wUnmanageWindow(panel->wwin, False, False);
}
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
panel->destroyed = 1;
2009-08-20 00:59:40 +02:00
/*
* kluge. If we destroy the panel before the icon chooser is closed,
* we will crash when it does close, trying to access something in the
* destroyed panel. Could use wretain()/wrelease() in the panel,
* but it is not working for some reason.
*/
if (panel->choosingIcon)
return;
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
WMDestroyWidget(panel->win);
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
XDestroyWindow(dpy, panel->parent);
2025-09-01 21:20:22 -04:00
wAppIconSetPanel(panel->editedIcon, NULL);
2025-09-01 21:20:22 -04:00
wAppIconSetEditing(panel->editedIcon, 0);
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
wfree(panel);
1998-09-29 22:36:29 +00:00
}