summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog26
-rw-r--r--src/actions.c57
-rw-r--r--src/bar.c6
-rw-r--r--src/events.c2
-rw-r--r--src/group.c57
-rw-r--r--src/group.h3
-rw-r--r--src/input.c17
-rw-r--r--src/input.h2
8 files changed, 113 insertions, 57 deletions
diff --git a/ChangeLog b/ChangeLog
index 546ace8..bdcd656 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,29 @@
+2003-05-25 Shawn Betts <sabetts@sfu.ca>
+
+ * src/input.c (read_key): Do not wait for the key release
+ event. Remove gobble_rel argument. Callers updated.
+
+2003-05-24 Shawn Betts <sabetts@sfu.ca>
+
+ * src/group.h (group_resort_window): new prototype
+
+ * src/group.c (group_find_window_by_number): return
+ rp_window_elem*. Dependant code updated.
+ (group_insert_window): new function
+ (group_in_list): likewise
+ (group_resort_window): likewise
+ (group_map_window): insert the window and sort the list.
+
+ * src/actions.c (cmd_number): Change the group number of the
+ window.
+ (cmd_resize): print an error message if the command was called
+ interactively with <2 arguments.
+
+2003-05-21 Shawn Betts <sabetts@sfu.ca>
+
+ * src/actions.c (cmd_resize): fail if data == NULL when called
+ non-interactively.
+
2003-05-20 Shawn Betts <sabetts@sfu.ca>
* src/linkedlist.h: Move all C function to linkedlist.c
diff --git a/src/actions.c b/src/actions.c
index 31e8cda..ca12c4e 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -781,7 +781,9 @@ cmd_select (int interactive, char *data)
/* try by number */
else if ((n = string_to_window_number (str)) >= 0)
{
- if ((w = group_find_window_by_number (rp_current_group, n)))
+ rp_window_elem *elem = group_find_window_by_number (rp_current_group, n);
+
+ if ((w = elem->win))
goto_window (w);
else
/* show the window list as feedback */
@@ -1098,16 +1100,12 @@ cmd_time (int interactive, char *data)
return NULL;
}
-/* Assign a new number to a window ala screen's number command. Thanks
- to Martin Samuelsson <cosis@lysator.liu.se> for the original
- patch. */
-/* FIXME: With the new group code, this doesn't work as expected. */
+/* Assign a new number to a window ala screen's number command. */
char *
cmd_number (int interactive, char *data)
{
- rp_frame *frame;
int old_number, new_number;
- rp_window *other_win, *win;
+ rp_window_elem *other_win, *win;
char *str;
char *tmp;
@@ -1116,11 +1114,9 @@ cmd_number (int interactive, char *data)
print_window_information (current_window());
return NULL;
}
- else
- {
- str = xstrdup (data);
- }
+ /* Read in the number requested by the user. */
+ str = xstrdup (data);
tmp = strtok (str, " ");
if (tmp)
{
@@ -1157,33 +1153,26 @@ cmd_number (int interactive, char *data)
return NULL;
}
- win = find_window_number (win_number);
+ win = group_find_window_by_number (rp_current_group, win_number);
}
else
{
PRINT_DEBUG (("2nd: NULL\n"));
- win = current_window();
+ win = group_find_window (&rp_current_group->mapped_windows, current_window());
}
+ /* Make the switch. */
if ( new_number >= 0 && win)
{
/* Find other window with same number and give it old number. */
- other_win = find_window_number (new_number);
+ other_win = group_find_window_by_number (rp_current_group, new_number);
if (other_win != NULL)
{
old_number = win->number;
other_win->number = old_number;
- /* Update the frame containing the window. */
- if (other_win->frame_number != EMPTY)
- {
- frame = screen_get_frame (other_win->scr, other_win->frame_number);
- frame->win_number = old_number;
- }
-
/* Resort the window in the list */
- list_del (&other_win->node);
- insert_into_list (other_win, &rp_mapped_window);
+ group_resort_window (rp_current_group, other_win);
}
else
{
@@ -1193,19 +1182,11 @@ cmd_number (int interactive, char *data)
win->number = new_number;
numset_add_num (rp_window_numset, new_number);
- /* Update the frame containing the window. */
- if (win->frame_number != EMPTY)
- {
- frame = screen_get_frame (win->scr, win->frame_number);
- frame->win_number = new_number;
- }
-
/* resort the the window in the list */
- list_del (&win->node);
- insert_into_list (win, &rp_mapped_window);
+ group_resort_window (rp_current_group, win);
/* Update the window list. */
- update_window_names (win->scr);
+ update_window_names (win->win->scr);
}
free (str);
@@ -1457,7 +1438,7 @@ cmd_resize (int interactive, char *data)
while (1)
{
show_frame_message (" Resize frame ");
- nbytes = read_key (&c, &mod, buffer, sizeof (buffer), 1);
+ nbytes = read_key (&c, &mod, buffer, sizeof (buffer));
if (c == RESIZE_VGROW_KEY && mod == RESIZE_VGROW_MODIFIER)
resize_frame_vertically (current_frame(), defaults.frame_resize_unit);
@@ -1497,6 +1478,12 @@ cmd_resize (int interactive, char *data)
else
{
int xdelta, ydelta;
+
+ if (data == NULL)
+ {
+ message (" resize: Two numeric arguments required ");
+ return NULL;
+ }
if (sscanf (data, "%d %d", &xdelta, &ydelta) < 2)
{
@@ -2970,7 +2957,7 @@ cmd_fselect (int interactive, char *data)
/* Read a key. */
XGetInputFocus (dpy, &fwin, &revert);
XSetInputFocus (dpy, s->key_window, RevertToPointerRoot, CurrentTime);
- read_key (&c, &mod, NULL, 0, 1);
+ read_key (&c, &mod, NULL, 0);
XSetInputFocus (dpy, fwin, RevertToPointerRoot, CurrentTime);
/* Destroy our number windows and free the array. */
diff --git a/src/bar.c b/src/bar.c
index 86edcb9..8266f6b 100644
--- a/src/bar.c
+++ b/src/bar.c
@@ -246,8 +246,10 @@ pos_in_line (char* msg, int pos)
int ret=0;
if(i>=0)
{
- for(; i<=pos && i>=0; ++ret, --i) if(msg[i]=='\n') break;
- }
+ for(; i<=pos && i>=0; ++ret, --i)
+ if(msg[i]=='\n')
+ break;
+ }
PRINT_DEBUG (("pos_in_line(\"%s\", %d) = %d\n", msg, pos, ret));
return ret;
}
diff --git a/src/events.c b/src/events.c
index 02a30d7..ce006e4 100644
--- a/src/events.c
+++ b/src/events.c
@@ -394,7 +394,7 @@ handle_key (rp_screen *s)
rat_grabbed = 1;
}
- read_key (&keysym, &mod, NULL, 0, 1);
+ read_key (&keysym, &mod, NULL, 0);
XSetInputFocus (dpy, fwin, revert, CurrentTime);
if (rat_grabbed)
diff --git a/src/group.c b/src/group.c
index b09e2e3..cbf645e 100644
--- a/src/group.c
+++ b/src/group.c
@@ -77,7 +77,7 @@ group_find_window (struct list_head *list, rp_window *win)
return NULL;
}
-rp_window *
+rp_window_elem *
group_find_window_by_number (rp_group *g, int num)
{
rp_window_elem *cur;
@@ -85,13 +85,63 @@ group_find_window_by_number (rp_group *g, int num)
list_for_each_entry (cur, &g->mapped_windows, node)
{
if (cur->number == num)
- return cur->win;
+ return cur;
}
return NULL;
}
+
+/* Insert a window_elem into the correct spot in the group's window
+ list to preserve window number ordering. */
+static void
+group_insert_window (struct list_head *h, rp_window_elem *w)
+{
+ rp_window_elem *cur;
+
+ list_for_each_entry (cur, h, node)
+ {
+ if (cur->number > w->number)
+ {
+ list_add_tail (&w->node, &cur->node);
+ return;
+ }
+ }
+
+ list_add_tail(&w->node, h);
+}
+
+int
+group_in_list (struct list_head *h, rp_window_elem *w)
+{
+ rp_window_elem *cur;
+
+ list_for_each_entry (cur, h, node)
+ {
+ if (cur == w)
+ return 1;
+ }
+
+ return 0;
+}
+
+/* If a window_elem's number has changed then the list has to be
+ resorted. */
+void
+group_resort_window (rp_group *g, rp_window_elem *w)
+{
+ /* Only a mapped window can be resorted. */
+ if (!group_in_list (&g->mapped_windows, w))
+ {
+ PRINT_DEBUG (("Attempting to restort an unmapped window!\n"));
+ return;
+ }
+
+ list_del (&w->node);
+ group_insert_window (&g->mapped_windows, w);
+}
+
void
group_add_window (rp_group *g, rp_window *w)
{
@@ -116,7 +166,8 @@ group_map_window (rp_group *g, rp_window *win)
if (we)
{
we->number = numset_request (g->numset);
- list_move_tail (&we->node, &g->mapped_windows);
+ list_del (&we->node);
+ group_insert_window (&g->mapped_windows, we);
}
}
diff --git a/src/group.h b/src/group.h
index 346ffe8..fa58cce 100644
--- a/src/group.h
+++ b/src/group.h
@@ -3,6 +3,7 @@
void init_groups ();
void group_add_window (rp_group *g, rp_window *w);
+void group_resort_window (rp_group *g, rp_window_elem *w);
void group_free (rp_group *g);
rp_group *group_new (int number);
@@ -26,6 +27,6 @@ rp_group *group_next_group ();
rp_group *group_add_new_group ();
rp_window_elem *group_find_window (struct list_head *list, rp_window *win);
-rp_window *group_find_window_by_number (rp_group *g, int num);
+rp_window_elem *group_find_window_by_number (rp_group *g, int num);
#endif
diff --git a/src/input.c b/src/input.c
index 94e2c9a..1cb370e 100644
--- a/src/input.c
+++ b/src/input.c
@@ -258,30 +258,19 @@ cook_keycode (XKeyEvent *ev, KeySym *keysym, unsigned int *mod, char *keysym_nam
}
int
-read_key (KeySym *keysym, unsigned int *modifiers, char *keysym_name, int len, int gobble_rel)
+read_key (KeySym *keysym, unsigned int *modifiers, char *keysym_name, int len)
{
XEvent ev;
int nbytes;
- unsigned int keycode;
/* Read a key from the keyboard. */
do
{
XMaskEvent (dpy, KeyPressMask, &ev);
- /* Store the keycode so we can wait for it's corresponding key
- release event. */
- keycode = ev.xkey.keycode;
*modifiers = ev.xkey.state;
nbytes = cook_keycode (&ev.xkey, keysym, modifiers, keysym_name, len, 0);
} while (IsModifierKey (*keysym));
- /* Gobble the release event for the key we pressed. */
- if (gobble_rel)
- do
- {
- XMaskEvent (dpy, KeyReleaseMask, &ev);
- } while (ev.xkey.keycode != keycode);
-
return nbytes;
}
@@ -369,7 +358,7 @@ get_more_input (char *prompt, char *preinput)
/* XSync (dpy, False); */
- nbytes = read_key (&ch, &modifier, keysym_buf, keysym_bufsize, 0);
+ nbytes = read_key (&ch, &modifier, keysym_buf, keysym_bufsize);
while (ch != XK_Return)
{
PRINT_DEBUG (("key %ld\n", ch));
@@ -441,7 +430,7 @@ get_more_input (char *prompt, char *preinput)
update_input_window(s, prompt, str, cur_len);
}
- nbytes = read_key (&ch, &modifier, keysym_buf, keysym_bufsize, 0);
+ nbytes = read_key (&ch, &modifier, keysym_buf, keysym_bufsize);
}
str[cur_len] = 0;
diff --git a/src/input.h b/src/input.h
index 631d4d4..0544f37 100644
--- a/src/input.h
+++ b/src/input.h
@@ -26,7 +26,7 @@ char *keysym_to_string (KeySym keysym, unsigned int modifier);
int cook_keycode (XKeyEvent *ev, KeySym *keysym, unsigned int *mod, char *keysym_name, int len, int ignore_bad_mods);
char *get_input (char *prompt);
char *get_more_input (char *prompt, char *preinput);
-int read_key (KeySym *keysym, unsigned int *modifiers, char *keysym_name, int len, int gobble_rel);
+int read_key (KeySym *keysym, unsigned int *modifiers, char *keysym_name, int len);
unsigned int x11_mask_to_rp_mask (unsigned int mask);
unsigned int rp_mask_to_x11_mask (unsigned int mask);
void update_modifier_map ();