summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Turney <jon.turney@dronecode.org.uk>2016-02-19 21:53:00 +0000
committerJon Turney <jon.turney@dronecode.org.uk>2018-05-13 18:21:59 +0100
commitdaf134f0a57107db96ba371f1211651da738cec2 (patch)
tree5ef51ebf6c5632845d5a6f4a3c35ea8cd87d11fd
parentdbce3981bd2407d51f64285a8b72bebf28424054 (diff)
Add -icon option to set the screen window icon in windowed mode
Add an -icon option to set the screen window icon in windowed mode Allow cygwin paths in an icon-specification Update man pages and system.XWinrc appropriately Also, log an error if the icon specified for TRAYICON cannot be loaded Also, fix a bug in appending a '\' to IconDirectory only if it doesn't already end with one, which was fortunately benign. Also, if we are exiting in ddxProcessArgument() due to an error in options, use a non-zero exit status. XXX: LoadImageComma would be simpler if we just said that XWinrc paths are Cygwin paths on Cygwin, Windows paths on MinGW, but that could break existing .XWinrc files XXX: Given that we can specify paths, I'm not sure what IconDirectory wins us. v2: Fix formatting problems in man page additions
-rw-r--r--hw/xwin/InitOutput.c2
-rw-r--r--hw/xwin/man/XWin.man4
-rw-r--r--hw/xwin/man/XWinrc.man29
-rw-r--r--hw/xwin/system.XWinrc12
-rw-r--r--hw/xwin/win.h4
-rw-r--r--hw/xwin/wincreatewnd.c20
-rw-r--r--hw/xwin/winprefs.c74
-rw-r--r--hw/xwin/winprefs.h4
-rw-r--r--hw/xwin/winprocarg.c38
9 files changed, 129 insertions, 58 deletions
diff --git a/hw/xwin/InitOutput.c b/hw/xwin/InitOutput.c
index ed2950d2b..03540fa6d 100644
--- a/hw/xwin/InitOutput.c
+++ b/hw/xwin/InitOutput.c
@@ -779,6 +779,8 @@ winUseMsg(void)
ErrorF("-[no]hostintitle\n"
"\tIn multiwindow mode, add remote host names to window titles.\n");
+ ErrorF("-icon icon_specifier\n" "\tSet screen window icon in windowed mode.\n");
+
ErrorF("-ignoreinput\n" "\tIgnore keyboard and mouse input.\n");
#ifdef XWIN_XF86CONFIG
diff --git a/hw/xwin/man/XWin.man b/hw/xwin/man/XWin.man
index 3eedf0174..a22baf62a 100644
--- a/hw/xwin/man/XWin.man
+++ b/hw/xwin/man/XWin.man
@@ -113,6 +113,10 @@ The X server window takes the full screen, covering completely the
\fIWindows\fP desktop.
Currently \fB\-fullscreen\fP may only be applied to one X screen.
.TP 8
+.B "\-icon" \fIicon-specifier\fP
+Override the window icon for the screen window from the default.
+The \fIicon-specifier\fP is as defined in \fIXWinrc(__filemansuffix__)\fP.
+.TP 8
.B \-nodecoration
Do not give the Cygwin/X window a \fIWindows\fP window border, title bar,
etc.
diff --git a/hw/xwin/man/XWinrc.man b/hw/xwin/man/XWinrc.man
index 07fd00f38..15eaca652 100644
--- a/hw/xwin/man/XWinrc.man
+++ b/hw/xwin/man/XWinrc.man
@@ -163,31 +163,34 @@ such items should be included at the start or at the end of the menu.
.SH Icon Instructions
-When specifying an \fIicon-file\fP in the following commands several different formats are allowed:
-.br
-\fB"NAME.ICO"\fP\fI of an .ico format file\fP
-.br
-\t \t ("cygwin.ico", "apple.ico")
-.br
-\fB"NAME.DLL,nn"\fP\fI of a .DLL and icon index\fP
+When specifying an \fIicon-specifier\fP in the following commands several different formats are allowed:
+.PP
+.IP \fI"NAME.ICO"\fP 16
+filename of an .ico format file
.br
-\t \t ("c:\\windows\\system32\\shell32.dll,4" is the default folder icon)
+(e.g. "cygwin.ico", "apple.ico", "C:\\icons\\cheese.ico", "/usr/share/icons/moon.ico")
+.IP \fI"NAME.DLL,nnn"\fP 16
+filename of a DLL with an index into it's ICON resources
.br
-\fB",nnn"\fP\fI index into XWin.EXE internal ICON resources\fP
+(e.g. "c:\\windows\\system32\\shell32.dll,4", the default folder icon,
+ "/usr/bin/cygicons-0.dll,10", the hippo icon)
+.IP \fI",nnn"\fP 16
+index into the XWin executable's internal ICON resources
.br
-\t \t (",101" is the 1st icon inside \fIXWin.EXE\fP)
+(e.g. ",101" is the 1st icon in \fIXWin\fP)
.TP 8
.B ICONDIRECTORY \fIWindows-path-to-icon-directory\fP
-Defines the default directory to search for \ficon-file\fP files.
+Defines the default directory for the file when an \fIicon-specifier\fP doesn't
+contain an absolute path.
It should be a \fIWindows\fP style path (e.g. C:\\cygwin\\usr\\local\\icons).
.TP 8
-.B DEFAULTICON \fIicon-file\fP
+.B DEFAULTICON \fIicon-specifier\fP
Defines a replacement for the standard X icon for applications without
specified icons.
.TP 8
.B ICONS {
.br
- \fIclass-or-name-of-window\fP \fIicon-file\fP
+ \fIclass-or-name-of-window\fP \fIicon-specifier\fP
.br
\fI...\fP
.br
diff --git a/hw/xwin/system.XWinrc b/hw/xwin/system.XWinrc
index 87d714a68..c2e9ceb9a 100644
--- a/hw/xwin/system.XWinrc
+++ b/hw/xwin/system.XWinrc
@@ -8,10 +8,6 @@
# Comments begin with "#" or "//" and go to the end-of-line
-# Paths to commands are **cygwin** based (i.e. /usr/local/bin/xcalc)
-
-# Paths to icons are **WINDOWS** based (i.e. c:\windows\icons)
-
# Menus are defined as...
# MENU <name> {
# <Menu Text> EXEC <command>
@@ -55,15 +51,15 @@
# To define where ICO files live (** Windows path**)
# ICONDIRECTORY <windows-path i.e. c:\cygwin\usr\icons>
-# NOTE: If you specify a fully qualified path to an ICON below
-# (i.e. "c:\xxx" or "d:\xxxx")
+# NOTE: If you specify an absolute path in Windows or Cygwin format to an ICON below
+# (i.e. "c:\icons\xxx.ico" or "/usr/share/icons/xxx.ico")
# this ICONDIRECTORY will not be prepended
# To change the taskbar icon use...
-# TRAYICON <name-of-windows-ico-file-in-icondirectory>
+# TRAYICON <icon-specifier>
# To define a replacement for the standard X icon for apps w/o specified icons
-# DEFAULTICON <name-of-windows-ico-file-in-icondirectory>
+# DEFAULTICON <icon-specifier>
# To define substitute icons on a per-window basis use...
# ICONS {
diff --git a/hw/xwin/win.h b/hw/xwin/win.h
index a6eb9f81d..ff5570ec5 100644
--- a/hw/xwin/win.h
+++ b/hw/xwin/win.h
@@ -412,6 +412,10 @@ typedef struct {
/* Did the user explicitly set this screen? */
Bool fExplicitScreen;
+
+ /* Icons for screen window */
+ HICON hIcon;
+ HICON hIconSm;
} winScreenInfo, *winScreenInfoPtr;
/*
diff --git a/hw/xwin/wincreatewnd.c b/hw/xwin/wincreatewnd.c
index daa6daac9..4205e0357 100644
--- a/hw/xwin/wincreatewnd.c
+++ b/hw/xwin/wincreatewnd.c
@@ -72,18 +72,12 @@ winCreateBoundingWindowFullScreen(ScreenPtr pScreen)
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = g_hInstance;
- wc.hIcon =
- (HICON) LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_XWIN), IMAGE_ICON,
- GetSystemMetrics(SM_CXICON),
- GetSystemMetrics(SM_CYICON), 0);
+ wc.hIcon = pScreenInfo->hIcon;
wc.hCursor = 0;
wc.hbrBackground = 0;
wc.lpszMenuName = NULL;
wc.lpszClassName = WINDOW_CLASS;
- wc.hIconSm =
- (HICON) LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_XWIN), IMAGE_ICON,
- GetSystemMetrics(SM_CXSMICON),
- GetSystemMetrics(SM_CYSMICON), LR_DEFAULTSIZE);
+ wc.hIconSm = pScreenInfo->hIconSm;
RegisterClassEx(&wc);
/* Set display and screen-specific tooltip text */
@@ -182,18 +176,12 @@ winCreateBoundingWindowWindowed(ScreenPtr pScreen)
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = g_hInstance;
- wc.hIcon =
- (HICON) LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_XWIN), IMAGE_ICON,
- GetSystemMetrics(SM_CXICON),
- GetSystemMetrics(SM_CYICON), 0);
+ wc.hIcon = pScreenInfo->hIcon;
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = WINDOW_CLASS;
- wc.hIconSm =
- (HICON) LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_XWIN), IMAGE_ICON,
- GetSystemMetrics(SM_CXSMICON),
- GetSystemMetrics(SM_CYSMICON), LR_DEFAULTSIZE);
+ wc.hIconSm = pScreenInfo->hIconSm;
RegisterClassEx(&wc);
/* Get size of work area */
diff --git a/hw/xwin/winprefs.c b/hw/xwin/winprefs.c
index 59a0f01c9..1afba3165 100644
--- a/hw/xwin/winprefs.c
+++ b/hw/xwin/winprefs.c
@@ -39,6 +39,7 @@
#include <sys/resource.h>
#include <sys/wait.h>
#include <pthread.h>
+#include <sys/cygwin.h>
#endif
#include "win.h"
@@ -61,9 +62,6 @@ extern int parse_file(FILE * fp);
/* Currently in use command ID, incremented each new menu item created */
static int g_cmdid = STARTMENUID;
-/* Local function to handle comma-ified icon names */
-static HICON LoadImageComma(char *fname, int sx, int sy, int flags);
-
/*
* Creates or appends a menu from a MENUPARSED structure
*/
@@ -575,7 +573,7 @@ winOverrideDefaultIcon(int size)
HICON hicon;
if (pref.defaultIconName[0]) {
- hicon = LoadImageComma(pref.defaultIconName, size, size, 0);
+ hicon = LoadImageComma(pref.defaultIconName, pref.iconDirectory, size, size, 0);
if (hicon == NULL)
ErrorF("winOverrideDefaultIcon: LoadImageComma(%s) failed\n",
pref.defaultIconName);
@@ -597,9 +595,12 @@ winTaskbarIcon(void)
hicon = 0;
/* First try and load an overridden, if success then return it */
if (pref.trayIconName[0]) {
- hicon = LoadImageComma(pref.trayIconName,
+ hicon = LoadImageComma(pref.trayIconName, pref.iconDirectory,
GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON), 0);
+ if (hicon == NULL)
+ ErrorF("winTaskbarIcon: LoadImageComma(%s) failed\n",
+ pref.trayIconName);
}
/* Otherwise return the default */
@@ -614,17 +615,18 @@ winTaskbarIcon(void)
}
/*
+ * Handle comma-ified icon names
+ *
* Parse a filename to extract an icon:
* If fname is exactly ",nnn" then extract icon from our resource
* else if it is "file,nnn" then extract icon nnn from that file
* else try to load it as an .ico file and if that fails return NULL
*/
-static HICON
-LoadImageComma(char *fname, int sx, int sy, int flags)
+HICON
+LoadImageComma(char *fname, char *iconDirectory, int sx, int sy, int flags)
{
HICON hicon;
int i;
- char file[PATH_MAX + NAME_MAX + 2];
/* Some input error checking */
if (!fname || !fname[0])
@@ -640,31 +642,67 @@ LoadImageComma(char *fname, int sx, int sy, int flags)
MAKEINTRESOURCE(i), IMAGE_ICON, sx, sy, flags);
}
else {
+ char *file = malloc(PATH_MAX + NAME_MAX + 2);
+ Bool convert = FALSE;
+
+ if (!file)
+ return NULL;
+
file[0] = 0;
- /* Prepend path if not given a "X:\" filename */
+
+ /* If fname starts 'X:\', it's an absolute Windows path, do nothing */
if (!(fname[0] && fname[1] == ':' && fname[2] == '\\')) {
- strcpy(file, pref.iconDirectory);
- if (pref.iconDirectory[0])
- if (fname[strlen(fname) - 1] != '\\')
- strcat(file, "\\");
+#ifdef __CYGWIN__
+ /* If fname starts with '/', it's an absolute cygwin path, we'll
+ need to convert it */
+ if (fname[0] == '/') {
+ convert = TRUE;
+ }
+ else
+#endif
+ if (iconDirectory) {
+ /* Otherwise, prepend the default icon directory, which
+ currently must be in absolute Windows path form */
+ strcpy(file, iconDirectory);
+ if (iconDirectory[0])
+ if (iconDirectory[strlen(iconDirectory) - 1] != '\\')
+ strcat(file, "\\");
+ }
}
strcat(file, fname);
+ /* Trim off any ',index' */
if (strrchr(file, ',')) {
- /* Specified as <fname>,<index> */
-
*(strrchr(file, ',')) = 0; /* End string at comma */
i = atoi(strrchr(fname, ',') + 1);
- hicon = ExtractIcon(g_hInstance, file, i);
}
else {
- /* Just an .ico file... */
+ i = -1;
+ }
+#ifdef __CYGWIN__
+ /* Convert from Cygwin path to Windows path */
+ if (convert) {
+ char *converted_file = cygwin_create_path(CCP_POSIX_TO_WIN_A | CCP_ABSOLUTE, file);
+ if (converted_file) {
+ free(file);
+ file = converted_file;
+ }
+ }
+#endif
+
+ if (i >= 0) {
+ /* Specified as <fname>,<index> */
+ hicon = ExtractIcon(g_hInstance, file, i);
+ }
+ else {
+ /* Specified as just an .ico file */
hicon = (HICON) LoadImage(NULL,
file,
IMAGE_ICON,
sx, sy, LR_LOADFROMFILE | flags);
}
+ free(file);
}
return hicon;
}
@@ -686,7 +724,7 @@ winOverrideIcon(char *res_name, char *res_class, char *wmName)
if (pref.icon[i].hicon)
return pref.icon[i].hicon;
- hicon = LoadImageComma(pref.icon[i].iconFile, 0, 0, LR_DEFAULTSIZE);
+ hicon = LoadImageComma(pref.icon[i].iconFile, pref.iconDirectory, 0, 0, LR_DEFAULTSIZE);
if (hicon == NULL)
ErrorF("winOverrideIcon: LoadImageComma(%s) failed\n",
pref.icon[i].iconFile);
diff --git a/hw/xwin/winprefs.h b/hw/xwin/winprefs.h
index 36f3f4152..d1fef2ed9 100644
--- a/hw/xwin/winprefs.h
+++ b/hw/xwin/winprefs.h
@@ -173,4 +173,8 @@ unsigned long
HICON winTaskbarIcon(void);
HICON winOverrideDefaultIcon(int size);
+
+HICON
+LoadImageComma(char *fname, char *iconDirectory, int sx, int sy, int flags);
+
#endif
diff --git a/hw/xwin/winprocarg.c b/hw/xwin/winprocarg.c
index 66fda3805..3f3c1c2be 100644
--- a/hw/xwin/winprocarg.c
+++ b/hw/xwin/winprocarg.c
@@ -40,6 +40,7 @@ from The Open Group.
#include "winconfig.h"
#include "winmsg.h"
#include "winmonitors.h"
+#include "winprefs.h"
#include "winclipboard/winclipboard.h"
@@ -142,6 +143,13 @@ winInitializeScreenDefaults(void)
defaultScreenInfo.fUseUnixKillKey = WIN_DEFAULT_UNIX_KILL;
defaultScreenInfo.fIgnoreInput = FALSE;
defaultScreenInfo.fExplicitScreen = FALSE;
+ defaultScreenInfo.hIcon = (HICON)
+ LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_XWIN), IMAGE_ICON,
+ GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0);
+ defaultScreenInfo.hIconSm = (HICON)
+ LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_XWIN), IMAGE_ICON,
+ GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
+ LR_DEFAULTSIZE);
/* Note that the default screen has been initialized */
fInitializedScreenDefaults = TRUE;
@@ -341,7 +349,7 @@ ddxProcessArgument(int argc, char *argv[], int i)
("ddxProcessArgument - screen - Invalid monitor number %d\n",
iMonitor);
UseMsg();
- exit(0);
+ exit(1);
return 0;
}
}
@@ -390,7 +398,7 @@ ddxProcessArgument(int argc, char *argv[], int i)
("ddxProcessArgument - screen - Invalid monitor number %d\n",
iMonitor);
UseMsg();
- exit(0);
+ exit(1);
return 0;
}
@@ -421,7 +429,7 @@ ddxProcessArgument(int argc, char *argv[], int i)
("ddxProcessArgument - screen - Invalid monitor number %d\n",
iMonitor);
UseMsg();
- exit(0);
+ exit(1);
return 0;
}
@@ -1103,6 +1111,30 @@ ddxProcessArgument(int argc, char *argv[], int i)
return 1;
}
+ if (IS_OPTION("-icon")) {
+ char *iconspec;
+ CHECK_ARGS(1);
+ iconspec = argv[++i];
+ screenInfoPtr->hIcon = LoadImageComma(iconspec, NULL,
+ GetSystemMetrics(SM_CXICON),
+ GetSystemMetrics(SM_CYICON),
+ 0);
+ screenInfoPtr->hIconSm = LoadImageComma(iconspec, NULL,
+ GetSystemMetrics(SM_CXSMICON),
+ GetSystemMetrics(SM_CYSMICON),
+ LR_DEFAULTSIZE);
+ if ((screenInfoPtr->hIcon == NULL) ||
+ (screenInfoPtr->hIconSm == NULL)) {
+ ErrorF("ddxProcessArgument - icon - Invalid icon specification %s\n",
+ iconspec);
+ exit(1);
+ return 0;
+ }
+
+ /* Indicate that we have processed the argument */
+ return 2;
+ }
+
return 0;
}