1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-19 12:28:22 +01:00

Icon functions moved to appicon.c

The icon functions wApplicationExtractDirPackIcon() wApplicationSaveIconPathFor()
are moved to appicon.c from application.c.

This functions are Application Icon related and should be included in appicon.
This commit is contained in:
Rodolfo García Peñas (kix)
2012-06-18 08:47:15 +02:00
committed by Carlos R. Mafra
parent 7f022f1c8f
commit f44944c18d
4 changed files with 81 additions and 86 deletions

View File

@@ -26,6 +26,7 @@
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <errno.h> #include <errno.h>
@@ -58,6 +59,7 @@
/**** Global variables ****/ /**** Global variables ****/
extern Cursor wCursor[WCUR_LAST]; extern Cursor wCursor[WCUR_LAST];
extern WPreferences wPreferences; extern WPreferences wPreferences;
extern WDDomain *WDWindowAttributes;
#define MOD_MASK wPreferences.modifier_mask #define MOD_MASK wPreferences.modifier_mask
@@ -65,6 +67,41 @@ void appIconMouseDown(WObjDescriptor * desc, XEvent * event);
static void iconDblClick(WObjDescriptor * desc, XEvent * event); static void iconDblClick(WObjDescriptor * desc, XEvent * event);
static void iconExpose(WObjDescriptor * desc, XEvent * event); static void iconExpose(WObjDescriptor * desc, XEvent * event);
/* This function is used if the application is a .app. It checks if it has an icon in it
* like for example /usr/local/GNUstep/Applications/WPrefs.app/WPrefs.tiff
*/
void wApplicationExtractDirPackIcon(WScreen * scr, char *path, char *wm_instance, char *wm_class)
{
char *iconPath = NULL;
char *tmp = NULL;
if (strstr(path, ".app")) {
tmp = wmalloc(strlen(path) + 16);
if (scr->flags.supports_tiff) {
strcpy(tmp, path);
strcat(tmp, ".tiff");
if (access(tmp, R_OK) == 0)
iconPath = tmp;
}
if (!iconPath) {
strcpy(tmp, path);
strcat(tmp, ".xpm");
if (access(tmp, R_OK) == 0)
iconPath = tmp;
}
if (!iconPath)
wfree(tmp);
if (iconPath) {
wApplicationSaveIconPathFor(iconPath, wm_instance, wm_class);
wfree(iconPath);
}
}
}
WAppIcon *wAppIconCreateForDock(WScreen * scr, char *command, char *wm_instance, char *wm_class, int tile) WAppIcon *wAppIconCreateForDock(WScreen * scr, char *command, char *wm_instance, char *wm_class, int tile)
{ {
WAppIcon *dicon; WAppIcon *dicon;
@@ -844,6 +881,46 @@ void appIconMouseDown(WObjDescriptor * desc, XEvent * event)
} }
} }
/* This function save the application icon and store the path in the Dictionary */
void wApplicationSaveIconPathFor(char *iconPath, char *wm_instance, char *wm_class)
{
WMPropList *dict = WDWindowAttributes->dictionary;
WMPropList *adict, *key, *iconk;
WMPropList *val;
char *tmp;
tmp = get_name_for_instance_class(wm_instance, wm_class);
key = WMCreatePLString(tmp);
wfree(tmp);
adict = WMGetFromPLDictionary(dict, key);
iconk = WMCreatePLString("Icon");
if (adict) {
val = WMGetFromPLDictionary(adict, iconk);
} else {
/* no dictionary for app, so create one */
adict = WMCreatePLDictionary(NULL, NULL);
WMPutInPLDictionary(dict, key, adict);
WMReleasePropList(adict);
val = NULL;
}
if (!val) {
val = WMCreatePLString(iconPath);
WMPutInPLDictionary(adict, iconk, val);
WMReleasePropList(val);
} else {
val = NULL;
}
WMReleasePropList(key);
WMReleasePropList(iconk);
if (val && !wPreferences.flags.noupdates)
UpdateDomainFile(WDWindowAttributes);
}
void save_app_icon(WWindow *wwin, WApplication *wapp) void save_app_icon(WWindow *wwin, WApplication *wapp)
{ {
char *tmp, *path; char *tmp, *path;

View File

@@ -80,6 +80,10 @@ void makeAppIconFor(WApplication * wapp);
void removeAppIconFor(WApplication * wapp); void removeAppIconFor(WApplication * wapp);
void save_app_icon(WWindow *wwin, WApplication *wapp); void save_app_icon(WWindow *wwin, WApplication *wapp);
void paint_app_icon(WApplication *wapp); void paint_app_icon(WApplication *wapp);
void wApplicationSaveIconPathFor(char *iconPath, char *wm_instance,
char *wm_class);
void wApplicationExtractDirPackIcon(WScreen *scr,char *path, char *wm_instance,
char *wm_class);
Bool wAppIconChangeImage(WAppIcon *icon, char *file); Bool wAppIconChangeImage(WAppIcon *icon, char *file);
Bool wAppIconSave(WAppIcon *aicon); Bool wAppIconSave(WAppIcon *aicon);

View File

@@ -21,9 +21,7 @@
#include "wconfig.h" #include "wconfig.h"
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "WindowMaker.h" #include "WindowMaker.h"
#include "menu.h" #include "menu.h"
@@ -35,8 +33,6 @@
#include "application.h" #include "application.h"
#include "appmenu.h" #include "appmenu.h"
#include "properties.h" #include "properties.h"
#include "stacking.h"
#include "actions.h"
#include "workspace.h" #include "workspace.h"
#include "dock.h" #include "dock.h"
@@ -44,8 +40,6 @@
extern XContext wAppWinContext; extern XContext wAppWinContext;
extern XContext wWinContext; extern XContext wWinContext;
extern WPreferences wPreferences;
extern WDDomain *WDWindowAttributes;
/******** Local variables ********/ /******** Local variables ********/
@@ -107,81 +101,6 @@ static void extractIcon(WWindow * wwin)
wfree(progname); wfree(progname);
} }
} }
void wApplicationSaveIconPathFor(char *iconPath, char *wm_instance, char *wm_class)
{
WMPropList *dict = WDWindowAttributes->dictionary;
WMPropList *adict, *key, *iconk;
WMPropList *val;
char *tmp;
tmp = get_name_for_instance_class(wm_instance, wm_class);
key = WMCreatePLString(tmp);
wfree(tmp);
adict = WMGetFromPLDictionary(dict, key);
iconk = WMCreatePLString("Icon");
if (adict) {
val = WMGetFromPLDictionary(adict, iconk);
} else {
/* no dictionary for app, so create one */
adict = WMCreatePLDictionary(NULL, NULL);
WMPutInPLDictionary(dict, key, adict);
WMReleasePropList(adict);
val = NULL;
}
if (!val) {
val = WMCreatePLString(iconPath);
WMPutInPLDictionary(adict, iconk, val);
WMReleasePropList(val);
} else {
val = NULL;
}
WMReleasePropList(key);
WMReleasePropList(iconk);
if (val && !wPreferences.flags.noupdates)
UpdateDomainFile(WDWindowAttributes);
}
/* This function is used if the application is a .app. It checks if it has an icon in it
* like for example /usr/local/GNUstep/Applications/WPrefs.app/WPrefs.tiff
*/
void wApplicationExtractDirPackIcon(WScreen * scr, char *path, char *wm_instance, char *wm_class)
{
char *iconPath = NULL;
char *tmp = NULL;
if (strstr(path, ".app")) {
tmp = wmalloc(strlen(path) + 16);
if (scr->flags.supports_tiff) {
strcpy(tmp, path);
strcat(tmp, ".tiff");
if (access(tmp, R_OK) == 0)
iconPath = tmp;
}
if (!iconPath) {
strcpy(tmp, path);
strcat(tmp, ".xpm");
if (access(tmp, R_OK) == 0)
iconPath = tmp;
}
if (!iconPath)
wfree(tmp);
if (iconPath) {
wApplicationSaveIconPathFor(iconPath, wm_instance, wm_class);
wfree(iconPath);
}
}
}
static void app_icon_create_from_docks(WWindow *wwin, WApplication *wapp, Window main_window) static void app_icon_create_from_docks(WWindow *wwin, WApplication *wapp, Window main_window)
{ {
WScreen *scr = wwin->screen_ptr; WScreen *scr = wwin->screen_ptr;
@@ -381,4 +300,3 @@ void wApplicationDeactivate(WApplication *wapp)
} }
#endif #endif
} }

View File

@@ -48,10 +48,6 @@ typedef struct WApplication {
WApplication *wApplicationCreate(struct WWindow *wwin); WApplication *wApplicationCreate(struct WWindow *wwin);
WApplication *wApplicationOf(Window window); WApplication *wApplicationOf(Window window);
void wApplicationDestroy(WApplication *wapp); void wApplicationDestroy(WApplication *wapp);
void wApplicationExtractDirPackIcon(WScreen *scr,char *path, char *wm_instance,
char *wm_class);
void wApplicationSaveIconPathFor(char *iconPath, char *wm_instance,
char *wm_class);
void wAppBounce(WApplication *); void wAppBounce(WApplication *);
void wAppBounceWhileUrgent(WApplication *); void wAppBounceWhileUrgent(WApplication *);