summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
Diffstat (limited to 'hw')
-rw-r--r--hw/xwin/InitOutput.c6
-rw-r--r--hw/xwin/_usr_X11R6_lib_X11_system.XWinrc16
-rw-r--r--hw/xwin/winprefs.c143
-rw-r--r--hw/xwin/winprefs.h6
-rw-r--r--hw/xwin/winprefslex.l1
-rw-r--r--hw/xwin/winprefsyacc.y14
-rwxr-xr-xhw/xwin/wintrayicon.c7
7 files changed, 151 insertions, 42 deletions
diff --git a/hw/xwin/InitOutput.c b/hw/xwin/InitOutput.c
index f5a243268..d080a10e3 100644
--- a/hw/xwin/InitOutput.c
+++ b/hw/xwin/InitOutput.c
@@ -463,6 +463,9 @@ InitOutput (ScreenInfo *screenInfo, int argc, char *argv[])
winMsg(X_INFO, "XF86Config is not supported. See http://x.cygwin.com/docs/faq/cygwin-xfree-faq.html for more information\n");
#endif
+ /* Load preferences from XWinrc file */
+ LoadPreferences();
+
/* Setup global screen info parameters */
screenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
screenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
@@ -516,9 +519,6 @@ InitOutput (ScreenInfo *screenInfo, int argc, char *argv[])
}
}
- /* Load preferences from XWinrc file */
- LoadPreferences();
-
#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
#if defined(XCSECURITY)
diff --git a/hw/xwin/_usr_X11R6_lib_X11_system.XWinrc b/hw/xwin/_usr_X11R6_lib_X11_system.XWinrc
index dbd79f2bf..27d1d12e0 100644
--- a/hw/xwin/_usr_X11R6_lib_X11_system.XWinrc
+++ b/hw/xwin/_usr_X11R6_lib_X11_system.XWinrc
@@ -40,8 +40,24 @@
# ...
# }
+# When specifying an ICONFILE in the following commands several different
+# formats are allowed:
+# 1. Name of a regular Windows .ico format file
+# (ex: "cygwin.ico", "apple.ico")
+# 2. Name and index into a Windows .DLL
+# (ex: "c:\windows\system32\shell32.dll,4" gives the default folder icon
+# "c:\windows\system32\shell32.dll,5" gives the floppy drive icon)
+# 3. Index into XWin.EXE internal ICON resource
+# (ex: ",101" is the 1st icon inside XWin.exe)
+
# 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")
+# this ICONDIRECTORY will not be prepended
+
+# To change the taskbar icon use...
+# TRAYICON <name-of-windows-ico-file-in-icondirectory>
# To define a replacement for the standard X icon for apps w/o specified icons
# DEFAULTICON <name-of-windows-ico-file-in-icondirectory>
diff --git a/hw/xwin/winprefs.c b/hw/xwin/winprefs.c
index 589fc678e..bead229df 100644
--- a/hw/xwin/winprefs.c
+++ b/hw/xwin/winprefs.c
@@ -37,6 +37,7 @@
/* Fixups to prevent collisions between Windows and X headers */
#define ATOM DWORD
#include <windows.h>
+#include <shellapi.h>
#include "winprefs.h"
#include "winmultiwindowclass.h"
@@ -65,6 +66,11 @@ static int g_cmdid = STARTMENUID;
/* Defined in DIX */
extern char *display;
+/* 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
*/
@@ -227,6 +233,7 @@ ReloadPrefs (void)
pref.iconDirectory[0] = 0;
pref.defaultIconName[0] = 0;
+ pref.trayIconName[0] = 0;
for (i=0; i<pref.iconItems; i++)
if (pref.icon[i].hicon)
@@ -462,25 +469,13 @@ unsigned long
winOverrideDefaultIcon()
{
HICON hicon;
- char fname[PATH_MAX+NAME_MAX+2];
if (pref.defaultIconName[0])
{
- /* Make sure we have a dir with trailing backslash */
- /* Note we are using _Windows_ paths here, not cygwin */
- strcpy (fname, pref.iconDirectory);
- if (pref.iconDirectory[0])
- if (fname[strlen(fname)-1]!='\\')
- strcat (fname, "\\");
- strcat (fname, pref.defaultIconName);
-
- hicon = (HICON)LoadImage(NULL,
- fname,
- IMAGE_ICON,
- 0, 0,
- LR_DEFAULTSIZE|LR_LOADFROMFILE);
+ hicon = LoadImageComma (pref.defaultIconName, 0, 0, LR_DEFAULTSIZE);
if (hicon==NULL)
- ErrorF ("winOverrideDefaultIcon: LoadIcon(%s) failed\n", fname);
+ ErrorF ("winOverrideDefaultIcon: LoadIcon(%s) failed\n",
+ pref.defaultIconName);
return (unsigned long)hicon;
}
@@ -490,6 +485,104 @@ winOverrideDefaultIcon()
/*
+ * Return the HICON to use in the taskbar notification area
+ */
+unsigned long
+winTaskbarIcon(void)
+{
+ HICON hicon;
+
+ hicon = 0;
+ /* First try and load an overridden, if success then return it */
+ if (pref.trayIconName[0])
+ {
+ hicon = LoadImageComma (pref.trayIconName,
+ GetSystemMetrics (SM_CXSMICON),
+ GetSystemMetrics (SM_CYSMICON),
+ 0 );
+ }
+
+ /* Otherwise return the default */
+ if (!hicon)
+ hicon = (HICON) LoadImage (g_hInstance,
+ MAKEINTRESOURCE(IDI_XWIN),
+ IMAGE_ICON,
+ GetSystemMetrics (SM_CXSMICON),
+ GetSystemMetrics (SM_CYSMICON),
+ 0);
+
+ return (unsigned long)hicon;
+}
+
+
+/*
+ * 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 hicon;
+ int index;
+ char file[PATH_MAX+NAME_MAX+2];
+
+ /* Some input error checking */
+ if (!fname || !fname[0])
+ return NULL;
+
+ index = 0;
+ hicon = NULL;
+
+ if (fname[0]==',')
+ {
+ /* It's the XWIN.EXE resource they want */
+ index = atoi (fname+1);
+ hicon = LoadImage (g_hInstance,
+ MAKEINTRESOURCE(index),
+ IMAGE_ICON,
+ sx,
+ sy,
+ flags);
+ }
+ else
+ {
+ file[0] = 0;
+ /* Prepend path if not given a "X:\" filename */
+ if ( !(fname[0] && fname[1]==':' && fname[2]=='\\') )
+ {
+ strcpy (file, pref.iconDirectory);
+ if (pref.iconDirectory[0])
+ if (fname[strlen(fname)-1]!='\\')
+ strcat (file, "\\");
+ }
+ strcat (file, fname);
+
+ if (strrchr (file, ','))
+ {
+ /* Specified as <fname>,<index> */
+
+ *(strrchr (file, ',')) = 0; /* End string at comma */
+ index = atoi (strrchr (fname, ',') + 1);
+ hicon = ExtractIcon (g_hInstance, file, index);
+ }
+ else
+ {
+ /* Just an .ico file... */
+
+ hicon = (HICON)LoadImage (NULL,
+ file,
+ IMAGE_ICON,
+ sx,
+ sy,
+ LR_LOADFROMFILE|flags);
+ }
+ }
+ return hicon;
+}
+
+/*
* Check for a match of the window class to one specified in the
* ICONS{} section in the prefs file, and load the icon from a file
*/
@@ -500,7 +593,6 @@ winOverrideIcon (unsigned long longWin)
char *res_name, *res_class;
int i;
HICON hicon;
- char fname[PATH_MAX+NAME_MAX+2];
char *wmName;
if (pWin==NULL)
@@ -525,21 +617,10 @@ winOverrideIcon (unsigned long longWin)
if (pref.icon[i].hicon)
return pref.icon[i].hicon;
- /* Make sure we have a dir with trailing backslash */
- /* Note we are using _Windows_ paths here, not cygwin */
- strcpy (fname, pref.iconDirectory);
- if (pref.iconDirectory[0])
- if (fname[strlen(fname)-1]!='\\')
- strcat (fname, "\\");
- strcat (fname, pref.icon[i].iconFile);
-
- hicon = (HICON)LoadImage(NULL,
- fname,
- IMAGE_ICON,
- 0, 0,
- LR_DEFAULTSIZE|LR_LOADFROMFILE);
- if (hicon==NULL)
- ErrorF ("winOverrideIcon: LoadIcon(%s) failed\n", fname);
+ hicon = LoadImageComma (pref.icon[i].iconFile, 0, 0, LR_DEFAULTSIZE);
+ if (hicon==NULL)
+ ErrorF ("winOverrideIcon: LoadIcon(%s) failed\n",
+ pref.icon[i].iconFile);
pref.icon[i].hicon = (unsigned long)hicon;
return (unsigned long)hicon;
diff --git a/hw/xwin/winprefs.h b/hw/xwin/winprefs.h
index 843cd2e0d..bd3b7831b 100644
--- a/hw/xwin/winprefs.h
+++ b/hw/xwin/winprefs.h
@@ -41,7 +41,7 @@
#define NAME_MAX PATH_MAX
#endif
#define MENU_MAX 128 /* Maximum string length of a menu name or item */
-#define PARAM_MAX (4*PATH_MAX) /* Maximim length of a parameter to a MENU */
+#define PARAM_MAX (4*PATH_MAX) /* Maximum length of a parameter to a MENU */
/* Supported commands in a MENU {} statement */
@@ -114,6 +114,7 @@ typedef struct WINPREFS
/* Icon information */
char iconDirectory[PATH_MAX+1]; /* Where do the .icos lie? (Win32 path) */
char defaultIconName[NAME_MAX+1]; /* Replacement for x.ico */
+ char trayIconName[NAME_MAX+1]; /* Replacement for tray icon */
ICONITEM *icon;
int iconItems;
@@ -148,5 +149,8 @@ unsigned long
winOverrideIcon (unsigned long longpWin);
unsigned long
+winTaskbarIcon(void);
+
+unsigned long
winOverrideDefaultIcon(void);
#endif
diff --git a/hw/xwin/winprefslex.l b/hw/xwin/winprefslex.l
index 77303c290..595a94a67 100644
--- a/hw/xwin/winprefslex.l
+++ b/hw/xwin/winprefslex.l
@@ -80,6 +80,7 @@ static char *makestr(char *str)
[aA][lL][wW][aA][yY][sS][oO][nN][tT][oO][pP] { return ALWAYSONTOP; }
[dD][eE][bB][uU][gG] { return DEBUG; }
[rR][eE][lL][oO][aA][dD] { return RELOAD; }
+[tT][rR][aA][yY][iI][cC][oO][nN] { return TRAYICON; }
"{" { return LB; }
"}" { return RB; }
"\""[^\"\r\n]+"\"" { yylval.sVal = makestr(yytext+1); \
diff --git a/hw/xwin/winprefsyacc.y b/hw/xwin/winprefsyacc.y
index 49ef41754..bfee9c105 100644
--- a/hw/xwin/winprefsyacc.y
+++ b/hw/xwin/winprefsyacc.y
@@ -51,6 +51,7 @@ static void SetIconDirectory (char *path);
static void SetDefaultIcon (char *fname);
static void SetRootMenu (char *menu);
static void SetDefaultSysMenu (char *menu, int pos);
+static void SetTrayIcon (char *fname);
static void OpenMenu(char *menuname);
static void AddMenuLine(char *name, MENUCOMMANDTYPE cmd, char *param);
@@ -79,7 +80,7 @@ extern int yylex(void);
%token NEWLINE MENU LB RB ICONDIRECTORY DEFAULTICON ICONS DEFAULTSYSMENU
%token SYSMENU ROOTMENU SEPARATOR ATSTART ATEND EXEC ALWAYSONTOP DEBUG
-%token RELOAD
+%token RELOAD TRAYICON
%token <sVal> STRING
%type <iVal> atspot
@@ -107,6 +108,10 @@ command: defaulticon
| rootmenu
| defaultsysmenu
| debug
+ | trayicon
+ ;
+
+trayicon: TRAYICON STRING NEWLINE { SetTrayIcon($2); free($2); }
;
rootmenu: ROOTMENU STRING NEWLINE { SetRootMenu($2); free($2); }
@@ -193,6 +198,13 @@ SetDefaultIcon (char *fname)
}
static void
+SetTrayIcon (char *fname)
+{
+ strncpy (pref.trayIconName, fname, NAME_MAX);
+ pref.trayIconName[NAME_MAX] = 0;
+ ErrorF("trayiconname: %s\n", pref.trayIconName);
+}
+static void
SetRootMenu (char *menu)
{
strncpy (pref.rootMenuName, menu, MENU_MAX);
diff --git a/hw/xwin/wintrayicon.c b/hw/xwin/wintrayicon.c
index 35b2fecec..4b87d248a 100755
--- a/hw/xwin/wintrayicon.c
+++ b/hw/xwin/wintrayicon.c
@@ -49,12 +49,7 @@ winInitNotifyIcon (winPrivScreenPtr pScreenPriv)
nid.uID = pScreenInfo->dwScreen;
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
nid.uCallbackMessage = WM_TRAYICON;
- nid.hIcon = LoadImage (g_hInstance,
- MAKEINTRESOURCE(IDI_XWIN),
- IMAGE_ICON,
- GetSystemMetrics (SM_CXSMICON),
- GetSystemMetrics (SM_CYSMICON),
- 0);
+ nid.hIcon = (HICON)winTaskbarIcon ();
/* Save handle to the icon so it can be freed later */
pScreenPriv->hiconNotifyIcon = nid.hIcon;