wmxres: Use autotools for build
[dockapps.git] / wmxres / wmxres.c
blob1e9e8718ed436fc64e50434982cd73faabf50153
1 /*
2 * wmxres.c
3 * by Mychel Platyny
4 */
6 /*
7 * Les includes
8 */
10 #include <unistd.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <string.h>
14 #include <X11/xpm.h>
15 #include <X11/Xlib.h>
16 #include <X11/extensions/Xxf86dga.h>
17 #include <X11/extensions/xf86vmode.h>
18 #include "wmgeneral/wmgeneral.h"
19 #include "wmxres-master.xpm"
20 #include "wmxres-mask.xbm"
23 * Les Definitions
26 int button_state=-1;
27 int isw;
28 int res_count=-1;
29 int res_selected;
30 int res_i_active=-1;
31 char res_active[12];
32 char res_list[100][20];
33 XF86VidModeModeInfo **res_modelines;
34 XEvent Event;
37 * Les Fonctions
39 void ButtonUp(int);
40 void ButtonDown(int);
41 void DrawLight(int);
42 void DrawResMode(int);
43 void GetXModes(void);
44 void ActiveXNewMode(void);
45 void GetXActiveMode(void);
48 * Yalla
50 int main(int argc,char *argv[])
52 if (argc == 2 && strcmp(argv[1], "-v") == 0) {
53 printf("wmxres "VERSION"\n");
54 return 0;
57 openXwindow(argc, argv, wmxres_master_xpm, wmxres_mask_bits,
58 wmxres_mask_width, wmxres_mask_height);
60 AddMouseRegion(0,43,44,55,55); /* Bouton d'activation */
61 AddMouseRegion(1,19,44,31,55); /* Bouton scan gauche */
62 AddMouseRegion(2,31,44,43,55); /* Bouton scan droit */
64 GetXModes();
65 GetXActiveMode();
66 res_selected=res_i_active;
67 DrawResMode(res_selected);
68 DrawLight(1);
70 while (1)
72 while (XPending(display))
74 XNextEvent(display, &Event);
75 switch (Event.type)
77 case Expose:
78 /* On se fait beau */
79 RedrawWindow();
80 break;
81 case DestroyNotify:
82 /* Ciao */
83 XCloseDisplay(display);
84 exit(0);
85 break;
86 case ButtonPress:
87 /* Bouton enfonce */
88 isw = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
89 switch (isw)
91 case 0: /* Activation */
92 ButtonDown(0);
93 ActiveXNewMode();
94 DrawLight(1);
95 break;
96 case 1: /* Je scan a gauche */
97 ButtonDown(1);
98 DrawResMode(res_selected);
99 DrawLight(0);
100 break;
101 case 2: /* Je scan a droite */
102 ButtonDown(2);
103 DrawResMode(res_selected);
104 DrawLight(0);
105 break;
107 if (res_selected==res_i_active) { DrawLight(1); }
108 button_state = isw;
109 break;
110 case ButtonRelease:
111 /* Bouton relache donc pas enfonce */
112 switch (button_state)
114 case 0:
115 ButtonUp(0);
116 break;
117 case 1:
118 ButtonUp(1);
119 break;
120 case 2:
121 ButtonUp(2);
122 break;
124 break;
127 usleep (200000);
132 * Recuperation des resolutions X possible
134 void GetXModes(void)
136 int c;
138 if (!(res_count > 0)) {
139 XF86VidModeGetAllModeLines( display, XDefaultScreen(display), &res_count, &res_modelines);
141 if (res_count < 2) {
142 printf("Error : X must be configured with more than one mode.\n");
143 exit(1);
147 /* fix bounds on res_count -- Todd Troxell <ttroxell@debian.org */
148 if(res_count > 100) {
149 res_count =100;
152 for(c=0; c < res_count ; c++) {
153 sprintf(res_list[c], "%dx%d", res_modelines[c]->hdisplay, res_modelines[c]->vdisplay);
158 * Recuperation de la resolution X active
160 void GetXActiveMode(void)
162 XF86VidModeModeLine vm_modelines;
163 int a, i;
165 XF86VidModeGetModeLine( display, XDefaultScreen(display), &a, &vm_modelines);
166 sprintf(res_active, "%dx%d", vm_modelines.hdisplay, vm_modelines.vdisplay);
168 for(i=0; i < res_count; i++) {
169 if (!strcmp(res_active, res_list[i])) {
170 res_i_active=i;
176 * Activation d'une nouvelle resolution X
178 void ActiveXNewMode()
180 XF86VidModeSwitchToMode( display, XDefaultScreen(display), res_modelines[res_selected]);
181 XFlush(display);
182 res_i_active=res_selected;
186 * Affichage d'une resolution
188 void DrawResMode(int show_mode)
190 int c, i, k;
191 char *res_width, *res_height;
192 char buf[1024];
193 char *strtmp;
195 strtmp=strdup(res_list[show_mode]);
197 res_width=strtok(strtmp, "x");
198 res_height=strtok((char *) NULL, "x");
200 k=atoi(res_width);
201 sprintf(buf, "%04i", k);
202 k = 16;
203 for (i=0; buf[i]; i++) {
204 c = buf[i];
205 c -= '0';
206 copyXPMArea(c * 6, 61, 6, 7, k-1, 9);
207 k += 6;
210 k=atoi(res_height);
211 sprintf(buf, "%04i", k);
212 k = 16;
213 for (i=0; buf[i]; i++) {
214 c = buf[i];
215 c -= '0';
216 copyXPMArea(c * 6, 61, 6, 7, k-1, 18);
217 k += 6;
220 RedrawWindow();
224 * Allumage de la loupiote
226 void DrawLight(int light_state)
228 copyXPMArea (102, light_state? 35: 47, 14, 11, 1, 44);
229 RedrawWindowXYWH(1, 44, 14, 11);
230 RedrawWindow();
236 * Un on enfonce le bouton
238 void ButtonDown(int button)
240 switch (button)
242 case 0:
243 copyXPMArea(79, 96, 12, 11, 43, 44);
244 RedrawWindowXYWH(43, 44, 12, 11);
245 break;
246 case 1:
247 copyXPMArea(55, 96, 12, 11, 19, 44);
248 RedrawWindowXYWH(19, 44, 12, 11);
249 res_selected--;
250 if (res_selected < 0) { res_selected=res_count-1; }
251 break;
252 case 2:
253 copyXPMArea(67, 96, 12, 11, 31, 44);
254 RedrawWindowXYWH(31, 44, 12, 11);
255 res_selected++;
256 if (res_selected > res_count-1) { res_selected=0; }
257 break;
262 * Et deux on relache le bouton
264 void ButtonUp(int button)
266 switch (button)
268 case 0:
269 copyXPMArea(79, 84, 12, 11, 43, 44);
270 RedrawWindowXYWH(43, 44, 12, 11);
271 break;
272 case 1:
273 copyXPMArea(55, 84, 12, 11, 19, 44);
274 RedrawWindowXYWH(19, 44, 12, 11);
275 break;
276 case 2:
277 copyXPMArea(67, 84, 12, 11, 31, 44);
278 RedrawWindowXYWH(31, 44, 12, 11);
279 break;