[hackers] [wmii] Cleanup.

From: Kris Maglione <jg_AT_suckless.org>
Date: Sat Apr 14 14:09:36 2007

changeset: 2074:a6624d17ef24
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Sat Apr 14 08:06:23 2007 -0400
summary: Cleanup.

diff -r 9a8fddb687bf -r a6624d17ef24 cmd/wmii/column.c
--- a/cmd/wmii/column.c Sat Apr 14 04:41:15 2007 -0400
+++ b/cmd/wmii/column.c Sat Apr 14 08:06:23 2007 -0400
@@ -2,7 +2,9 @@
  * Copyright ©2006-2007 Kris Maglione <fbsdaemon_AT_gmail.com>
  * See LICENSE file for license details.
  */
+#include <assert.h>
 #include <math.h>
+#include <stdio.h>
 #include <string.h>
 #include <X11/extensions/shape.h>
 #include <util.h>
@@ -342,6 +344,7 @@ arrange_column(Area *a, Bool dirty) {
                 }
                 goto resize;
         default:
+ assert(!"Can't happen");
                 break;
         }
         scale_column(a);
@@ -359,119 +362,112 @@ resize:
         }
 }
 
-static void
-match_horiz(Area *a, XRectangle *r) {
- Frame *f;
-
- for(f=a->frame; f; f=f->anext) {
- f->rect.x = r->x;
- f->rect.width = r->width;
- resize_frame(f, &f->rect);
- }
-}
-
-void
-resize_column(Frame *f, XRectangle *new) {
- Area *west, *east, *a;
- Frame *north, *south;
+void
+resize_column(Area *a, int w) {
+ Area *an;
+ int dw;
+
+ an = a->next;
+ assert(an != nil);
+
+ dw = w - a->rect.width;
+ a->rect.width += dw;
+ an->rect.width -= dw;
+
+ arrange_view(a->view);
+ focus_view(screen, a->view);
+}
+
+static void
+resize_colframeh(Frame *f, XRectangle *r) {
+ Area *a;
+ Frame *fa, *fb;
+ uint minh;
+ int dy, dh, maxy;
+
+ a = f->area;
+ maxy = r_south(r);
+
+ minh = 2 * labelh(&def.font);
+
+ fa = f->anext;
+ for(fb = a->frame; fb; fb = fb->anext)
+ if(fb->anext == f) break;
+
+ if(fb)
+ r->y = max(r->y, fb->rect.y + minh);
+ else
+ r->y = a->rect.y;
+
+ if(fa) {
+ if(maxy > r_south(&fa->rect) - minh)
+ maxy = r_south(&fa->rect) - minh;
+ }
+ else
+ if(r_south(r) >= r_south(&a->rect))
+ maxy = r_south(&a->rect) - 1;
+
+ dy = f->rect.y - r->y;
+ dh = maxy - r_south(&f->rect);
+ if(fb) {
+ fb->rect.height -= dy;
+ resize_frame(fb, &fb->rect);
+ }
+ if(fa) {
+ fa->rect.height -= dh;
+ resize_frame(fa, &fa->rect);
+ }
+
+ f->rect.height = maxy - r->y;
+ resize_frame(f, &f->rect);
+}
+
+void
+resize_colframe(Frame *f, XRectangle *r) {
+ Area *a, *al, *ar;
         View *v;
- BlitzAlign sticky;
- uint min_height;
- uint min_width;
+ uint minw;
+ int dx, dw, maxx;
 
         a = f->area;
         v = a->view;
- min_height = 2 * labelh(&def.font);
- min_width = screen->rect.width/NCOL;
-
- for(west=v->area->next; west; west=west->next)
- if(west->next == a) break;
- east = a->next;
- for(north=a->frame; north; north=north->anext)
- if(north->anext == f) break;
- south = f->anext;
- /* validate (and trim if necessary) horizontal resize */
- sticky = get_sticky(&f->rect, new);
- if(new->width < min_width) {
- if(sticky & EAST)
- new->x = r_east(&a->rect) - min_width;
- new->width = min_width;
- }
- if(west && !(sticky & WEST)) {
- if(new->x < 0 || new->x < (west->rect.x + min_width)) {
- new->width -= (west->rect.x + min_width) - new->x;
- new->x = west->rect.x + min_width;
- }
- } else {
- new->width += new->x - a->rect.x;
- new->x = a->rect.x;
- }
- if(east && !(sticky & EAST)) {
- if(r_east(new) > r_east(&east->rect) - min_width)
- new->width = r_east(&east->rect) - min_width - new->x;
- } else
- new->width = r_east(&a->rect) - new->x;
- if(new->width < min_width)
- goto AfterHorizontal;
- /* horizontal resize */
- sticky = get_sticky(&a->rect, new);
- if(west && !(sticky & WEST)) {
- west->rect.width = new->x - west->rect.x;
- a->rect.width += a->rect.x - new->x;
- a->rect.x = new->x;
- match_horiz(a, &a->rect);
- match_horiz(west, &west->rect);
- //relax_column(west);
- }
- if(east && !(sticky & EAST)) {
- east->rect.width -= r_east(new) - east->rect.x;
- east->rect.x = r_east(new);
- a->rect.width = r_east(new) - a->rect.x;
- match_horiz(a, &a->rect);
- match_horiz(east, &east->rect);
- }
-AfterHorizontal:
- /* skip vertical resize unless the column is in equal mode */
- if(a->mode != Coldefault)
- goto AfterVertical;
- /* validate (and trim if necessary) vertical resize */
- sticky = get_sticky(&f->rect, new);
- if(new->height < min_height) {
- if((f->rect.height < min_height) && sticky & (NORTH|SOUTH))
- goto AfterVertical;
- if(sticky & SOUTH)
- new->y = r_south(&f->rect) - min_height;
- new->height = min_height;
- }
- if(north && !(sticky & NORTH))
- if(new->y < 0 || new->y < (north->rect.y + min_height)) {
- new->height -= (north->rect.y + min_height) - new->y;
- new->y = north->rect.y + min_height;
- }
- if(south && !(sticky & SOUTH)) {
- if(r_south(new) > r_south(&south->rect) - min_height)
- new->height = r_south(&south->rect) - min_height - new->y;
- }
- if(new->height < min_height)
- goto AfterVertical;
- /* vertical resize */
- if(north && !(sticky & NORTH)) {
- north->rect.height = new->y - north->rect.y;
- f->rect.height += f->rect.y - new->y;
- f->rect.y = new->y;
- resize_frame(north, &north->rect);
- resize_frame(f, &f->rect);
- }
- if(south && !(sticky & SOUTH)) {
- south->rect.height -= r_south(new) - south->rect.y;
- south->rect.y = r_south(new);
- f->rect.y = new->y;
- f->rect.height = new->height;
- resize_frame(f, &f->rect);
- resize_frame(south, &south->rect);
- }
-AfterVertical:
- arrange_column(a, False);
+ maxx = r_east(r);
+
+ minw = screen->rect.width/NCOL;
+
+ ar = a->next;
+ for(al = v->area->next; al; al = al->next)
+ if(al->next == a) break;
+
+ if(al)
+ r->x = max(r->x, al->rect.x + minw);
+ else
+ r->x = max(r->x, 0);
+
+ if(ar) {
+ if(maxx >= r_east(&ar->rect) - minw)
+ maxx = r_east(&ar->rect) - minw;
+ }
+ else
+ if(maxx > screen->rect.width)
+ maxx = screen->rect.width - 1;
+
+ dx = a->rect.x - r->x;
+ dw = maxx - r_east(&a->rect);
+ if(dx) {
+ al->rect.width -= dx;
+ arrange_column(al, False);
+ }
+ if(dw) {
+ ar->rect.width -= dw;
+ arrange_column(ar, False);
+ }
+
+ resize_colframeh(f, r);
+
+ a->rect.width = maxx - r->x;
+ arrange_view(a->view);
+
         focus_view(screen, v);
 }
 
diff -r 9a8fddb687bf -r a6624d17ef24 cmd/wmii/fns.h
--- a/cmd/wmii/fns.h Sat Apr 14 04:41:15 2007 -0400
+++ b/cmd/wmii/fns.h Sat Apr 14 08:06:23 2007 -0400
@@ -6,163 +6,164 @@ char *message_root(char *message);
 char *message_root(char *message);
 
 /* area.c */
-Area *create_area(View *v, Area *pos, uint w);
-void destroy_area(Area *a);
-Area *area_of_id(View *t, ushort id);
-void focus_area(Area *a);
-char *select_area(Area *a, char *arg);
-void send_to_area(Area *to, Frame *f);
-void attach_to_area(Area *a, Frame *f, Bool send);
-void detach_from_area(Frame *f);
-Client *area_selclient(Area *a);
+Area *create_area(View*, Area *pos, uint w);
+void destroy_area(Area*);
+Area *area_of_id(View*, ushort id);
+void focus_area(Area*);
+char *select_area(Area*, char *arg);
+void send_to_area(Area*, Frame*);
+void attach_to_area(Area*, Frame*, Bool send);
+void detach_from_area(Frame*);
+Client *area_selclient(Area*);
 
 /* bar.c */
 Bar *create_bar(Bar **b_link, char *name);
-void destroy_bar(Bar **b_link, Bar *b);
+void destroy_bar(Bar **b_link, Bar*);
 void draw_bar(WMScreen *s);
-void draw_border(BlitzBrush *b);
+void draw_border(BlitzBrush*);
 void resize_bar();
 Bar *bar_of_name(Bar *b_link, const char *name);
 
 /* client.c */
-Client *create_client(Window w, XWindowAttributes *wa);
-void destroy_client(Client *c);
-void configure_client(Client *c);
-void prop_client(Client *c, Atom a);
-void kill_client(Client *c);
-void gravitate_client(Client *c, Bool invert);
-void map_client(Client *c);
-void unmap_client(Client *c, int state);
-void map_frame(Client *c);
-void unmap_frame(Client *c);
-void set_cursor(Client *c, Cursor cur);
-void focus_frame(Frame *f, Bool restack);
-void reparent_client(Client *c, Window w, int x, int y);
-void manage_client(Client *c);
-void focus(Client *c, Bool restack);
-void focus_client(Client *c);
-void resize_client(Client *c, XRectangle *r);
-void apply_sizehints(Client *c, XRectangle *r, Bool floating, Bool frame, BlitzAlign sticky);
-char *send_client(Frame *f, char *arg, Bool swap);
-char * message_client(Client *c, char *message);
-void move_client(Client *c, char *arg);
-void size_client(Client *c, char *arg);
+Client *create_client(Window, XWindowAttributes*);
+void destroy_client(Client*);
+void configure_client(Client*);
+void prop_client(Client *c, Atom);
+void kill_client(Client*);
+void gravitate_client(Client*, Bool invert);
+void map_client(Client*);
+void unmap_client(Client*, int state);
+void map_frame(Client*);
+void unmap_frame(Client*);
+void set_cursor(Client*, Cursor cur);
+void focus_frame(Frame*, Bool restack);
+void reparent_client(Client*, Window w, int x, int y);
+void manage_client(Client*);
+void focus(Client*, Bool restack);
+void focus_client(Client*);
+void resize_client(Client*, XRectangle*);
+void apply_sizehints(Client*, XRectangle*, Bool floating, Bool frame, BlitzAlign sticky);
+char *send_client(Frame*, char*, Bool swap);
+char * message_client(Client*, char*);
+void move_client(Client*, char *arg);
+void size_client(Client*, char *arg);
 Client *selclient();
-Frame *win2frame(Window w);
-Client *win2client(Window w);
-void update_client_grab(Client *c);
-void apply_rules(Client *c);
-void apply_tags(Client *c, const char *tags);
+Frame *win2frame(Window);
+Client *win2client(Window);
+void update_client_grab(Client*);
+void apply_rules(Client*);
+void apply_tags(Client*, const char*);
 
 /* column.c */
-Divide *win2div(Window w);
+Divide *win2div(Window);
 void update_dividers();
 void update_divs();
-void draw_div(Divide *d);
-void arrange_column(Area *a, Bool dirty);
-void resize_column(Frame *f, XRectangle *r);
+void draw_div(Divide*);
+void arrange_column(Area*, Bool dirty);
+void resize_column(Area*, int w);
+void resize_colframe(Frame*, XRectangle*);
 int str2colmode(const char *str);
-Area *new_column(View *v, Area *pos, uint w);
+Area *new_column(View*, Area *pos, uint w);
 
 /* draw.c */
-int loadcolor(Blitz *blitz, BlitzColor *c);
-void draw_label(BlitzBrush *b, char *text);
-void draw_tile(BlitzBrush *b);
-void draw_rect(BlitzBrush *b);
+int loadcolor(Blitz *, BlitzColor *);
+void draw_label(BlitzBrush *, char *text);
+void draw_tile(BlitzBrush *);
+void draw_rect(BlitzBrush *);
 
-void drawbg(Display *dpy, Drawable drawable, GC gc,
- XRectangle *rect, BlitzColor c, Bool fill, Bool border);
-void drawcursor(Display *dpy, Drawable drawable, GC gc,
- int x, int y, uint h, BlitzColor c);
-uint textwidth(BlitzFont *font, char *text);
-uint textwidth_l(BlitzFont *font, char *text, uint len);
-void loadfont(Blitz *blitz, BlitzFont *font);
+void drawbg(Display*, Drawable, GC,
+ XRectangle*, BlitzColor, Bool fill, Bool border);
+void drawcursor(Display*, Drawable, GC,
+ int x, int y, uint h, BlitzColor);
+uint textwidth(BlitzFont*, char *text);
+uint textwidth_l(BlitzFont*, char *text, uint len);
+void loadfont(Blitz*, BlitzFont*);
 uint labelh(BlitzFont *font);
-char *parse_colors(char **buf, int *buflen, BlitzColor *col);
+char *parse_colors(char **buf, int *buflen, BlitzColor*);
 
 /* event.c */
-void dispatch_event(XEvent *e);
-void check_x_event(IxpConn *c);
+void dispatch_event(XEvent*);
+void check_x_event(IxpConn*);
 uint flushevents(long even_mask, Bool dispatch);
 
 /* frame.c */
-Frame *create_frame(Client *c, View *v);
-void remove_frame(Frame *f);
-void insert_frame(Frame *pos, Frame *f, Bool before);
-void resize_frame(Frame *f, XRectangle *r);
+Frame *create_frame(Client*, View*);
+void remove_frame(Frame*);
+void insert_frame(Frame *pos, Frame*, Bool before);
+void resize_frame(Frame*, XRectangle*);
 Bool frame_to_top(Frame *f);
-void set_frame_cursor(Frame *f, int x, int y);
-void swap_frames(Frame *fa, Frame *fb);
+void set_frame_cursor(Frame*, int x, int y);
+void swap_frames(Frame*, Frame*);
 int frame_delta_h();
-void frame2client(Frame *f, XRectangle *r);
-void client2frame(Frame *f, XRectangle *r);
-int ingrabbox(Frame *f, int x, int y);
-void draw_frame(Frame *f);
+void frame2client(Frame*, XRectangle*);
+void client2frame(Frame*, XRectangle*);
+int ingrabbox(Frame*, int x, int y);
+void draw_frame(Frame*);
 void draw_frames();
-void update_frame_widget_colors(Frame *f);
-void check_frame_constraints(XRectangle *rect);
+void update_frame_widget_colors(Frame*);
+void check_frame_constraints(XRectangle*);
 
 /* fs.c */
-void fs_attach(Ixp9Req *r);
-void fs_clunk(Ixp9Req *r);
-void fs_create(Ixp9Req *r);
-void fs_flush(Ixp9Req *r);
-void fs_freefid(Fid *f);
-void fs_open(Ixp9Req *r);
-void fs_read(Ixp9Req *r);
-void fs_remove(Ixp9Req *r);
-void fs_stat(Ixp9Req *r);
-void fs_walk(Ixp9Req *r);
-void fs_write(Ixp9Req *r);
-void write_event(char *format, ...);
+void fs_attach(Ixp9Req*);
+void fs_clunk(Ixp9Req*);
+void fs_create(Ixp9Req*);
+void fs_flush(Ixp9Req*);
+void fs_freefid(Fid*);
+void fs_open(Ixp9Req*);
+void fs_read(Ixp9Req*);
+void fs_remove(Ixp9Req*);
+void fs_stat(Ixp9Req*);
+void fs_walk(Ixp9Req*);
+void fs_write(Ixp9Req*);
+void write_event(char*, ...);
 
 /* geom.c */
-Bool ptinrect(int x, int y, XRectangle * r);
-BlitzAlign quadrant(XRectangle *rect, int x, int y);
-Cursor cursor_of_quad(BlitzAlign align);
-int strtorect(XRectangle *r, const char *val);
+Bool ptinrect(int x, int y, XRectangle*);
+BlitzAlign quadrant(XRectangle*, int x, int y);
+Cursor cursor_of_quad(BlitzAlign);
+int strtorect(XRectangle*, const char*);
 BlitzAlign get_sticky(XRectangle *src, XRectangle *dst);
-int r_east(XRectangle *r);
-int r_south(XRectangle *r);
+int r_east(XRectangle*);
+int r_south(XRectangle*);
 
 /* key.c */
-void kpress(Window w, ulong mod, KeyCode keycode);
+void kpress(Window, ulong mod, KeyCode);
 void update_keys();
 void init_lock_keys();
-ulong mod_key_of_str(char *val);
+ulong mod_key_of_str(char*);
 
 /* mouse.c */
-void mouse_resizecol(Divide *d);
-void do_mouse_resize(Client *c, Bool grabbox, BlitzAlign align);
-void grab_mouse(Window w, ulong mod, ulong button);
-void ungrab_mouse(Window w, ulong mod, uint button);
+void mouse_resizecol(Divide*);
+void do_mouse_resize(Client*, Bool opaque, BlitzAlign);
+void grab_mouse(Window, ulong mod, ulong button);
+void ungrab_mouse(Window, ulong mod, uint button);
 BlitzAlign snap_rect(XRectangle *rects, int num, XRectangle *current,
- BlitzAlign *mask, int snap);
-void grab_button(Window w, uint button, ulong mod);
+ BlitzAlign *mask, int snapw);
+void grab_button(Window, uint button, ulong mod);
 
 /* rule.c */
