Change to the linux kernel coding style
[wmaker-crm.git] / WINGs / wappresource.c
1
2 #include <unistd.h>
3
4 #include "WINGsP.h"
5
6 #include <X11/Xutil.h>
7
8 #include "GNUstep.h"
9
10 extern struct W_Application WMApplication;
11
12 void WMSetApplicationIconWindow(WMScreen * scr, Window window)
13 {
14 scr->applicationIconWindow = window;
15
16 if (scr->groupLeader) {
17 XWMHints *hints;
18
19 hints = XGetWMHints(scr->display, scr->groupLeader);
20 hints->flags |= IconWindowHint;
21 hints->icon_window = window;
22
23 XSetWMHints(scr->display, scr->groupLeader, hints);
24 XFree(hints);
25 }
26 }
27
28 void WMSetApplicationIconImage(WMScreen * scr, RImage * image)
29 {
30 WMPixmap *icon;
31
32 if (scr->applicationIconImage == image)
33 return;
34
35 if (scr->applicationIconImage)
36 RReleaseImage(scr->applicationIconImage);
37
38 scr->applicationIconImage = RRetainImage(image);
39
40 /* 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 }
45 }
46
47 RImage *WMGetApplicationIconImage(WMScreen * scr)
48 {
49 return scr->applicationIconImage;
50 }
51
52 void WMSetApplicationIconPixmap(WMScreen * scr, WMPixmap * icon)
53 {
54 if (scr->applicationIconPixmap == icon)
55 return;
56
57 if (scr->applicationIconPixmap)
58 WMReleasePixmap(scr->applicationIconPixmap);
59
60 scr->applicationIconPixmap = WMRetainPixmap(icon);
61
62 if (scr->groupLeader) {
63 XWMHints *hints;
64
65 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);
69
70 XSetWMHints(scr->display, scr->groupLeader, hints);
71 XFree(hints);
72 }
73 }
74
75 WMPixmap *WMGetApplicationIconPixmap(WMScreen * scr)
76 {
77 return scr->applicationIconPixmap;
78 }
79
80 WMPixmap *WMCreateApplicationIconBlendedPixmap(WMScreen * scr, RColor * color)
81 {
82 WMPixmap *pix;
83
84 if (scr->applicationIconImage) {
85 RColor gray;
86
87 gray.red = 0xae;
88 gray.green = 0xaa;
89 gray.blue = 0xae;
90 gray.alpha = 0xff;
91
92 if (!color)
93 color = &gray;
94
95 pix = WMCreateBlendedPixmapFromRImage(scr, scr->applicationIconImage, color);
96 } else {
97 pix = NULL;
98 }
99
100 return pix;
101 }
102
103 void WMSetApplicationHasAppIcon(WMScreen * scr, Bool flag)
104 {
105 scr->aflags.hasAppIcon = ((flag == 0) ? 0 : 1);
106 }
107
108 void W_InitApplication(WMScreen * scr)
109 {
110 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;
149 }