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 "wmgeneral/wmgeneral.h"
60 #include "wmgeneral/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 void main(int argc
, char *argv
[])
103 if (strlen(ProgName
) >= 6)
104 ProgName
+= (strlen(ProgName
) - 6);
107 wmkeys_routine(argc
, argv
);
114 void wmkeys_routine(int argc
, char **argv
)
120 openXwindow(argc
, argv
, wmkeys_master_xpm
, wmkeys_mask_bits
, 64, 64);
121 enable_configuration(0);
123 /* add mouse region */
124 AddMouseRegion(0, 5, 5, 58, 122);
127 waitpid(0, NULL
, WNOHANG
);
130 while (XPending(display
)) {
131 XNextEvent(display
, &Event
);
132 switch (Event
.type
) {
137 XCloseDisplay(display
);
141 but_stat
= CheckMouseRegion(Event
.xbutton
.x
, Event
.xbutton
.y
);
144 i
= CheckMouseRegion(Event
.xbutton
.x
, Event
.xbutton
.y
);
145 if (but_stat
== i
&& but_stat
>= 0) {
149 if(current_config
== num_configs
)
151 enable_configuration(current_config
);
159 /* Sleep 0.3 seconds */
167 * Draws string s in the LCD display portion of the window.
170 void draw_string(char* s
)
173 for(i
=0; i
<strlen(s
) && i
<8; i
++) {
174 copyXPMArea((toupper(s
[i
]) - 'A')*6, 74, 6, 9, 5+(i
*6), 49);
182 int getline(FILE* pfile
, char* s
, int lim
)
185 for(i
=0; i
<lim
-1 && (c
=fgetc(pfile
)) != EOF
&& c
!='\n'; ++i
) {
199 * Reads the appropriate configuration file from ${HOME}/.wmkeysrc
200 * or from /etc/wmkeysrc, in that order.
208 char key
[256], value
[256];
210 home_var
= getenv("HOME");
212 rcfilename
= malloc(sizeof(char) * strlen(home_var
) + 11 /* / .wmkeysrc + NULL*/);
213 strcpy(rcfilename
, home_var
);
214 strcat(rcfilename
, "/.wmkeysrc");
216 pfile
= fopen(rcfilename
, "r");
218 /* try to open system-wide configuration */
219 strcpy(rcfilename
, "/etc/wmkeysrc");
220 pfile
= fopen(rcfilename
, "r");
223 fprintf(stderr
, "Error: cannot open ${HOME}/.wmkeysrc or /etc/wmkeysrc\n");
228 while(!feof(pfile
)) {
229 getline(pfile
, key
, 256);
232 getline(pfile
, value
, 256);
234 configs
[num_configs
].name
= malloc(sizeof(char)*strlen(key
)+1);
235 strcpy(configs
[num_configs
].name
, key
);
236 configs
[num_configs
].filename
= malloc(sizeof(char)*strlen(value
)+1);
237 strcpy(configs
[num_configs
].filename
, value
);
241 if(num_configs
== 0) {
242 fprintf(stderr
, "Error: no configurations, exiting.\n");
248 * enable_configuration()
250 * Enables configuration number n.
253 void enable_configuration(int n
)
256 draw_string(configs
[n
].name
);
257 strcpy(syscmd
, "xmodmap ");
258 strcat(syscmd
, configs
[n
].filename
);