-void update_rules(Rule **rule, const char *data);
+void update_rules(Rule**, const char*);
 void trim(char *str, const char *chars);
 
 /* view.c */
-void arrange_view(View *v);
-void scale_view(View *v, float w);
-View *get_view(const char *name);
-View *create_view(const char *name);
-void focus_view(WMScreen *s, View *v);
-void update_client_views(Client *c, char **tags);
-XRectangle *rects_of_view(View *v, uint *num, Frame *ignore);
-View *view_of_id(ushort id);
-void select_view(const char *arg);
-void attach_to_view(View *v, Frame *f);
-Client *view_selclient(View *v);
-char *message_view(View *v, char *message);
-void restack_view(View *v);
-uchar *view_index(View *v);
-void destroy_view(View *v);
+void arrange_view(View*);
+void scale_view(View*, float w);
+View *get_view(const char*);
+View *create_view(const char*);
+void focus_view(WMScreen*, View*);
+void update_client_views(Client*, char**);
+XRectangle *rects_of_view(View*, uint *num, Frame *ignore);
+View *view_of_id(ushort);
+void select_view(const char*);
+void attach_to_view(View*, Frame*);
+Client *view_selclient(View*);
+char *message_view(View*, char*);
+void restack_view(View*);
+uchar *view_index(View*);
+void destroy_view(View*);
 void update_views();
