mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-20 04:48:06 +01:00
Fix wIconUpdate logic
This patch changes the logic for choosing the icon, and gets rid of wIconChangeImage in favor of wIconChangeImageFile. Old logic: * On create, load either NET_WM_ICON or the file from disk. * On update, choose (in order): 1. WM_HINTS icon_window 2. WM_HINTS icon_pixmap 3. Whatever was loaded on creation, unless wIconChangeImage or wIconChangeImageFile was called. 4. Default icon. New logic: * On update, choose (in order): 1. WM_HINTS icon_window 2. NET_WM_ICON 3. WM_HINTS icon_pixmap 4. Icon file from disk. 5. Default icon. Signed-off-by: Brad Jorsch <anomie@users.sourceforge.net>
This commit is contained in:
committed by
Carlos R. Mafra
parent
7aff3b6e44
commit
ee1f13da45
@@ -364,7 +364,6 @@ WApplication *wApplicationCreate(WWindow * wwin)
|
|||||||
if (wapp->app_icon) {
|
if (wapp->app_icon) {
|
||||||
char *tmp, *path;
|
char *tmp, *path;
|
||||||
struct stat dummy;
|
struct stat dummy;
|
||||||
RImage *image;
|
|
||||||
|
|
||||||
tmp = wDefaultGetIconFile(scr, wapp->app_icon->wm_instance, wapp->app_icon->wm_class, True);
|
tmp = wDefaultGetIconFile(scr, wapp->app_icon->wm_instance, wapp->app_icon->wm_class, True);
|
||||||
|
|
||||||
@@ -377,16 +376,8 @@ WApplication *wApplicationCreate(WWindow * wwin)
|
|||||||
if (path) {
|
if (path) {
|
||||||
wfree(path);
|
wfree(path);
|
||||||
}
|
}
|
||||||
image = wDefaultGetImage(scr, wapp->app_icon->wm_instance, wapp->app_icon->wm_class);
|
wIconUpdate(wapp->app_icon->icon);
|
||||||
if (image) {
|
wAppIconPaint(wapp->app_icon);
|
||||||
wIconChangeImage(wapp->app_icon->icon, image);
|
|
||||||
wAppIconPaint(wapp->app_icon);
|
|
||||||
/* TODO:
|
|
||||||
* wIconChangeImage() should be rewriten to use retain/release
|
|
||||||
* The way it is now is too confusing about where the icon is
|
|
||||||
* finally released. -Dan */
|
|
||||||
/* --this is wrong at the moment-- RReleaseImage(image); */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if the displayed icon was supplied by the client, save the icon */
|
/* if the displayed icon was supplied by the client, save the icon */
|
||||||
|
|||||||
@@ -1139,17 +1139,8 @@ void wDefaultUpdateIcons(WScreen * scr)
|
|||||||
file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class, False);
|
file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class, False);
|
||||||
if ((file && aicon->icon->file && strcmp(file, aicon->icon->file) != 0)
|
if ((file && aicon->icon->file && strcmp(file, aicon->icon->file) != 0)
|
||||||
|| (file && !aicon->icon->file)) {
|
|| (file && !aicon->icon->file)) {
|
||||||
RImage *new_image;
|
wIconChangeImageFile(aicon->icon, file);
|
||||||
|
wAppIconPaint(aicon);
|
||||||
if (aicon->icon->file)
|
|
||||||
wfree(aicon->icon->file);
|
|
||||||
aicon->icon->file = wstrdup(file);
|
|
||||||
|
|
||||||
new_image = wDefaultGetImage(scr, aicon->wm_instance, aicon->wm_class);
|
|
||||||
if (new_image) {
|
|
||||||
wIconChangeImage(aicon->icon, new_image);
|
|
||||||
wAppIconPaint(aicon);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
aicon = aicon->next;
|
aicon = aicon->next;
|
||||||
}
|
}
|
||||||
@@ -1162,15 +1153,7 @@ void wDefaultUpdateIcons(WScreen * scr)
|
|||||||
file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class, False);
|
file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class, False);
|
||||||
if ((file && wwin->icon->file && strcmp(file, wwin->icon->file) != 0)
|
if ((file && wwin->icon->file && strcmp(file, wwin->icon->file) != 0)
|
||||||
|| (file && !wwin->icon->file)) {
|
|| (file && !wwin->icon->file)) {
|
||||||
RImage *new_image;
|
wIconChangeImageFile(wwin->icon, file);
|
||||||
|
|
||||||
if (wwin->icon->file)
|
|
||||||
wfree(wwin->icon->file);
|
|
||||||
wwin->icon->file = wstrdup(file);
|
|
||||||
|
|
||||||
new_image = wDefaultGetImage(scr, wwin->wm_instance, wwin->wm_class);
|
|
||||||
if (new_image)
|
|
||||||
wIconChangeImage(wwin->icon, new_image);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wwin = wwin->prev;
|
wwin = wwin->prev;
|
||||||
|
|||||||
67
src/icon.c
67
src/icon.c
@@ -154,10 +154,7 @@ WIcon *wIconCreate(WWindow * wwin)
|
|||||||
#else
|
#else
|
||||||
icon->show_title = 1;
|
icon->show_title = 1;
|
||||||
#endif
|
#endif
|
||||||
if (!icon->image && !WFLAGP(wwin, always_user_icon))
|
icon->file_image = wDefaultGetImage(scr, wwin->wm_instance, wwin->wm_class);
|
||||||
icon->image = RRetainImage(wwin->net_icon_image);
|
|
||||||
if (!icon->image)
|
|
||||||
icon->image = wDefaultGetImage(scr, wwin->wm_instance, wwin->wm_class);
|
|
||||||
|
|
||||||
file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class, False);
|
file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class, False);
|
||||||
if (file) {
|
if (file) {
|
||||||
@@ -213,12 +210,12 @@ WIcon *wIconCreateWithIconFile(WScreen * scr, char *iconfile, int tile)
|
|||||||
icon->core->stacking->child_of = NULL;
|
icon->core->stacking->child_of = NULL;
|
||||||
|
|
||||||
if (iconfile) {
|
if (iconfile) {
|
||||||
icon->image = RLoadImage(scr->rcontext, iconfile, 0);
|
icon->file_image = RLoadImage(scr->rcontext, iconfile, 0);
|
||||||
if (!icon->image) {
|
if (!icon->file_image) {
|
||||||
wwarning(_("error loading image file \"%s\": %s"), iconfile, RMessageForError(RErrorCode));
|
wwarning(_("error loading image file \"%s\": %s"), iconfile, RMessageForError(RErrorCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
icon->image = wIconValidateIconSize(scr, icon->image);
|
icon->file_image = wIconValidateIconSize(scr, icon->file_image);
|
||||||
|
|
||||||
icon->file = wstrdup(iconfile);
|
icon->file = wstrdup(iconfile);
|
||||||
}
|
}
|
||||||
@@ -262,8 +259,8 @@ void wIconDestroy(WIcon * icon)
|
|||||||
if (icon->file)
|
if (icon->file)
|
||||||
wfree(icon->file);
|
wfree(icon->file);
|
||||||
|
|
||||||
if (icon->image != NULL)
|
if (icon->file_image != NULL)
|
||||||
RReleaseImage(icon->image);
|
RReleaseImage(icon->file_image);
|
||||||
|
|
||||||
wCoreDestroy(icon->core);
|
wCoreDestroy(icon->core);
|
||||||
wfree(icon);
|
wfree(icon);
|
||||||
@@ -357,18 +354,6 @@ void wIconChangeTitle(WIcon * icon, char *new_title)
|
|||||||
wIconPaint(icon);
|
wIconPaint(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wIconChangeImage(WIcon * icon, RImage * new_image)
|
|
||||||
{
|
|
||||||
assert(icon != NULL);
|
|
||||||
|
|
||||||
if (icon->image)
|
|
||||||
RReleaseImage(icon->image);
|
|
||||||
|
|
||||||
icon->image = new_image;
|
|
||||||
|
|
||||||
wIconUpdate(icon);
|
|
||||||
}
|
|
||||||
|
|
||||||
RImage *wIconValidateIconSize(WScreen * scr, RImage * icon)
|
RImage *wIconValidateIconSize(WScreen * scr, RImage * icon)
|
||||||
{
|
{
|
||||||
RImage *tmp;
|
RImage *tmp;
|
||||||
@@ -397,17 +382,20 @@ Bool wIconChangeImageFile(WIcon * icon, char *file)
|
|||||||
char *path;
|
char *path;
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
|
if (icon->file_image)
|
||||||
|
RReleaseImage(icon->file_image);
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
wIconChangeImage(icon, NULL);
|
icon->file_image = NULL;
|
||||||
|
wIconUpdate(icon);
|
||||||
return True;
|
return True;
|
||||||
}
|
}
|
||||||
|
|
||||||
path = FindImage(wPreferences.icon_path, file);
|
path = FindImage(wPreferences.icon_path, file);
|
||||||
|
|
||||||
if (path && (image = RLoadImage(scr->rcontext, path, 0))) {
|
if (path && (image = RLoadImage(scr->rcontext, path, 0))) {
|
||||||
image = wIconValidateIconSize(icon->core->screen_ptr, image);
|
icon->file_image = wIconValidateIconSize(icon->core->screen_ptr, image);
|
||||||
|
wIconUpdate(icon);
|
||||||
wIconChangeImage(icon, image);
|
|
||||||
} else {
|
} else {
|
||||||
error = 1;
|
error = 1;
|
||||||
}
|
}
|
||||||
@@ -483,20 +471,23 @@ static char *getnameforicon(WWindow * wwin)
|
|||||||
char *wIconStore(WIcon * icon)
|
char *wIconStore(WIcon * icon)
|
||||||
{
|
{
|
||||||
char *path;
|
char *path;
|
||||||
RImage *image;
|
RImage *image = NULL;
|
||||||
WWindow *wwin = icon->owner;
|
WWindow *wwin = icon->owner;
|
||||||
|
|
||||||
if (!wwin || !wwin->wm_hints || !(wwin->wm_hints->flags & IconPixmapHint)
|
if (!wwin) return NULL;
|
||||||
|| wwin->wm_hints->icon_pixmap == None)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
path = getnameforicon(wwin);
|
path = getnameforicon(wwin);
|
||||||
if (!path)
|
if (!path)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
image = RCreateImageFromDrawable(icon->core->screen_ptr->rcontext,
|
if (wwin->net_icon_image) {
|
||||||
wwin->wm_hints->icon_pixmap, (wwin->wm_hints->flags & IconMaskHint)
|
image = RRetainImage(wwin->net_icon_image);
|
||||||
? wwin->wm_hints->icon_mask : None);
|
} else if (wwin->wm_hints && (wwin->wm_hints->flags & IconPixmapHint)
|
||||||
|
&& wwin->wm_hints->icon_pixmap != None) {
|
||||||
|
image = RCreateImageFromDrawable(icon->core->screen_ptr->rcontext,
|
||||||
|
wwin->wm_hints->icon_pixmap, (wwin->wm_hints->flags & IconMaskHint)
|
||||||
|
? wwin->wm_hints->icon_mask : None);
|
||||||
|
}
|
||||||
if (!image) {
|
if (!image) {
|
||||||
wfree(path);
|
wfree(path);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -571,11 +562,11 @@ void wIconUpdate(WIcon * icon)
|
|||||||
XFreePixmap(dpy, icon->pixmap);
|
XFreePixmap(dpy, icon->pixmap);
|
||||||
icon->pixmap = None;
|
icon->pixmap = None;
|
||||||
|
|
||||||
if (wwin && (WFLAGP(wwin, always_user_icon) || wwin->net_icon_image))
|
if (wwin && WFLAGP(wwin, always_user_icon))
|
||||||
goto user_icon;
|
goto user_icon;
|
||||||
|
|
||||||
/* use client specified icon window */
|
|
||||||
if (icon->icon_win != None) {
|
if (icon->icon_win != None) {
|
||||||
|
/* use client specified icon window */
|
||||||
XWindowAttributes attr;
|
XWindowAttributes attr;
|
||||||
int resize = 0;
|
int resize = 0;
|
||||||
unsigned int width, height, depth;
|
unsigned int width, height, depth;
|
||||||
@@ -626,6 +617,10 @@ void wIconUpdate(WIcon * icon)
|
|||||||
None, wCursor[WCUR_ARROW]);
|
None, wCursor[WCUR_ARROW]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (wwin && wwin->net_icon_image) {
|
||||||
|
/* Use _NET_WM_ICON icon */
|
||||||
|
icon->pixmap = makeIcon(scr, wwin->net_icon_image, icon->show_title,
|
||||||
|
icon->shadowed, icon->tile_type, icon->highlighted);
|
||||||
} else if (wwin && wwin->wm_hints && (wwin->wm_hints->flags & IconPixmapHint)) {
|
} else if (wwin && wwin->wm_hints && (wwin->wm_hints->flags & IconPixmapHint)) {
|
||||||
int x, y;
|
int x, y;
|
||||||
unsigned int w, h;
|
unsigned int w, h;
|
||||||
@@ -685,8 +680,8 @@ void wIconUpdate(WIcon * icon)
|
|||||||
} else {
|
} else {
|
||||||
user_icon:
|
user_icon:
|
||||||
|
|
||||||
if (icon->image) {
|
if (icon->file_image) {
|
||||||
icon->pixmap = makeIcon(scr, icon->image, icon->show_title,
|
icon->pixmap = makeIcon(scr, icon->file_image, icon->show_title,
|
||||||
icon->shadowed, icon->tile_type, icon->highlighted);
|
icon->shadowed, icon->tile_type, icon->highlighted);
|
||||||
} else {
|
} else {
|
||||||
/* make default icons */
|
/* make default icons */
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ typedef struct WIcon {
|
|||||||
Window icon_win; /* client suplied icon window */
|
Window icon_win; /* client suplied icon window */
|
||||||
|
|
||||||
char *file; /* the file with the icon image */
|
char *file; /* the file with the icon image */
|
||||||
RImage *image;
|
RImage *file_image; /* the image from the file */
|
||||||
|
|
||||||
unsigned int tile_type:4;
|
unsigned int tile_type:4;
|
||||||
unsigned int show_title:1;
|
unsigned int show_title:1;
|
||||||
@@ -63,7 +63,6 @@ void wIconDestroy(WIcon *icon);
|
|||||||
void wIconPaint(WIcon *icon);
|
void wIconPaint(WIcon *icon);
|
||||||
void wIconUpdate(WIcon *icon);
|
void wIconUpdate(WIcon *icon);
|
||||||
void wIconChangeTitle(WIcon *icon, char *new_title);
|
void wIconChangeTitle(WIcon *icon, char *new_title);
|
||||||
void wIconChangeImage(WIcon *icon, RImage *new_image);
|
|
||||||
Bool wIconChangeImageFile(WIcon *icon, char *file);
|
Bool wIconChangeImageFile(WIcon *icon, char *file);
|
||||||
void wIconSelect(WIcon *icon);
|
void wIconSelect(WIcon *icon);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user