Skip to content

Commit

Permalink
remove excess code
Browse files Browse the repository at this point in the history
  • Loading branch information
seanpringle committed Aug 29, 2012
1 parent 09e6368 commit 38ec14d
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 50 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -8,7 +8,7 @@ debug:
$(CC) -o goomwwm-debug goomwwm.c $(CFLAGS) -g -DDEBUG $(LDADD)

proto:
cat *.c | egrep '^(void|int|char|unsigned|client|Window|winlist|textbox|XWindow)' | sed -r 's/\)/);/' > proto.h
cat *.c | egrep '^(void|int|char|unsigned|client|Window|winlist|box|textbox|XWindow)' | sed -r 's/\)/);/' > proto.h

docs:
pandoc -s -w man goomwwm.md -o goomwwm.1
Expand Down
10 changes: 8 additions & 2 deletions box.c
Expand Up @@ -31,11 +31,17 @@ box* box_create(Window parent, bitmap flags, short x, short y, short w, short h,

b->flags = flags;
b->parent = parent;
box_color(b, color);

b->window = XCreateSimpleWindow(display, b->parent, 0, 0, 1, 1, 0, None, b->color);

b->window = XCreateSimpleWindow(display, b->parent, 0, 0, 1, 1, 0, None, None);
if (b->flags & BOX_OVERRIDE)
{
XSetWindowAttributes attr; attr.override_redirect = True;
XChangeWindowAttributes(display, b->window, CWOverrideRedirect, &attr);
}

box_moveresize(b, x, y, w, h);
box_color(b, color);

return b;
}
Expand Down
18 changes: 8 additions & 10 deletions client.c
Expand Up @@ -1046,19 +1046,17 @@ void client_flash(client *c, char *color, int delay, int title)
message_box(delay, c->x+c->w/2, c->y+c->h/2, config_title_fg, config_title_bg, config_title_bc, c->title);

// four coloured squares in the window's corners
unsigned int bg = color_get(color);
Window tl = window_create_override(x1, y1, config_flash_width, config_flash_width, bg);
Window tr = window_create_override(x2, y1, config_flash_width, config_flash_width, bg);
Window bl = window_create_override(x1, y2, config_flash_width, config_flash_width, bg);
Window br = window_create_override(x2, y2, config_flash_width, config_flash_width, bg);
box *tl = box_create(root, BOX_OVERRIDE, x1, y1, config_flash_width, config_flash_width, color);
box *tr = box_create(root, BOX_OVERRIDE, x2, y1, config_flash_width, config_flash_width, color);
box *bl = box_create(root, BOX_OVERRIDE, x1, y2, config_flash_width, config_flash_width, color);
box *br = box_create(root, BOX_OVERRIDE, x2, y2, config_flash_width, config_flash_width, color);

XMapRaised(display, tl); XMapRaised(display, tr);
XMapRaised(display, bl); XMapRaised(display, br);
box_show(tl); box_show(tr); box_show(bl); box_show(br);

XSync(display, False); usleep(delay*1000);
XSync(display, False);
usleep(delay*1000);

XDestroyWindow(display, tl); XDestroyWindow(display, tr);
XDestroyWindow(display, bl); XDestroyWindow(display, br);
box_free(tl); box_free(tr); box_free(bl); box_free(br);

exit(EXIT_SUCCESS);
}
Expand Down
4 changes: 3 additions & 1 deletion goomwwm.h
Expand Up @@ -51,6 +51,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
typedef unsigned char bool;
typedef unsigned long long bitmap;

#define BOX_OVERRIDE 1<<0

typedef struct {
bitmap flags;
Window window, parent;
Expand Down Expand Up @@ -533,7 +535,7 @@ Time latest = CurrentTime;
struct mouse_drag {
XButtonEvent button;
XWindowAttributes attr;
Window overlay;
box *overlay;
short x, y, w, h;
unsigned int flags;
};
Expand Down
11 changes: 6 additions & 5 deletions handle.c
Expand Up @@ -370,11 +370,11 @@ void handle_buttonpress(XEvent *ev)
take_pointer(c->window, PointerMotionMask|ButtonReleaseMask, None);

mouse_dragger = allocate_clear(sizeof(struct mouse_drag));
mouse_dragger->overlay = window_create(c->x, c->y, c->w, c->h, color_get(config_border_blur));
mouse_dragger->overlay = box_create(root, BOX_OVERRIDE, c->x, c->y, c->w, c->h, config_border_blur);

unsigned long opacity = 0xffffffff / 2;
// no map yet, see motionnotify
window_set_cardinal_prop(mouse_dragger->overlay, netatoms[_NET_WM_WINDOW_OPACITY], &opacity, 1);
window_set_cardinal_prop(mouse_dragger->overlay->window, netatoms[_NET_WM_WINDOW_OPACITY], &opacity, 1);

memcpy(&mouse_dragger->attr, &c->xattr, sizeof(c->xattr));
memcpy(&mouse_dragger->button, &ev->xbutton, sizeof(ev->xbutton));
Expand Down Expand Up @@ -430,7 +430,7 @@ void handle_buttonrelease(XEvent *ev)
}

