15 #include <X11/extensions/xf86vmode.h>
16 #include <libdockapp/dockapp.h>
17 #include "wmxres-master.xpm"
18 #include "wmxres-mask.xbm"
30 char res_list
[100][20];
31 XF86VidModeModeInfo
**res_modelines
;
41 void DrawResMode(int);
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
);
59 int main(int argc
,char *argv
[])
61 DACallbacks eventCallbacks
= {NULL
, buttonPress
, buttonRelease
,
62 NULL
, NULL
, NULL
, NULL
};
64 unsigned short width
, height
;
66 DAParseArguments(argc
, argv
, NULL
, 0,
67 "Window Maker dockapp to select your display mode",
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
);
81 res_selected
=res_i_active
;
82 DrawResMode(res_selected
);
90 void pressActivate(int x
, int y
, DARect rect
, void *data
)
97 void pressLeft(int x
, int y
, DARect rect
, void *data
)
100 DrawResMode(res_selected
);
101 DrawLight(res_selected
== res_i_active
? 1 : 0);
104 void pressRight(int x
, int y
, DARect rect
, void *data
)
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
)
127 void releaseLeft(int x
, int y
, DARect rect
, void *data
)
132 void releaseRight(int x
, int y
, DARect rect
, void *data
)
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
155 if (!(res_count
> 0)) {
156 XF86VidModeGetAllModeLines(DADisplay
, XDefaultScreen(DADisplay
), &res_count
, &res_modelines
);
159 printf("Error : X must be configured with more than one mode.\n");
164 /* fix bounds on res_count -- Todd Troxell <ttroxell@debian.org */
165 if(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
;
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
])) {
193 * Activation d'une nouvelle resolution X
195 void ActiveXNewMode()
197 XF86VidModeSwitchToMode(DADisplay
, XDefaultScreen(DADisplay
), res_modelines
[res_selected
]);
199 res_i_active
=res_selected
;
203 * Affichage d'une resolution
205 void DrawResMode(int show_mode
)
208 char *res_width
, *res_height
;
212 strtmp
=strdup(res_list
[show_mode
]);
214 res_width
=strtok(strtmp
, "x");
215 res_height
=strtok((char *) NULL
, "x");
218 sprintf(buf
, "%04i", k
);
220 for (i
=0; buf
[i
]; i
++) {
223 XCopyArea(DADisplay
, pixmap
, pixmap
, DAGC
,
224 c
* 6, 61, 6, 7, k
-1, 9);
229 sprintf(buf
, "%04i", k
);
231 for (i
=0; buf
[i
]; i
++) {
234 XCopyArea(DADisplay
, pixmap
, pixmap
, DAGC
,
235 c
* 6, 61, 6, 7, k
-1, 18);
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);
255 * Un on enfonce le bouton
257 void ButtonDown(int button
)
262 XCopyArea(DADisplay
, pixmap
, pixmap
, DAGC
,
263 79, 96, 12, 11, 43, 44);
266 XCopyArea(DADisplay
, pixmap
, pixmap
, DAGC
,
267 55, 96, 12, 11, 19, 44);
269 if (res_selected
< 0) { res_selected
=res_count
-1; }
272 XCopyArea(DADisplay
, pixmap
, pixmap
, DAGC
,
273 67, 96, 12, 11, 31, 44);
275 if (res_selected
> res_count
-1) { res_selected
=0; }
282 * Et deux on relache le bouton
284 void ButtonUp(int button
)
289 XCopyArea(DADisplay
, pixmap
, pixmap
, DAGC
,
290 79, 84, 12, 11, 43, 44);
293 XCopyArea(DADisplay
, pixmap
, pixmap
, DAGC
,
294 55, 84, 12, 11, 19, 44);
297 XCopyArea(DADisplay
, pixmap
, pixmap
, DAGC
,
298 67, 84, 12, 11, 31, 44);