5 * A Window Maker/AfterStep dock application for switching X key sets
8 * Copyright (C) 1999 Eric Crampton <EricCrampton@worldnet.att.net>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this software; see the file COPYING. If not, write to
23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301 USA
26 * Reference source: wmtime dock app
44 #include <sys/param.h>
45 #include <sys/types.h>
53 #include <X11/extensions/shape.h>
56 * Window Maker includes
59 #include "libdockapp/wmgeneral.h"
60 #include "libdockapp/misc.h"
63 * Pixmap, bitmap includes
66 #include "wmkeys-master.xpm"
67 #include "wmkeys-mask.xbm"
80 keysym_config configs
[10];
88 void wmkeys_routine(int, char **);
90 void draw_string(char* s
);
91 void enable_configuration(int n
);
97 int main(int argc
, char *argv
[])
103 if (strlen(ProgName
) >= 6)
104 ProgName
+= (strlen(ProgName
) - 6);
107 wmkeys_routine(argc
, argv
);
116 void wmkeys_routine(int argc
, char **argv
)
122 openXwindow(argc
, argv
, wmkeys_master_xpm
, wmkeys_mask_bits
, 64, 64);
123 enable_configuration(0);
125 /* add mouse region */
126 AddMouseRegion(0, 5, 5, 58, 122);
129 waitpid(0, NULL
, WNOHANG
);
132 while (XPending(display
)) {
133 XNextEvent(display
, &Event
);
134 switch (Event
.type
) {
139 XCloseDisplay(display
);
143 but_stat
= CheckMouseRegion(Event
.xbutton
.x
, Event
.xbutton
.y
);
146 i
= CheckMouseRegion(Event
.xbutton
.x
, Event
.xbutton
.y
);
147 if (but_stat
== i
&& but_stat
>= 0) {
151 if(current_config
== num_configs
)
153 enable_configuration(current_config
);
161 /* Sleep 0.3 seconds */
169 * Draws string s in the LCD display portion of the window.
172 void draw_string(char* s
)
175 for(i
=0; i
<strlen(s
) && i
<8; i
++) {
176 copyXPMArea((toupper(s
[i
]) - 'A')*6, 74, 6, 9, 5+(i
*6), 49);
184 int getline_wmkeys(FILE* pfile
, char* s
, int lim
)
187 for(i
=0; i
<lim
-1 && (c
=fgetc(pfile
)) != EOF
&& c
!='\n'; ++i
) {
201 * Reads the appropriate configuration file from ${HOME}/.wmkeysrc
202 * or from /etc/wmkeysrc, in that order.
210 char key
[256], value
[256];
212 home_var
= getenv("HOME");
214 rcfilename
= malloc(sizeof(char) * strlen(home_var
) + 11 /* / .wmkeysrc + NULL*/);
215 strcpy(rcfilename
, home_var
);
216 strcat(rcfilename
, "/.wmkeysrc");
218 pfile
= fopen(rcfilename
, "r");
220 /* try to open system-wide configuration */
221 strcpy(rcfilename
, "/etc/wmkeysrc");
222 pfile
= fopen(rcfilename
, "r");
225 fprintf(stderr
, "Error: cannot open ${HOME}/.wmkeysrc or /etc/wmkeysrc\n");
230 while(!feof(pfile
)) {
231 getline_wmkeys(pfile
, key
, 256);
234 getline_wmkeys(pfile
, value
, 256);
236 configs
[num_configs
].name
= malloc(sizeof(char)*strlen(key
)+1);
237 strcpy(configs
[num_configs
].name
, key
);
238 configs
[num_configs
].filename
= malloc(sizeof(char)*strlen(value
)+1);
239 strcpy(configs
[num_configs
].filename
, value
);
243 if(num_configs
== 0) {
244 fprintf(stderr
, "Error: no configurations, exiting.\n");
250 * enable_configuration()
252 * Enables configuration number n.
255 void enable_configuration(int n
)
258 draw_string(configs
[n
].name
);
259 strcpy(syscmd
, "xmodmap ");
260 strcat(syscmd
, configs
[n
].filename
);