release_pointer();
XDestroyWindow(display, mouse_dragger->overlay);
box_free(mouse_dragger->overlay);
free(mouse_dragger);
mouse_dragger = NULL;

Expand All @@ -452,7 +452,8 @@ void handle_motionnotify(XEvent *ev)
client *c = client_create(ev->xmotion.window);
if (c && c->manage && mouse_dragger)
{
XMapRaised(display, mouse_dragger->overlay);
box_show(mouse_dragger->overlay);

client_extended_data(c);
int xd = ev->xbutton.x_root - mouse_dragger->button.x_root;
int yd = ev->xbutton.y_root - mouse_dragger->button.y_root;
Expand All @@ -477,7 +478,7 @@ void handle_motionnotify(XEvent *ev)
mouse_dragger->h = h;

//XMoveResizeWindow(display, mouse_dragger->overlay, x, y, w, h);
client_moveresize(client_create(mouse_dragger->overlay), mouse_dragger->flags, x, y, w, h);
client_moveresize(client_create(mouse_dragger->overlay->window), mouse_dragger->flags, x, y, w, h);
}
}

Expand Down
3 changes: 1 addition & 2 deletions proto.h
@@ -1,3 +1,4 @@
box* box_create(Window parent, bitmap flags, short x, short y, short w, short h, char *color);
void box_color(box *b, char *color);
void box_moveresize(box *b, short x, short y, short w, short h);
void box_show(box *b);
Expand Down Expand Up @@ -178,8 +179,6 @@ int take_pointer(Window w, unsigned long mask, Cursor cur);
void release_keyboard();
void release_pointer();
void message_box(int delay, int x, int y, char *fgc, char *bgc, char *bc, char *txt);
Window window_create_override(int x, int y, int w, int h, unsigned int color);
Window window_create(int x, int y, int w, int h, unsigned int color);
void notice(const char *fmt, ...);
void notification(int delay, const char *fmt, ...);
void event_log(const char *e, Window w);
Expand Down
36 changes: 7 additions & 29 deletions util.c
Expand Up @@ -222,20 +222,20 @@ void message_box(int delay, int x, int y, char *fgc, char *bgc, char *bc, char *

display = XOpenDisplay(0x0);

Window box = window_create_override(0, 0, 1, 1, color_get(config_title_bg));
box *b = box_create(root, BOX_OVERRIDE, 0, 0, 1, 1, config_title_bg);

textbox *text = textbox_create(box, TB_CENTER|TB_AUTOHEIGHT|TB_AUTOWIDTH,
textbox *text = textbox_create(b->window, TB_CENTER|TB_AUTOHEIGHT|TB_AUTOWIDTH,
8, 5, 1, 1, config_title_font, config_title_fg, config_title_bg, txt, NULL);

XMoveResizeWindow(display, box,
box_moveresize(b,
MIN(mon.x+mon.w-text->w-26, MAX(mon.x+26, x - text->w/2)),
MIN(mon.y+mon.h-text->h-20, MAX(mon.y+20, y - text->h/2)),
text->w + 16, text->h + 10);

XSelectInput(display, box, ExposureMask);
XSelectInput(display, b->window, ExposureMask);

textbox_show(text);
XMapRaised(display, box);
box_show(b);

double stamp = timestamp();
while ((timestamp()-stamp) < (double)delay/1000)
Expand All @@ -252,31 +252,9 @@ void message_box(int delay, int x, int y, char *fgc, char *bgc, char *bc, char *
}

textbox_free(text);
exit(EXIT_SUCCESS);
}
box_free(b);

// wrapper for XCreateSimpleWindow so we can track our own windows
Window window_create_override(int x, int y, int w, int h, unsigned int color)
{
Window win = XCreateSimpleWindow(display, root, x, y, w, h, 0, None, color);
XSetWindowAttributes attr; attr.override_redirect = True;
XChangeWindowAttributes(display, win, CWOverrideRedirect, &attr);
// pre-create window's cache, so we know it's ours later
wincache *cache = allocate_clear(sizeof(wincache));
winlist_append(windows, win, cache);
cache->is_ours = 1;
return win;
}

// wrapper for XCreateSimpleWindow so we can track our own windows
Window window_create(int x, int y, int w, int h, unsigned int color)
{
Window win = XCreateSimpleWindow(display, root, x, y, w, h, 0, None, color);
// pre-create window's cache, so we know it's ours later
wincache *cache = allocate_clear(sizeof(wincache));
winlist_append(windows, win, cache);
cache->is_ours = 1;
return win;
exit(EXIT_SUCCESS);
}

// bottom right of screen
Expand Down

0 comments on commit 38ec14d

Please sign in to comment.