summaryrefslogtreecommitdiff
path: root/src/split.c
diff options
context:
space:
mode:
authorsabetts <sabetts>2003-02-22 11:16:55 +0000
committersabetts <sabetts>2003-02-22 11:16:55 +0000
commit00a37f7479fc780669afd3ad82d938a1096952d0 (patch)
treed3c88eb1ae06ed1c7c94c69057f0fcbf6fce48a1 /src/split.c
parent4cacfe9c7bf4fea269a7f99879bc3f1e6ea9d45b (diff)
downloadratpoison-00a37f7479fc780669afd3ad82d938a1096952d0.zip
* src/actions.c (cmd_number): use list delete entry macro
(cmd_number): likewise (cmd_escape): use list looping macro (cmd_escape): likewise (cmd_defpadding): likewise (cmd_defborder): likewise * src/data.h: include linkedlist.h (struct rp_window_frame): use struct list_head instead of next, prev pointers. (struct rp_window): likewise (struct screen_info): rename rp_window_frame_sentinel to rp_window_frames and change it's type to list_head. * src/events.c (mapping_notify): use list looping macro (mapping_notify): likewise * src/list.c: rename rp_unmapped_window_sentinel to rp_unmapped_window and rp_mapped_window_sentinel to rp_mapped_window. Use LIST_HEAD to create them. externs updated. (add_to_window_list): use list add entry macro. (find_window_in_list): list head is of type list_head. Prototype and callers updated. (find_window_in_list): use list looping macro (init_window_list): remove function (find_window_number): use list looping macro (find_window_name): likewise (find_window_prev): use list previous entry macro (find_window_next): use list next entry macro (find_window_other): use list looping macro (append_to_list): remove function (insert_into_list): use list looping macro (insert_into_list): use list add entry macro (remove_from_list): remove function (get_window_list): use list looping macro * src/main.c (main): do not call init_window_list() * src/manage.c (unmanage): use list delete macro (map_window): likewise (withdraw_window): use list moving macro to move entry to another list. (hide_others): use list looping macro * src/split.c (num_frames): use list looping macro (frames_screen): likewise (maximize_all_windows_in_frame): likewise (delete_frame_from_list): remove function (create_initial_frame): remove list init code. Add current frame to screen's frame list. (init_frame_list): use list init macro (find_last_frame): use list looping macro (find_windows_frame): likewise (find_frame_next): use list next entry macro (find_frame_prev): use list previous entry macro (find_window_for_frame): use list looping macro (split_frame): use list add entry macro (remove_all_splits): use list looping macro (resize_frame_vertically): likewise (resize_frame_horizontally): likewise (total_frame_area): likewise (frame_overlaps): likewise (remove_frame): likewise (find_frame_up): likewise (find_frame_down): likewise (find_frame_left): likewise (find_frame_right): likewise
Diffstat (limited to 'src/split.c')
-rw-r--r--src/split.c177
1 files changed, 44 insertions, 133 deletions
diff --git a/src/split.c b/src/split.c
index 53b596b..68f6cfb 100644
--- a/src/split.c
+++ b/src/split.c
@@ -44,9 +44,7 @@ num_frames (screen_info *s)
int count = 0;
rp_window_frame *cur;
- for (cur = s->rp_window_frame_sentinel->next;
- cur != s->rp_window_frame_sentinel;
- cur = cur->next)
+ list_for_each_entry (cur, &s->rp_window_frames, node)
{
count++;
}
@@ -74,9 +72,7 @@ frames_screen (rp_window_frame *frame)
rp_window_frame *cur;
for (i=0; i<num_screens; i++)
- for (cur = screens[i].rp_window_frame_sentinel->next;
- cur !=screens[i]. rp_window_frame_sentinel;
- cur = cur->next)
+ list_for_each_entry (cur, &screens[i].rp_window_frames, node)
{
if (frame == cur)
return &screens[i];
@@ -92,9 +88,7 @@ maximize_all_windows_in_frame (rp_window_frame *frame)
{
rp_window *win;
- for (win = rp_mapped_window_sentinel->next;
- win != rp_mapped_window_sentinel;
- win = win->next)
+ list_for_each_entry (win, &rp_mapped_window, node)
{
if (win->frame == frame)
{
@@ -103,13 +97,6 @@ maximize_all_windows_in_frame (rp_window_frame *frame)
}
}
-static void
-delete_frame_from_list (rp_window_frame *frame)
-{
- frame->next->prev = frame->prev;
- frame->prev->next = frame->next;
-}
-
/* Make the frame occupy the entire screen */
static void
maximize_frame (rp_window_frame *frame)
@@ -129,15 +116,10 @@ create_initial_frame (screen_info *screen)
{
screen->rp_current_frame = xmalloc (sizeof (rp_window_frame));
- update_last_access (screen->rp_current_frame);
-
- screen->rp_window_frame_sentinel->next = screen->rp_current_frame;
- screen->rp_window_frame_sentinel->prev = screen->rp_current_frame;
- screen->rp_current_frame->next = screen->rp_window_frame_sentinel;
- screen->rp_current_frame->prev = screen->rp_window_frame_sentinel;
+ list_add_tail (&screen->rp_current_frame->node, &screen->rp_window_frames);
+ update_last_access (screen->rp_current_frame);
maximize_frame (screen->rp_current_frame);
-
set_frames_window (screen->rp_current_frame, NULL);
}
@@ -153,10 +135,7 @@ init_frame_lists ()
void
init_frame_list (screen_info *screen)
{
- screen->rp_window_frame_sentinel = xmalloc (sizeof (rp_window_frame));
-
- screen->rp_window_frame_sentinel->next = screen->rp_window_frame_sentinel;
- screen->rp_window_frame_sentinel->prev = screen->rp_window_frame_sentinel;
+ INIT_LIST_HEAD (&screen->rp_window_frames);
create_initial_frame(screen);
}
@@ -167,9 +146,7 @@ find_last_frame (screen_info *s)
rp_window_frame *cur, *last = NULL;
int last_access = -1;
- for (cur = s->rp_window_frame_sentinel->next;
- cur != s->rp_window_frame_sentinel;
- cur = cur->next)
+ list_for_each_entry (cur, &s->rp_window_frames, node)
{
if (cur != s->rp_current_frame
&& cur->last_access > last_access)
@@ -191,9 +168,7 @@ find_windows_frame (rp_window *win)
s = win->scr;
- for (cur = s->rp_window_frame_sentinel->next;
- cur != s->rp_window_frame_sentinel;
- cur = cur->next)
+ list_for_each_entry (cur, &s->rp_window_frames, node)
{
if (cur->win == win) return cur;
}
@@ -204,35 +179,15 @@ find_windows_frame (rp_window *win)
rp_window_frame *
find_frame_next (rp_window_frame *frame)
{
- rp_window_frame *cur;
-
if (frame == NULL) return NULL;
-
- cur = frame;
- if (cur->next == frames_screen (frame)->rp_window_frame_sentinel)
- {
- cur = cur->next;
- if (cur->next == frame) return NULL;
- }
-
- return cur->next;
+ return list_next_entry (frame, &frames_screen (frame)->rp_window_frames, node);
}
rp_window_frame *
find_frame_prev (rp_window_frame *frame)
{
- rp_window_frame *cur;
-
if (frame == NULL) return NULL;
-
- cur = frame;
- if (cur->prev == frames_screen (frame)->rp_window_frame_sentinel)
- {
- cur = cur->prev;
- if (cur->prev == frame) return NULL;
- }
-
- return cur->prev;
+ return list_prev_entry (frame, &frames_screen (frame)->rp_window_frames, node);
}
rp_window *
@@ -269,9 +224,7 @@ find_window_for_frame (rp_window_frame *frame)
rp_window *most_recent = NULL;
rp_window *cur;
- for (cur = rp_mapped_window_sentinel->next;
- cur != rp_mapped_window_sentinel;
- cur = cur->next)
+ list_for_each_entry (cur, &rp_mapped_window, node)
{
if (cur->scr == s
&& cur != current_window()
@@ -305,11 +258,10 @@ split_frame (rp_window_frame *frame, int way, int pixels)
frame. */
update_last_access (new_frame);
- /* append the new frame to the list */
- new_frame->prev = s->rp_window_frame_sentinel->prev;
- s->rp_window_frame_sentinel->prev->next = new_frame;
- s->rp_window_frame_sentinel->prev = new_frame;
- new_frame->next = s->rp_window_frame_sentinel;
+ /* TODO: don't put the new frame at the end of the list, put it
+ after the existing frame. Then cycling frames cycles in the order
+ they were created. */
+ list_add_tail (&new_frame->node, &s->rp_window_frames);
set_frames_window (new_frame, NULL);
@@ -379,46 +331,31 @@ h_split_frame (rp_window_frame *frame, int pixels)
void
remove_all_splits ()
{
+ struct list_head *tmp, *iter;
screen_info *s = &screens[rp_current_screen];
- rp_window *cur_window;
- rp_window_frame *frame, *cur_frame;
- rp_window *win;
+ rp_window_frame *frame = NULL;
+ rp_window *win = NULL;
- cur_window = current_window();
- cur_frame = s->rp_current_frame;
-
- while (s->rp_window_frame_sentinel->next != s->rp_window_frame_sentinel)
+ /* Hide all the windows not in the current frame. */
+ list_for_each_entry (win, &rp_mapped_window, node)
{
- frame = s->rp_window_frame_sentinel->next;
- delete_frame_from_list (frame);
- if (frame != s->rp_current_frame)
- {
- for (win = rp_mapped_window_sentinel->next;
- win != rp_mapped_window_sentinel;
- win = win->next)
- {
- if (win->frame == frame)
- hide_window (win);
- }
- }
- free (frame);
+ if (win->frame == frame)
+ hide_window (win);
}
- create_initial_frame (s);
-
- /* Maximize all the windows that were in the current frame. */
- for (win = rp_mapped_window_sentinel->next;
- win != rp_mapped_window_sentinel;
- win = win->next)
+ /* Delete all the frames except the current one. */
+ list_for_each_safe_entry (frame, iter, tmp, &s->rp_window_frames, node)
{
- if (win->frame == cur_frame)
+ if (frame != s->rp_current_frame)
{
- set_frames_window (win->scr->rp_current_frame, win);
- maximize (win);
+ list_del (&frame->node);
+ free (frame);
}
}
- set_frames_window (s->rp_current_frame, cur_window);
+ /* Maximize the frame and the windows in the frame. */
+ maximize_frame (s->rp_current_frame);
+ maximize_all_windows_in_frame (s->rp_current_frame);
}
/* Shrink the size of the frame to fit it's current window. */
@@ -450,9 +387,7 @@ resize_frame_vertically (rp_window_frame *frame, int diff)
orig_y = frame->y;
/* Look for frames below that needs to be resized. */
- for (cur = s->rp_window_frame_sentinel->next;
- cur != s->rp_window_frame_sentinel;
- cur = cur->next)
+ list_for_each_entry (cur, &s->rp_window_frames, node)
{
if (cur->y == (frame->y + frame->height)
&& (cur->x + cur->width) > frame->x
@@ -477,9 +412,7 @@ resize_frame_vertically (rp_window_frame *frame, int diff)
/* Found no frames below, look for some above. */
if (!found_adjacent_frames)
{
- for (cur = s->rp_window_frame_sentinel->next;
- cur != s->rp_window_frame_sentinel;
- cur = cur->next)
+ list_for_each_entry (cur, &s->rp_window_frames, node)
{
if (cur->y == (frame->y - cur->height)
&& (cur->x + cur->width) > frame->x
@@ -513,9 +446,7 @@ resize_frame_vertically (rp_window_frame *frame, int diff)
frame->height += diff;
/* If we left any gaps, take care of them too. */
- for (cur = s->rp_window_frame_sentinel->next;
- cur != s->rp_window_frame_sentinel;
- cur = cur->next)
+ list_for_each_entry (cur, &s->rp_window_frames, node)
{
if (cur->y == orig_y && cur->x >= min_bound
&& cur->x + cur->width <= max_bound
@@ -556,9 +487,7 @@ resize_frame_horizontally (rp_window_frame *frame, int diff)
orig_x = frame->x;
/* Look for frames on the right that needs to be resized. */
- for (cur = s->rp_window_frame_sentinel->next;
- cur != s->rp_window_frame_sentinel;
- cur = cur->next)
+ list_for_each_entry (cur, &s->rp_window_frames, node)
{
if (cur->x == (frame->x + frame->width)
&& (cur->y + cur->height) > frame->y
@@ -583,9 +512,7 @@ resize_frame_horizontally (rp_window_frame *frame, int diff)
/* Found no frames to the right, look for some to the left. */
if (!found_adjacent_frames)
{
- for (cur = s->rp_window_frame_sentinel->next;
- cur != s->rp_window_frame_sentinel;
- cur = cur->next)
+ list_for_each_entry (cur, &s->rp_window_frames, node)
{
if (cur->x == (frame->x - cur->width)
&& (cur->y + cur->height) > frame->y
@@ -619,9 +546,7 @@ resize_frame_horizontally (rp_window_frame *frame, int diff)
frame->width += diff;
/* If we left any gaps, take care of them too. */
- for (cur = s->rp_window_frame_sentinel->next;
- cur != s->rp_window_frame_sentinel;
- cur = cur->next)
+ list_for_each_entry (cur, &s->rp_window_frames, node)
{
if (cur->x == orig_x && cur->y >= min_bound
&& cur->y + cur->height <= max_bound
@@ -677,9 +602,7 @@ total_frame_area (screen_info *s)
int area = 0;
rp_window_frame *cur;
- for (cur = s->rp_window_frame_sentinel->next;
- cur != s->rp_window_frame_sentinel;
- cur = cur->next)
+ list_for_each_entry (cur, &s->rp_window_frames, node)
{
area += cur->width * cur->height;
}
@@ -710,9 +633,7 @@ frame_overlaps (rp_window_frame *frame)
s = frames_screen (frame);
- for (cur = s->rp_window_frame_sentinel->next;
- cur != s->rp_window_frame_sentinel;
- cur = cur->next)
+ list_for_each_entry (cur, &s->rp_window_frames, node)
{
if (cur != frame && frames_overlap (cur, frame))
{
@@ -736,13 +657,11 @@ remove_frame (rp_window_frame *frame)
area = total_frame_area(s);
PRINT_DEBUG ("Total Area: %d\n", area);
- delete_frame_from_list (frame);
+ list_del (&frame->node);
hide_window (frame->win);
hide_others (frame->win);
- for (cur = s->rp_window_frame_sentinel->next;
- cur != s->rp_window_frame_sentinel;
- cur = cur->next)
+ list_for_each_entry (cur, &s->rp_window_frames, node)
{
rp_window_frame tmp_frame;
int fits = 0;
@@ -926,9 +845,7 @@ find_frame_up (rp_window_frame *frame)
screen_info *s = frames_screen (frame);
rp_window_frame *cur;
- for (cur = s->rp_window_frame_sentinel->next;
- cur != s->rp_window_frame_sentinel;
- cur = cur->next)
+ list_for_each_entry (cur, &s->rp_window_frames, node)
{
if (frame->y == cur->y + cur->height)
{
@@ -946,9 +863,7 @@ find_frame_down (rp_window_frame *frame)
screen_info *s = frames_screen (frame);
rp_window_frame *cur;
- for (cur = s->rp_window_frame_sentinel->next;
- cur != s->rp_window_frame_sentinel;
- cur = cur->next)
+ list_for_each_entry (cur, &s->rp_window_frames, node)
{
if (frame->y + frame->height == cur->y)
{
@@ -966,9 +881,7 @@ find_frame_left (rp_window_frame *frame)
screen_info *s = frames_screen (frame);
rp_window_frame *cur;
- for (cur = s->rp_window_frame_sentinel->next;
- cur != s->rp_window_frame_sentinel;
- cur = cur->next)
+ list_for_each_entry (cur, &s->rp_window_frames, node)
{
if (frame->x == cur->x + cur->width)
{
@@ -986,9 +899,7 @@ find_frame_right (rp_window_frame *frame)
screen_info *s = frames_screen (frame);
rp_window_frame *cur;
- for (cur = s->rp_window_frame_sentinel->next;
- cur != s->rp_window_frame_sentinel;
- cur = cur->next)
+ list_for_each_entry (cur, &s->rp_window_frames, node)
{
if (frame->x + frame->width == cur->x)
{