Change to the linux kernel coding style
[wmaker-crm.git] / WINGs / wappresource.c
Commit [+]AuthorDateLineData
d214a2ca dan1999-09-09 13:46:59 +00001
d214a2ca dan1999-09-09 13:46:59 +00002#include <unistd.h>
3
4#include "WINGsP.h"
5
6#include <X11/Xutil.h>
7
d214a2ca dan1999-09-09 13:46:59 +00008#include "GNUstep.h"
9
d214a2ca dan1999-09-09 13:46:59 +000010extern struct W_Application WMApplication;
11
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020012void WMSetApplicationIconWindow(WMScreen * scr, Window window)
36e46831 dan2001-04-21 07:12:21 +000013{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020014 scr->applicationIconWindow = window;
36e46831 dan2001-04-21 07:12:21 +000015
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020016 if (scr->groupLeader) {
17 XWMHints *hints;
edc57cf7 kojima2000-09-25 19:21:45 +000018
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020019 hints = XGetWMHints(scr->display, scr->groupLeader);
20 hints->flags |= IconWindowHint;
21 hints->icon_window = window;
36e46831 dan2001-04-21 07:12:21 +000022
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020023 XSetWMHints(scr->display, scr->groupLeader, hints);
24 XFree(hints);
25 }
edc57cf7 kojima2000-09-25 19:21:45 +000026}
27
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020028void WMSetApplicationIconImage(WMScreen * scr, RImage * image)
36e46831 dan2001-04-21 07:12:21 +000029{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020030 WMPixmap *icon;
36e46831 dan2001-04-21 07:12:21 +000031
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020032 if (scr->applicationIconImage == image)
33 return;
36e46831 dan2001-04-21 07:12:21 +000034
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020035 if (scr->applicationIconImage)
36 RReleaseImage(scr->applicationIconImage);
36e46831 dan2001-04-21 07:12:21 +000037
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020038 scr->applicationIconImage = RRetainImage(image);
36e46831 dan2001-04-21 07:12:21 +000039
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020040 /* TODO: check whether we should set the pixmap only if there's none yet */
41 if (image != NULL && (icon = WMCreatePixmapFromRImage(scr, image, 128)) != NULL) {
42 WMSetApplicationIconPixmap(scr, icon);
43 WMReleasePixmap(icon);
44 }
36e46831 dan2001-04-21 07:12:21 +000045}
46
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020047RImage *WMGetApplicationIconImage(WMScreen * scr)
36e46831 dan2001-04-21 07:12:21 +000048{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020049 return scr->applicationIconImage;
36e46831 dan2001-04-21 07:12:21 +000050}
51
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020052void WMSetApplicationIconPixmap(WMScreen * scr, WMPixmap * icon)
36e46831 dan2001-04-21 07:12:21 +000053{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020054 if (scr->applicationIconPixmap == icon)
55 return;
36e46831 dan2001-04-21 07:12:21 +000056
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020057 if (scr->applicationIconPixmap)
58 WMReleasePixmap(scr->applicationIconPixmap);
36e46831 dan2001-04-21 07:12:21 +000059
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020060 scr->applicationIconPixmap = WMRetainPixmap(icon);
36e46831 dan2001-04-21 07:12:21 +000061
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020062 if (scr->groupLeader) {
63 XWMHints *hints;
d214a2ca dan1999-09-09 13:46:59 +000064
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020065 hints = XGetWMHints(scr->display, scr->groupLeader);
66 hints->flags |= IconPixmapHint | IconMaskHint;
67 hints->icon_pixmap = (icon != NULL ? icon->pixmap : None);
68 hints->icon_mask = (icon != NULL ? icon->mask : None);
36e46831 dan2001-04-21 07:12:21 +000069
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020070 XSetWMHints(scr->display, scr->groupLeader, hints);
71 XFree(hints);
72 }
d214a2ca dan1999-09-09 13:46:59 +000073}
74
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020075WMPixmap *WMGetApplicationIconPixmap(WMScreen * scr)
d214a2ca dan1999-09-09 13:46:59 +000076{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020077 return scr->applicationIconPixmap;
36e46831 dan2001-04-21 07:12:21 +000078}
79
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020080WMPixmap *WMCreateApplicationIconBlendedPixmap(WMScreen * scr, RColor * color)
36e46831 dan2001-04-21 07:12:21 +000081{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020082 WMPixmap *pix;
36e46831 dan2001-04-21 07:12:21 +000083
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020084 if (scr->applicationIconImage) {
85 RColor gray;
36e46831 dan2001-04-21 07:12:21 +000086
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020087 gray.red = 0xae;
88 gray.green = 0xaa;
89 gray.blue = 0xae;
90 gray.alpha = 0xff;
36e46831 dan2001-04-21 07:12:21 +000091
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020092 if (!color)
93 color = &gray;
36e46831 dan2001-04-21 07:12:21 +000094
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020095 pix = WMCreateBlendedPixmapFromRImage(scr, scr->applicationIconImage, color);
96 } else {
97 pix = NULL;
98 }
36e46831 dan2001-04-21 07:12:21 +000099
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200100 return pix;
d214a2ca dan1999-09-09 13:46:59 +0000101}
102
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200103void WMSetApplicationHasAppIcon(WMScreen * scr, Bool flag)
d214a2ca dan1999-09-09 13:46:59 +0000104{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200105 scr->aflags.hasAppIcon = ((flag == 0) ? 0 : 1);
d214a2ca dan1999-09-09 13:46:59 +0000106}
107
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200108void W_InitApplication(WMScreen * scr)
d214a2ca dan1999-09-09 13:46:59 +0000109{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200110 Window leader;
111 XClassHint *classHint;
112 XWMHints *hints;
113
114 leader = XCreateSimpleWindow(scr->display, scr->rootWin, -1, -1, 1, 1, 0, 0, 0);
115
116 if (!scr->aflags.simpleApplication) {
117 classHint = XAllocClassHint();
118 classHint->res_name = "groupLeader";
119 classHint->res_class = WMApplication.applicationName;
120 XSetClassHint(scr->display, leader, classHint);
121 XFree(classHint);
122
123 XSetCommand(scr->display, leader, WMApplication.argv, WMApplication.argc);
124
125 hints = XAllocWMHints();
126
127 hints->flags = WindowGroupHint;
128 hints->window_group = leader;
129
130 /* This code will never actually be reached, because to have
131 * scr->applicationIconPixmap set we need to have a screen first,
132 * but this function is called in the screen creation process.
133 * -Dan
134 */
135 if (scr->applicationIconPixmap) {
136 hints->flags |= IconPixmapHint;
137 hints->icon_pixmap = scr->applicationIconPixmap->pixmap;
138 if (scr->applicationIconPixmap->mask) {
139 hints->flags |= IconMaskHint;
140 hints->icon_mask = scr->applicationIconPixmap->mask;
141 }
142 }
143
144 XSetWMHints(scr->display, leader, hints);
145
146 XFree(hints);
147 }
148 scr->groupLeader = leader;
d214a2ca dan1999-09-09 13:46:59 +0000149}