wmclockmon: remove obsolete `GTK_CALENDAR_WEEK_START_MONDAY`
[dockapps.git] / wmxres / wmxres.c
blob64998e63db183ce6bd0bf31657a88ff8e0840d2f
1 /*
2 * wmxres.c
3 * by Mychel Platyny
4 */
6 /*
7 * Les includes
8 */
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <X11/X.h>
14 #include <X11/Xlib.h>
15 #include <X11/extensions/xf86vmode.h>
16 #include <libdockapp/dockapp.h>
17 #include "wmxres-master.xpm"
18 #include "wmxres-mask.xbm"
21 * Les Definitions
24 int button_state=-1;
25 int isw;
26 int res_count=-1;
27 int res_selected;
28 int res_i_active=-1;
29 char res_active[12];
30 char res_list[100][20];
31 XF86VidModeModeInfo **res_modelines;
32 XEvent Event;
33 Pixmap pixmap;
36 * Les Fonctions
38 void ButtonUp(int);
39 void ButtonDown(int);
40 void DrawLight(int);
41 void DrawResMode(int);
42 void GetXModes(void);
43 void ActiveXNewMode(void);
44 void GetXActiveMode(void);
46 void pressActivate(int x, int y, DARect rect, void *data);
47 void pressLeft(int x, int y, DARect rect, void *data);
48 void pressRight(int x, int y, DARect rect, void *data);
49 void buttonPress(int button, int state, int x, int y);
51 void releaseActivate(int x, int y, DARect rect, void *data);
52 void releaseLeft(int x, int y, DARect rect, void *data);
53 void releaseRight(int x, int y, DARect rect, void *data);
54 void buttonRelease(int button, int state, int x, int y);
57 * Yalla
59 int main(int argc,char *argv[])
61 DACallbacks eventCallbacks = {NULL, buttonPress, buttonRelease,
62 NULL, NULL, NULL, NULL};
63 Pixmap mask;
64 unsigned short width, height;
66 DAParseArguments(argc, argv, NULL, 0,
67 "Window Maker dockapp to select your display mode",
68 PACKAGE_STRING);
70 DAInitialize(NULL, PACKAGE_NAME, 56, 56, argc, argv);
71 DASetCallbacks(&eventCallbacks);
73 DAMakePixmapFromData(wmxres_master_xpm, &pixmap, NULL, &width, &height);
74 mask = DAMakeShapeFromData(wmxres_mask_bits,
75 wmxres_mask_width, wmxres_mask_height);
76 DASetPixmap(pixmap);
77 DASetShape(mask);
79 GetXModes();
80 GetXActiveMode();
81 res_selected=res_i_active;
82 DrawResMode(res_selected);
83 DrawLight(1);
85 DASetTimeout(200);
86 DAShow();
87 DAEventLoop();
90 void pressActivate(int x, int y, DARect rect, void *data)
92 ButtonDown(0);
93 ActiveXNewMode();
94 DrawLight(1);
97 void pressLeft(int x, int y, DARect rect, void *data)
99 ButtonDown(1);
100 DrawResMode(res_selected);
101 DrawLight(res_selected == res_i_active ? 1 : 0);
104 void pressRight(int x, int y, DARect rect, void *data)
106 ButtonDown(2);
107 DrawResMode(res_selected);
108 DrawLight(res_selected == res_i_active ? 1 : 0);
111 void buttonPress(int button, int state, int x, int y)
113 DAActionRect pressRects[] = {
114 {{43, 44, 12, 12}, pressActivate},
115 {{19, 44, 12, 12}, pressLeft},
116 {{31, 44, 12, 12}, pressRight}
119 DAProcessActionRects(x, y, pressRects, 3, NULL);
122 void releaseActivate(int x, int y, DARect rect, void *data)
124 ButtonUp(0);
127 void releaseLeft(int x, int y, DARect rect, void *data)
129 ButtonUp(1);
132 void releaseRight(int x, int y, DARect rect, void *data)
134 ButtonUp(2);
137 void buttonRelease(int button, int state, int x, int y)
139 DAActionRect releaseRects[] = {
140 {{43, 44, 12, 12}, releaseActivate},
141 {{19, 44, 12, 12}, releaseLeft},
142 {{31, 44, 12, 12}, releaseRight}
145 DAProcessActionRects(x, y, releaseRects, 3, NULL);
149 * Recuperation des resolutions X possible
151 void GetXModes(void)
153 int c;
155 if (!(res_count > 0)) {
156 XF86VidModeGetAllModeLines(DADisplay, XDefaultScreen(DADisplay), &res_count, &res_modelines);
158 if (res_count < 2) {
159 printf("Error : X must be configured with more than one mode.\n");
160 exit(1);
164 /* fix bounds on res_count -- Todd Troxell <ttroxell@debian.org */
165 if(res_count > 100) {
166 res_count =100;
169 for(c=0; c < res_count ; c++) {
170 sprintf(res_list[c], "%dx%d", res_modelines[c]->hdisplay, res_modelines[c]->vdisplay);
175 * Recuperation de la resolution X active
177 void GetXActiveMode(void)
179 XF86VidModeModeLine vm_modelines;
180 int a, i;
182 XF86VidModeGetModeLine(DADisplay, XDefaultScreen(DADisplay), &a, &vm_modelines);
183 sprintf(res_active, "%dx%d", vm_modelines.hdisplay, vm_modelines.vdisplay);
185 for(i=0; i < res_count; i++) {
186 if (!strcmp(res_active, res_list[i])) {
187 res_i_active=i;
193 * Activation d'une nouvelle resolution X
195 void ActiveXNewMode()
197 XF86VidModeSwitchToMode(DADisplay, XDefaultScreen(DADisplay), res_modelines[res_selected]);
198 XFlush(DADisplay);
199 res_i_active=res_selected;
203 * Affichage d'une resolution
205 void DrawResMode(int show_mode)
207 int c, i, k;
208 char *res_width, *res_height;
209 char buf[1024];
210 char *strtmp;
212 strtmp=strdup(res_list[show_mode]);
214 res_width=strtok(strtmp, "x");
215 res_height=strtok((char *) NULL, "x");
217 k=atoi(res_width);
218 sprintf(buf, "%04i", k);
219 k = 16;
220 for (i=0; buf[i]; i++) {
221 c = buf[i];
222 c -= '0';
223 XCopyArea(DADisplay, pixmap, pixmap, DAGC,
224 c * 6, 61, 6, 7, k-1, 9);
225 k += 6;
228 k=atoi(res_height);
229 sprintf(buf, "%04i", k);
230 k = 16;
231 for (i=0; buf[i]; i++) {
232 c = buf[i];
233 c -= '0';
234 XCopyArea(DADisplay, pixmap, pixmap, DAGC,
235 c * 6, 61, 6, 7, k-1, 18);
236 k += 6;
239 DASetPixmap(pixmap);
243 * Allumage de la loupiote
245 void DrawLight(int light_state)
247 XCopyArea(DADisplay, pixmap, pixmap, DAGC,
248 102, light_state? 35: 47, 14, 11, 1, 44);
249 DASetPixmap(pixmap);
255 * Un on enfonce le bouton
257 void ButtonDown(int button)
259 switch (button)
261 case 0:
262 XCopyArea(DADisplay, pixmap, pixmap, DAGC,
263 79, 96, 12, 11, 43, 44);
264 break;
265 case 1:
266 XCopyArea(DADisplay, pixmap, pixmap, DAGC,
267 55, 96, 12, 11, 19, 44);
268 res_selected--;
269 if (res_selected < 0) { res_selected=res_count-1; }
270 break;
271 case 2:
272 XCopyArea(DADisplay, pixmap, pixmap, DAGC,
273 67, 96, 12, 11, 31, 44);
274 res_selected++;
275 if (res_selected > res_count-1) { res_selected=0; }
276 break;
278 DASetPixmap(pixmap);
282 * Et deux on relache le bouton
284 void ButtonUp(int button)
286 switch (button)
288 case 0:
289 XCopyArea(DADisplay, pixmap, pixmap, DAGC,
290 79, 84, 12, 11, 43, 44);
291 break;
292 case 1:
293 XCopyArea(DADisplay, pixmap, pixmap, DAGC,
294 55, 84, 12, 11, 19, 44);
295 break;
296 case 2:
297 XCopyArea(DADisplay, pixmap, pixmap, DAGC,
298 67, 84, 12, 11, 31, 44);
299 break;
301 DASetPixmap(pixmap);