2 "$Id: xutil.c 9201 2008-06-01 17:32:45Z anmaster $";
40 #include <X11/Xutil.h>
41 #include <X11/keysym.h>
106 #define KEYF_NORMAL 0x01
107 #define KEYF_FIRE 0x02
108 #define KEYF_RUN 0x04
109 #define KEYF_MODIFIERS 0x07
111 #define KEYF_EDIT 0x08
112 #define KEYF_STANDARD 0x10
121 #define MAX_KEYCODE 255
133 #include "pixmaps/question.111"
143 question_bits,question_width,question_height);
167 #define ROTATE_RIGHT(c) if ((c) & 01) (c) = ((c) >>1) + 0x80000000; else (c) >>= 1;
174 int i, tried = 0, depth=0;
179 vis = DefaultVisual(disp,screen_num);
180 if (vis->class >= StaticColor) {
181 *colormap = DefaultColormap(disp,screen_num);
182 depth = DefaultDepth(disp,screen_num);
185 *colormap = DefaultColormap(disp,screen_num);
186 printf(
"You have a black and white terminal.\n");
187 printf(
"These are no longer supported by cfclient.\n");
192 unsigned long pixels[13];
193 for (i=0; i<13; i++){
194 status = XLookupColor(disp,*colormap,
colorname[i],&exactcolor,
197 printf(
"Can't find colour %s.\n",
colorname[i]);
200 status = XAllocColor(disp,*colormap,&discolor[i]);
203 printf(
"Not enough colours. Trying a private colourmap.\n");
204 XFreeColors(disp, *colormap, pixels, i-1, 0);
205 *colormap = XCreateColormap(disp, w, vis, AllocNone);
206 XSetWindowColormap(disp, w, *colormap);
211 pixels[i] = discolor[i].pixel;
233 LOG(
LOG_WARNING,
"x11::insert_key",
"keycode that is passed is greater than 255.");
237 if (keys[keycode]==NULL) {
240 keys[keycode]->
next=NULL;
242 newkey=keys[keycode];
254 if (keys[keycode]->command!=NULL) {
258 while (newkey->
next!=NULL)
259 newkey = newkey->
next;
261 newkey = newkey->
next;
275 #define display GDK_DISPLAY()
287 if (buf[0]==
'#' || buf[0]==
'\n')
return;
288 if ((cpnext = strchr(buf,
' '))==NULL) {
289 LOG(
LOG_WARNING,
"x11::parse_keybind_line",
"Line %d (%s) corrupted.", line,buf);
295 while (*cpnext ==
' ') ++cpnext;
296 cp = strchr(cpnext,
' ');
298 LOG(
LOG_WARNING,
"x11::parse_keybind_line",
"Line %d (%s) corrupted in keybinding file.", line,buf);
302 cp1 = strchr(cp,
' ');
304 LOG(
LOG_WARNING,
"x11::parse_keybind_line",
"Line %d (%s) corrupted in keybinding file.", line,buf);
309 keysym = XStringToKeysym(cp);
311 if (keysym == NoSymbol) {
312 LOG(
LOG_WARNING,
"x11::parse_keybind_line",
"Could not convert %s into keysym", cp);
315 if (!strcmp(cpnext,
"commandkey")) {
320 if (!strcmp(cpnext,
"firekey0")) {
325 if (!strcmp(cpnext,
"firekey1")) {
330 if (!strcmp(cpnext,
"runkey0")) {
335 if (!strcmp(cpnext,
"runkey1")) {
340 if (!strcmp(cpnext,
"completekey")) {
345 if (!strcmp(cpnext,
"nextkey")) {
350 if (!strcmp(cpnext,
"prevkey")) {
360 keysym = XStringToKeysym(buf);
362 if ((cpnext = strchr(cp,
' '))==NULL) {
363 LOG(
LOG_WARNING,
"x11::parse_keybind_line",
"Line %d (%s) corrupted in keybinding file.", line, cp);
371 if ((cpnext = strchr(cp,
' '))==NULL) {
372 LOG(
LOG_WARNING,
"x11::parse_keybind_line",
"Line %d (%s) corrupted in keybinding file.", line, cp);
398 LOG(
LOG_WARNING,
"x11::parse_keybind_line",
"Unknown flag (%c) line %d in key binding file",
407 if ((keysym!=NoSymbol) &&
410 keycode = XKeysymToKeycode(
display, keysym);
421 LOG(
LOG_WARNING,
"x11::parse_keybind_line",
"could not convert keysym %s into keycode, ignoring",
426 cpnext[strlen(cpnext)-1]=
'\0';
427 if (strlen(cpnext)>(
sizeof(
bind_buf)-1)){
429 LOG(
LOG_WARNING,
"gtk::parse_keybind_line",
"Had to truncate a too long command");
431 insert_key(keysym, keycode, flags | standard, cpnext);
440 for(i=0;i<
sizeof(
def_keys)/
sizeof(
char *);i++) {
505 sprintf(buf,
"%s/.crossfire/keys", getenv(
"HOME"));
506 if ((fp=fopen(buf,
"r"))==NULL) {
507 LOG(
LOG_INFO,
"x11::init_keys",
"Could not open ~/.crossfire/keys, trying to load global bindings");
513 if ((fp=fopen(buf,
"r"))==NULL) {
518 while (fgets(buf,
BIG_BUF, fp)) {
561 gtk_label_set (GTK_LABEL(
run_label),
" ");
604 gtk_label_set (GTK_LABEL(
run_label),
"Run");
613 if (present_flags ==0) present_flags =
KEYF_NORMAL;
615 keyentry = keys[keycode];
616 while (keyentry!=NULL) {
617 if ((keyentry->
keysym!=NoSymbol && keyentry->
keysym!=keysym) ||
618 (!(keyentry->
flags & present_flags))) {
619 keyentry=keyentry->
next;
622 first_match = keyentry;
625 keyentry=keyentry->
next;
630 if (first_match!=NULL) {
638 gtk_entry_set_text(GTK_ENTRY(
entrytext),buf);
639 gtk_widget_grab_focus (GTK_WIDGET(
entrytext));
649 snprintf(buf,
sizeof(buf),
"fire %s", first_match->
command);
654 snprintf(buf,
sizeof(buf),
"run %s", first_match->
command);
656 else if (!repeated) {
657 strcpy(buf,first_match->
command);
661 snprintf(buf,
sizeof(buf),
"move %s (ignored)", first_match->
command);
670 if (key>=
'0' && key<=
'9') {
678 snprintf(buf,
sizeof(buf),
"Key unused (%s%s%s)",
681 keysym==NoSymbol?
"unknown": XKeysymToString(keysym));
718 if(key->
keysym == NoSymbol) {
719 snprintf(buf,
sizeof(buf),
"(null) %i %s %s",
723 snprintf(buf,
sizeof(buf),
"%s %i %s %s",
724 XKeysymToString(key->
keysym), kc,
729 if(key->
keysym == NoSymbol) {
730 snprintf(buf,
sizeof(buf),
"key (null) (%i) %s %s",
734 snprintf(buf,
sizeof(buf),
"key %s (%i) %s %s",
735 XKeysymToString(key->
keysym), kc,
752 snprintf(buf,
sizeof(buf),
"Commandkey %s (%d)",
756 snprintf(buf,
sizeof(buf),
"Firekeys 1: %s (%d), 2: %s (%d)",
760 snprintf(buf,
sizeof(buf),
"Runkeys 1: %s (%d), 2: %s (%d)",
765 snprintf(buf,
sizeof(buf),
"Command Completion Key %s (%d)",
770 snprintf(buf,
sizeof(buf),
"Next Command in History Key %s (%d)",
775 snprintf(buf,
sizeof(buf),
"Previous Command in History Key %s (%d)",
785 for (key=keys[i]; key!=NULL; key =key->
next) {
788 snprintf(buf,
sizeof(buf),
"%3d %s", count,
get_key_info(key, i, 0));
803 draw_info(
"Usage: bind [-nfre] {<commandline>/commandkey/firekey{1/2}/runkey{1/2}/",
NDI_BLACK);
809 while (*params==
' ') params++;
811 if (!strcmp(params,
"commandkey")) {
818 if (!strcmp(params,
"firekey1")) {
825 if (!strcmp(params,
"firekey2")) {
832 if (!strcmp(params,
"runkey1")) {
839 if (!strcmp(params,
"runkey2")) {
847 if (!strcmp(params,
"completekey")) {
855 if (!strcmp(params,
"prevkey")) {
863 if (!strcmp(params,
"nextkey")) {
872 if (params[0] !=
'-')
878 for (params++; *params !=
' '; params++)
896 snprintf(buf,
sizeof(buf),
"Unknown flag to bind: '%c'", *params);
913 if (strlen(params) >=
sizeof(
bind_buf)) {
918 snprintf(buf,
sizeof(buf),
"Push key to bind '%s'.",
bind_buf);
935 if (key==NULL)
return;
946 sprintf(buf,
"%s/.crossfire/keys", getenv(
"HOME"));
951 if ((fp=fopen(buf,
"w"))==NULL) {
952 snprintf(buf2,
sizeof(buf2),
"Could not open %s, key bindings not saved\n", buf);
957 fprintf(fp,
"! commandkey %s %d\n",
961 fprintf(fp,
"! firekey0 %s %d\n",
965 fprintf(fp,
"! firekey1 %s %d\n",
969 fprintf(fp,
"! runkey0 %s %d\n",
973 fprintf(fp,
"! runkey1 %s %d\n",
977 fprintf(fp,
"! completekey %s %d\n",
982 fprintf(fp,
"! nextkey %s %d\n",
986 fprintf(fp,
"! prevkey %s %d\n",
1034 snprintf(buf,
sizeof(buf),
"Binded to key '%s' (%i)",
1035 keysym==NoSymbol?
"unknown":XKeysymToString(keysym), (
int)k);
1059 int count=0, keyentry, onkey,global=0;
1063 if (params==NULL || params[0]==
'\0') {
1069 while (*params==
' ') params++;
1071 if (!strcmp(params,
"-a")) {
1075 if (!strncmp(params,
"-g",2)) {
1077 if (!(params=strchr(params,
' '))) {
1082 if ((keyentry=atoi(params))==0) {
1088 for (key=keys[onkey]; key; key =key->
next) {
1091 if (keyentry==count) {
1094 if (key == keys[onkey]) {
1095 keys[onkey] = key->
next;
1101 for (tmp=keys[onkey]; tmp->
next!=NULL; tmp=tmp->
next) {
1102 if (tmp->
next == key) {
1107 LOG(
LOG_ERROR,
"x11::unbind_key",
"found number entry, but could not find actual key");
1122 snprintf(buf,
sizeof(buf),
"Removed binding: %3d %s", count,
get_key_info(key, onkey, 0));
1151 snprintf(buf,
sizeof(buf),
"Downloaded %d of %d images", start, total);
1167 #define MAXPIXMAPNUM 10000
void parse_key_release(KeyCode kc, KeySym ks)
static KeySym completekeysym
static const char *const colorname[]
struct @10 private_cache[MAXPIXMAPNUM]
void parse_key(char key, KeyCode keycode, KeySym keysym, int repeated)
static char * get_key_info(Key_Entry *key, KeyCode kc, int save_mode)
void init_cache_data(void)
static char bind_buf[MAX_BUF]
static void save_keys(void)
void client_pickup(uint32 pickup)
static KeyCode completekey
snd_pcm_hw_params_t * params
static XColor discolor[16]
static void init_default_keybindings(void)
int make_path_to_file(char *filename)
const char *const directions[9]
static KeySym runkeysym[2]
PixmapInfo * pixmaps[MAXPIXMAPNUM]
void configure_keys(KeyCode k, KeySym keysym)
void LOG(LogLevel level, const char *origin, const char *format,...)
void parse_keybind_line(char *buf, int line, int standard)
static void unbind_usage(void)
static Key_Entry * keys[256]
void draw_message_window(int redraw)
sint16 use_config[CONFIG_NUMS]
static void show_keys(int allbindings)
void client_tick(uint32 tick)
const char *const def_keys[]
static void save_individual_key(FILE *fp, Key_Entry *key, KeyCode kc)
static KeySym firekeysym[2]
void extended_command(const char *ocommand)
static KeySym * bind_keysym
void bind_key(const char *params)
const char * rcsid_x11_xutil_c
char * strdup_local(const char *str)
void image_update_download_status(int start, int end, int total)
static void insert_key(KeySym keysym, KeyCode keycode, int flags, char *command)
static KeyCode commandkey
void allocate_colors(Display *disp, Window w, long screen_num, Colormap *colormap, XColor discolor[16])
void init_common_cache_data(void)
void draw_info(const char *str, int color)
int find_face_in_private_cache(char *face, int checksum)
static KeyCode * bind_keycode
void unbind_key(const char *params)
void draw_prompt(const char *str)
static KeySym commandkeysym
static KeyCode firekey[2]
void addsmooth(uint16 face, uint16 smooth_face)