-uint newcolw_of_view(View *v, int i);
+uint newcolw_of_view(View*, int i);
 
 /* wm.c */
-int wmii_error_handler(Display *dpy, XErrorEvent *error);
-int win_proto(Window w);
+int wmii_error_handler(Display*, XErrorEvent *error);
+int win_proto(Window);
diff -r 9a8fddb687bf -r a6624d17ef24 cmd/wmii/mouse.c
--- a/cmd/wmii/mouse.c Sat Apr 14 04:41:15 2007 -0400
+++ b/cmd/wmii/mouse.c Sat Apr 14 08:06:23 2007 -0400
@@ -357,7 +357,6 @@ mouse_resizecol(Divide *d) {
         XSetWindowAttributes wa;
         XEvent ev;
         Window cwin;
- XRectangle r;
         Divide *dp;
         View *v;
         Area *a;
@@ -406,9 +405,7 @@ mouse_resizecol(Divide *d) {
                 XMaskEvent(blz.dpy, MouseMask | ExposureMask, &ev);
                 switch (ev.type) {
                 case ButtonRelease:
- r = a->rect;
- r.width = x - r.x;
- resize_column(a->frame, &r);
+ resize_column(a, x - a->rect.x);
 
                         XUngrabPointer(blz.dpy, CurrentTime);
                         XSync(blz.dpy, False);
@@ -526,7 +523,7 @@ do_mouse_resize(Client *c, Bool opaque,
                                 xorborder(&frect);
 
                         if(!floating)
- resize_column(c->sel, &frect);
+ resize_colframe(f, &frect);
                         else
                                 resize_client(c, &frect);
 
Received on Sat Apr 14 2007 - 14:09:36 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:56:39 UTC