diff options
author | sabetts <sabetts> | 2001-09-09 02:59:23 +0000 |
---|---|---|
committer | sabetts <sabetts> | 2001-09-09 02:59:23 +0000 |
commit | 1bd2211aa5c392d9873c74ffc998bea744007a29 (patch) | |
tree | b695cac6f169042430a4d7c1a9cc0ac9bda63304 /src/actions.c | |
parent | 52cd2d7d10d543fe989e3cde617faf7453dcc494 (diff) | |
download | ratpoison-1bd2211aa5c392d9873c74ffc998bea744007a29.zip |
* src/list.h (update_window_position): new prototype
(window_name): new prototype
(get_window_list): update prototype
* src/events.c (grab_rat): Don't wrap in an #ifdef
(ungrab_rat): likewise
(handle_key): record if the rat is grabbed and only ungrab it at
the end if it was first grabbed.
* src/actions.h (cmd_pos): new prototype
(cmd_defwinpos): new prototype
(cmd_deftranspos): new prototype
(cmd_defmaxsizepos): new prototype
(cmd_defbartimeout): new prototype
(cmd_defbarloc): new prototype
(cmd_deffont): new prototype
(cmd_defpadding): new prototype
(cmd_defborder): new prototype
(cmd_definputwidth): new prototype
(cmd_defwaitcursor): new prototype
(cmd_defwinfmt): new prototype
(cmd_defwinname): new prototype
* src/messages.h (MESSAGE_FRAME_STRING): new message
* src/manage.c (get_wmname): renamed from get_window_name
(get_class_hints): new function
(get_res_name): likewise
(get_res_class): likewise
(update_window_name): update the window's wm_name, res_name, and
res_class fields.
(update_window_name): calls functions get_wmname, get_res_name,
get_res_class.
(update_window_name): Don't crop the window name.
(update_window_information): call update_window_position.
(move_window): new function
(maximize_transient): only set the window's width and height
fields.
(maximize_normal): likewise
(maximize): call move_window
(force_maximize): likewise
(force_maximize): if the window has resize hints, resize it 1
resize unit.
* src/main.c: new global variable, defaults. remove static
variable, font, and move to defaults. Dependant code updated.
(init_defaults): new function
(main): call init_defaults.
(init_screen): initialize the screen's fg_color to black and
bg_color to white.
* src/list.c (free_window): free the fields user_name, res_name,
res_class, and wm_name.
(update_window_position): new function
(window_name): new function. Code accessing a window's name uses
this function. All code updated.
(add_to_window_list): call update_window_position
(add_to_window_list): initialize wm_name, res_name, and res_class
for the new window.
(format_window_name): new function
(get_window_list): Add parameter fmt. All callers updated.
(get_window_list): call format_window_name.
* src/conf.h: move Configuration variables to the global variable,
defaults. Dependant code updated.
* src/data.h (TOP_LEFT): new define
(TOP_CENTER): likewise
(TOP_RIGHT): likewise
(CENTER_LEFT): likewise
(CENTER_CENTER): likewise
(CENTER_RIGHT): likewise
(BOTTOM_LEFT): likewise
(BOTTOM_CENTER): likewise
(BOTTOM_RIGHT): likewise
(struct rp_window): new fields user_name, wm_name, res_name,
res_class, position.
(struct rp_window): remove field name. Replaced with
user_name. Dependant code updated.
(struct screen_info): remove field font. dependant code updated.
(struct screen_info): new fields fg_color, bg_color.
(struct rp_defaults): new struct
(defaults): new global
* src/actions.c (parse_winpos): new function
(cmd_pos): likewise
(cmd_defwinpos): likewise
(cmd_deftranspos): likewise
(cmd_defmaxsizepos): likewise
(cmd_defbartimeout): likewise
(cmd_defbarloc): likewise
(cmd_deffont): likewise
(cmd_defpadding): likewise
(cmd_defborder): likewise
(cmd_definputwidth): likewise
(cmd_defwaitcursor): likewise
(cmd_defwinfmt): likewise
(cmd_defwinname): likewise
(user_commands): New commands defbarloc, defbartimeout, defborder,
deffont, defintputwidth, defmaxsizepos, defpadding, deftranspos,
defwaitcursor, defwinfmt, defwinname, defwinpos.
Diffstat (limited to 'src/actions.c')
-rw-r--r-- | src/actions.c | 535 |
1 files changed, 457 insertions, 78 deletions
diff --git a/src/actions.c b/src/actions.c index 74196d5..1d3509e 100644 --- a/src/actions.c +++ b/src/actions.c @@ -30,6 +30,84 @@ static rp_action *key_actions; static int key_actions_last; static int key_actions_table_size; +static user_command user_commands[] = + { {"abort", cmd_abort, arg_VOID}, + {"banish", cmd_banish, arg_VOID}, + {"bind", cmd_bind, arg_VOID}, + {"clock", cmd_clock, arg_VOID}, + {"colon", cmd_colon, arg_STRING}, + {"curframe", cmd_curframe, arg_VOID}, + {"delete", cmd_delete, arg_VOID}, + {"echo", cmd_echo, arg_STRING}, + {"escape", cmd_escape, arg_STRING}, + {"exec", cmd_exec, arg_STRING}, + {"focus", cmd_next_frame, arg_VOID}, + {"generate", cmd_generate, arg_STRING}, /* rename to stuff */ + {"help", cmd_help, arg_VOID}, + {"hsplit", cmd_h_split, arg_VOID}, + {"kill", cmd_kill, arg_VOID}, + {"maximize", cmd_maximize, arg_VOID}, + {"newwm", cmd_newwm, arg_STRING}, + {"next", cmd_next, arg_VOID}, + {"number", cmd_number, arg_STRING}, + {"only", cmd_only, arg_VOID}, + {"other", cmd_other, arg_VOID}, + {"pos", cmd_pos, arg_STRING}, + {"prev", cmd_prev, arg_VOID}, + {"quit", cmd_quit, arg_VOID}, + {"remove", cmd_remove, arg_VOID}, + {"rudeness", cmd_rudeness, arg_STRING}, + {"select", cmd_select, arg_STRING}, + {"source", cmd_source, arg_STRING}, + {"split", cmd_h_split, arg_VOID}, + {"title", cmd_rename, arg_STRING}, + {"unbind", cmd_unbind, arg_STRING}, + {"version", cmd_version, arg_VOID}, + {"vsplit", cmd_v_split, arg_VOID}, + {"windows", cmd_windows, arg_VOID}, + + /* Commands to set default behavior. */ + {"defbarloc", cmd_defbarloc, arg_STRING}, + {"defbartimeout", cmd_defbartimeout, arg_STRING}, + {"defborder", cmd_defborder, arg_STRING}, + {"deffont", cmd_deffont, arg_STRING}, + {"definputwidth", cmd_definputwidth, arg_STRING}, + {"defmaxsizepos", cmd_defmaxsizepos, arg_STRING}, + {"defpadding", cmd_defpadding, arg_STRING}, + {"deftranspos", cmd_deftranspos, arg_STRING}, + {"defwaitcursor", cmd_defwaitcursor, arg_STRING}, + {"defwinfmt", cmd_defwinfmt, arg_STRING}, + {"defwinname", cmd_defwinname, arg_STRING}, + {"defwinpos", cmd_defwinpos, arg_STRING}, + + /* Commands to help debug ratpoison. */ +#ifdef DEBUG +#endif + + /* the following screen commands may or may not be able to be + implemented. See the screen documentation for what should be + emulated with these commands */ +#if 0 + {"hardcopy", cmd_unimplemented, arg_VOID}, + {"lastmsg", cmd_unimplemented, arg_VOID}, + {"license", cmd_unimplemented, arg_VOID}, + {"lockscreen", cmd_unimplemented, arg_VOID}, + {"meta", cmd_unimplemented, arg_VOID}, + {"msgminwait", cmd_unimplemented, arg_VOID}, + {"msgwait", cmd_unimplemented, arg_VOID}, + {"nethack", cmd_unimplemented, arg_VOID}, + {"redisplay", cmd_unimplemented, arg_VOID}, + {"screen", cmd_unimplemented, arg_VOID}, + {"setenv", cmd_unimplemented, arg_VOID}, + {"shell", cmd_unimplemented, arg_VOID}, + {"shelltitle", cmd_unimplemented, arg_VOID}, + {"sleep", cmd_unimplemented, arg_VOID}, + {"sorendition", cmd_unimplemented, arg_VOID}, + {"startup_message", cmd_unimplemented, arg_VOID}, + {"stuff", cmd_unimplemented, arg_VOID}, +#endif + {0, 0, 0} }; + rp_action* find_keybinding_by_action (char *action) { @@ -184,65 +262,6 @@ initialize_default_keybindings (void) add_keybinding (XK_question, 0, "help"); } -user_command user_commands[] = - { {"abort", cmd_abort, arg_VOID}, - {"next", cmd_next, arg_VOID}, - {"prev", cmd_prev, arg_VOID}, - {"exec", cmd_exec, arg_STRING}, - {"select", cmd_select, arg_STRING}, - {"colon", cmd_colon, arg_STRING}, - {"kill", cmd_kill, arg_VOID}, - {"delete", cmd_delete, arg_VOID}, - {"other", cmd_other, arg_VOID}, - {"windows", cmd_windows, arg_VOID}, - {"title", cmd_rename, arg_STRING}, - {"clock", cmd_clock, arg_VOID}, - {"maximize", cmd_maximize, arg_VOID}, - {"newwm", cmd_newwm, arg_STRING}, - {"generate", cmd_generate, arg_STRING}, /* rename to stuff */ - {"version", cmd_version, arg_VOID}, - {"bind", cmd_bind, arg_VOID}, - {"unbind", cmd_unbind, arg_STRING}, - {"source", cmd_source, arg_STRING}, - {"escape", cmd_escape, arg_STRING}, - {"echo", cmd_echo, arg_STRING}, - {"split", cmd_h_split, arg_VOID}, - {"hsplit", cmd_h_split, arg_VOID}, - {"vsplit", cmd_v_split, arg_VOID}, - {"focus", cmd_next_frame, arg_VOID}, - {"only", cmd_only, arg_VOID}, - {"remove", cmd_remove, arg_VOID}, - {"banish", cmd_banish, arg_VOID}, - {"curframe", cmd_curframe, arg_VOID}, - {"help", cmd_help, arg_VOID}, - {"quit", cmd_quit, arg_VOID}, - {"number", cmd_number, arg_STRING}, - {"rudeness", cmd_rudeness, arg_STRING}, - - /* the following screen commands may or may not be able to be - implemented. See the screen documentation for what should be - emulated with these commands */ -#if 0 - {"stuff", cmd_unimplemented, arg_VOID}, - {"hardcopy", cmd_unimplemented, arg_VOID}, - {"lastmsg", cmd_unimplemented, arg_VOID}, - {"license", cmd_unimplemented, arg_VOID}, - {"lockscreen", cmd_unimplemented, arg_VOID}, - {"meta", cmd_unimplemented, arg_VOID}, - {"msgwait", cmd_unimplemented, arg_VOID}, - {"msgminwait", cmd_unimplemented, arg_VOID}, - {"nethack", cmd_unimplemented, arg_VOID}, - {"redisplay", cmd_unimplemented, arg_VOID}, - {"screen", cmd_unimplemented, arg_VOID}, - {"setenv", cmd_unimplemented, arg_VOID}, - {"shell", cmd_unimplemented, arg_VOID}, - {"shelltitle", cmd_unimplemented, arg_VOID}, - {"sleep", cmd_unimplemented, arg_VOID}, - {"sorendition", cmd_unimplemented, arg_VOID}, - {"startup_message", cmd_unimplemented, arg_VOID}, -#endif - {0, 0, 0} }; - /* return a KeySym from a string that contains either a hex value or an X keysym description */ static int string_to_keysym (char *str) @@ -680,10 +699,10 @@ cmd_rename (int interactive, void *data) if (*winname) { - free (current_window()->name); - current_window()->name = xmalloc (sizeof (char) * strlen (winname) + 1); + free (current_window()->user_name); + current_window()->user_name = xmalloc (sizeof (char) * strlen (winname) + 1); - strcpy (current_window()->name, winname); + strcpy (current_window()->user_name, winname); current_window()->named = 1; @@ -987,7 +1006,7 @@ cmd_windows (int interactive, void *data) else { window_list = sbuf_new (0); - get_window_list ("\n", window_list, &dummy, &dummy); + get_window_list (defaults.window_fmt, "\n", window_list, &dummy, &dummy); tmp = sbuf_get (window_list); free (window_list); @@ -1153,23 +1172,23 @@ cmd_help (int interactive, void *data) XSetInputFocus (dpy, s->help_window, RevertToPointerRoot, CurrentTime); XDrawString (dpy, s->help_window, s->normal_gc, - 10, y + s->font->max_bounds.ascent, + 10, y + defaults.font->max_bounds.ascent, "ratpoison key bindings", strlen ("ratpoison key bindings")); - y += FONT_HEIGHT (s->font) * 2; + y += FONT_HEIGHT (defaults.font) * 2; XDrawString (dpy, s->help_window, s->normal_gc, - 10, y + s->font->max_bounds.ascent, + 10, y + defaults.font->max_bounds.ascent, "Command key: ", strlen ("Command key: ")); keysym_name = keysym_to_string (prefix_key.sym, prefix_key.state); XDrawString (dpy, s->help_window, s->normal_gc, - 10 + XTextWidth (s->font, "Command key: ", strlen ("Command key: ")), - y + s->font->max_bounds.ascent, + 10 + XTextWidth (defaults.font, "Command key: ", strlen ("Command key: ")), + y + defaults.font->max_bounds.ascent, keysym_name, strlen (keysym_name)); free (keysym_name); - y += FONT_HEIGHT (s->font) * 2; + y += FONT_HEIGHT (defaults.font) * 2; i = 0; old_i = 0; @@ -1180,12 +1199,12 @@ cmd_help (int interactive, void *data) keysym_name = keysym_to_string (key_actions[i].key, key_actions[i].state); XDrawString (dpy, s->help_window, s->normal_gc, - x, y + s->font->max_bounds.ascent, + x, y + defaults.font->max_bounds.ascent, keysym_name, strlen (keysym_name)); - if (XTextWidth (s->font, keysym_name, strlen (keysym_name)) > max_width) + if (XTextWidth (defaults.font, keysym_name, strlen (keysym_name)) > max_width) { - max_width = XTextWidth (s->font, keysym_name, strlen (keysym_name)); + max_width = XTextWidth (defaults.font, keysym_name, strlen (keysym_name)); } free (keysym_name); @@ -1193,16 +1212,16 @@ cmd_help (int interactive, void *data) else { XDrawString (dpy, s->help_window, s->normal_gc, - x, y + s->font->max_bounds.ascent, + x, y + defaults.font->max_bounds.ascent, key_actions[i].data, strlen (key_actions[i].data)); - if (XTextWidth (s->font, key_actions[i].data, strlen (key_actions[i].data)) > max_width) + if (XTextWidth (defaults.font, key_actions[i].data, strlen (key_actions[i].data)) > max_width) { - max_width = XTextWidth (s->font, key_actions[i].data, strlen (key_actions[i].data)); + max_width = XTextWidth (defaults.font, key_actions[i].data, strlen (key_actions[i].data)); } } - y += FONT_HEIGHT (s->font); + y += FONT_HEIGHT (defaults.font); if (y > s->root_attr.height) { if (drawing_keys) @@ -1219,7 +1238,7 @@ cmd_help (int interactive, void *data) } max_width = 0; - y = FONT_HEIGHT (s->font) * 4; + y = FONT_HEIGHT (defaults.font) * 4; } else { @@ -1228,7 +1247,7 @@ cmd_help (int interactive, void *data) { x += max_width + 10; drawing_keys = 0; - y = FONT_HEIGHT (s->font) * 4; + y = FONT_HEIGHT (defaults.font) * 4; i = old_i; max_width = 0; } @@ -1266,3 +1285,363 @@ cmd_rudeness (int interactive, void *data) return NULL; } + +static int +parse_winpos (char *data) +{ + int ret = 0; + char *x, *y; + + x = xmalloc (strlen (data) + 1); + y = xmalloc (strlen (data) + 1); + + if (sscanf (data, "%s %s", x , y) < 2) + { + message (" pos: Two arguments needed "); + free (x); + free (y); + return -3; + } + + PRINT_DEBUG ("%s %s\n", x, y); + + switch (y[0]) + { + case 't': + case 'T': + ret = TOP_LEFT; + break; + + case 'c': + case 'C': + ret = CENTER_LEFT; + break; + + case 'b': + case 'B': + ret = BOTTOM_LEFT; + break; + + default: + ret = -1; + goto done; + break; + } + + switch (x[0]) + { + case 'l': + case 'L': + break; + + case 'c': + case 'C': + ret += TOP_CENTER; + break; + + case 'r': + case 'R': + ret += TOP_RIGHT; + break; + + default: + ret = -2; + goto done; + break; + } + + done: + free (x); + free (y); + + return ret; +} + +char * +cmd_pos (int interactive, void *data) +{ + int pos; + rp_window *win; + + if (current_window() == NULL) return NULL; + if (data == NULL) + { + message (" pos: Two arguments needed "); + return NULL; + } + + win = current_window(); + + if ((pos = parse_winpos (data)) < 0) + { + message (" pos: Unknown position "); + } + else + { + win->position = pos; + maximize (win); + } + + return NULL; +} + +char * +cmd_defwinpos (int interactive, void *data) +{ + int pos; + + if ((pos = parse_winpos (data)) < 0) + { + message (" pos: Unknown position "); + } + else + { + defaults.win_pos = pos; + } + + return NULL; +} + +char * +cmd_deftranspos (int interactive, void *data) +{ + int pos; + + if ((pos = parse_winpos (data)) < 0) + { + message (" pos: Unknown position "); + } + else + { + defaults.trans_pos = pos; + } + + return NULL; +} + +char * +cmd_defmaxsizepos (int interactive, void *data) +{ + int pos; + + if ((pos = parse_winpos (data)) < 0) + { + message (" pos: Unknown position "); + } + else + { + defaults.maxsize_pos = pos; + } + + return NULL; +} + +char * +cmd_defbartimeout (int interactive, void *data) +{ + if (data == NULL) return NULL; + + if (sscanf (data, "%d", &defaults.bar_timeout) < 1) + { + message (" defbartimeout: One argument required "); + } + + return NULL; +} + +char * +cmd_defbarloc (int interactive, void *data) +{ + int loc; + + if (data == NULL) return NULL; + + if (sscanf (data, "%d", &loc) < 1) + { + message (" defbarloc: One argument required "); + return NULL; + } + + switch (loc) + { + case 0: + defaults.bar_location = TOP_LEFT; + break; + case 1: + defaults.bar_location = TOP_RIGHT; + break; + case 2: + defaults.bar_location = BOTTOM_RIGHT; + break; + case 3: + defaults.bar_location = BOTTOM_LEFT; + break; + + default: + message (" defbarloc: Unknown location "); + break; + } + + return NULL; +} + +char * +cmd_deffont (int interactive, void *data) +{ + XFontStruct *font; + + if (data == NULL) return NULL; + + font = XLoadQueryFont (dpy, (char *)data); + if (font == NULL) + { + message (" deffont: Unknown font "); + return NULL; + } + + /* Save the font as the default. */ + XFreeFont (dpy, defaults.font); + defaults.font = font; + + return NULL; +} + +char * +cmd_defpadding (int interactive, void *data) +{ + rp_window_frame *frame; + int l, t, r, b; + + if (data == NULL) + { + message (" defpadding: Four arguments required "); + return NULL; + } + + if (sscanf (data, "%d %d %d %d", &l, &t, &r, &b) < 4) + { + message (" defpadding: Four arguments required "); + return NULL; + } + + /* Resize the frames to make sure they are not too big and not too + small. */ + for (frame = rp_window_frame_sentinel->next; + frame != rp_window_frame_sentinel; + frame = frame->next) + { + int bk_pos, bk_len; + + /* Resize horizontally. */ + bk_pos = frame->x; + bk_len = frame->width; + + if (frame->x == defaults.padding_left) + { + frame->x = l; + frame->width += bk_pos - l; + } + + if (bk_pos + bk_len == current_screen()->root_attr.width - defaults.padding_right) + frame->width = current_screen()->root_attr.width - r - frame->x; + + /* Resize vertically. */ + bk_pos = frame->y; + bk_len = frame->height; + + if (frame->y == defaults.padding_top) + { + frame->y = t; + frame->height += bk_pos - t; + } + + if (bk_pos + bk_len == current_screen()->root_attr.height - defaults.padding_bottom) + frame->height = current_screen()->root_attr.height - b - frame->y; + + maximize_all_windows_in_frame (frame); + } + + defaults.padding_left = l; + defaults.padding_right = r; + defaults.padding_top = t; + defaults.padding_bottom = b; + + return NULL; +} + +char * +cmd_defborder (int interactive, void *data) +{ + rp_window *win; + + if (data == NULL) return NULL; + + if (sscanf (data, "%d", &defaults.window_border_width) < 1) + { + message (" defborder: One argument required "); + } + + /* Update all the visible windows. */ + for (win = rp_mapped_window_sentinel->next; + win != rp_mapped_window_sentinel; + win = win->next) + { + if (win->frame) + maximize (win); + } + + return NULL; +} + +char * +cmd_definputwidth (int interactive, void *data) +{ + if (data == NULL + || sscanf (data, "%d", &defaults.input_window_size) < 1) + { + message (" definputwidth: One argument required "); + } + + return NULL; +} + +char * +cmd_defwaitcursor (int interactive, void *data) +{ + if (data == NULL + || sscanf (data, "%d", &defaults.wait_for_key_cursor) < 1) + { + message (" defwaitforkey: One argument required "); + } + + return NULL; +} + +char * +cmd_defwinfmt (int interactive, void *data) +{ + if (data == NULL) return NULL; + + free (defaults.window_fmt); + defaults.window_fmt = strdup (data); + + if (defaults.window_fmt == NULL) + { + PRINT_ERROR ("Not enough memory\n"); + exit (EXIT_FAILURE); + } + + return NULL; +} + +char * +cmd_defwinname (int interactive, void *data) +{ + if (data == NULL + || sscanf (data, "%d", &defaults.win_name) < 1) + { + message (" defwinname: One argument required "); + } + + return NULL; +} |