From: Michael D. Lowis Date: Thu, 1 Aug 2024 21:47:43 +0000 (-0400) Subject: remove unused code in prep to bring it back later... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=0e707481ca1a2acb5b1e88a853631e61a198d4e0;p=proto%2Fanvil.git remove unused code in prep to bring it back later... --- diff --git a/anvil.c b/anvil.c index 58434db..189a5ff 100644 --- a/anvil.c +++ b/anvil.c @@ -63,9 +63,9 @@ XConf X = {0}; /* Anvil State */ int PtrX = 0, PtrY = 0; -int Num_Monitors = 0; -Monitor Monitors[10] = {0}; -Workspace Workspaces[10] = {0}; +//int Num_Monitors = 0; +//Monitor Monitors[10] = {0}; +//Workspace Workspaces[10] = {0}; Client* Withdrawn = NULL; Client* Focused = NULL; @@ -87,43 +87,15 @@ static void xbtnpress(XEvent* e) printf("BTN_DN(w: 0x%lx s: %d x: %d y: %d rx: %d ry: %d)\n", ev->window, ev->state, ev->x, ev->y, ev->x_root, ev->y_root); X.start_x = ev->x_root, X.start_y = ev->y_root; X.last_x = ev->x_root, X.last_y = ev->y_root; -// Location loc = {0}; -// if (mons_find(ev->window, &loc) && (loc.client->frame == ev->window)) -// { -// Client* c = loc.client; -// if (ev->y < MIN_HEIGHT) -// { -// X.edge = E_TOP; -// } -// else if (ev->y_root > (c->y + c->h - BORDER_WIDTH)) -// { -// X.edge = E_BOTTOM; -// } -// else if (ev->x < BORDER_WIDTH) -// { -// X.edge = E_LEFT; -// } -// else if (ev->x_root > (c->x + c->w - BORDER_WIDTH)) -// { -// X.edge = E_RIGHT; -// } -// else -// { -// X.edge = E_NONE; -// } -// mouse_down(ev, &loc); -// } + Mouse_Down(ev); } static void xbtnrelease(XEvent* e) { XButtonEvent* ev = &(e->xbutton); printf("BTN_UP(w: 0x%lx x: %d y: %d rx: %d ry: %d)\n", ev->window, ev->x, ev->y, ev->x_root, ev->y_root); -// Location loc = {0}; -// if (mons_find(ev->window, &loc) && (loc.client->frame == ev->window)) -// { -// mouse_up(ev, &loc); -// } + + Mouse_Up(ev); X.mode = M_IDLE; XUngrabPointer(X.disp, CurrentTime); } @@ -134,11 +106,8 @@ static void xbtnmotion(XEvent* e) XMotionEvent *ev = &e->xmotion; printf("BTN_MV(w: 0x%lx x: %d y: %d rx: %d ry: %d)\n", ev->window, ev->x, ev->y, ev->x_root, ev->y_root); while (XCheckTypedWindowEvent(X.disp, ev->window, ev->type, e)); -// Location loc = {0}; -// if (mons_find(ev->window, &loc) && (loc.client->frame == ev->window)) -// { -// mouse_drag(ev, &loc); -// } + + Mouse_Drag(ev); X.last_x = ev->x_root, X.last_y = ev->y_root; } diff --git a/anvil.h b/anvil.h index 4675ce5..c46dd30 100644 --- a/anvil.h +++ b/anvil.h @@ -86,28 +86,28 @@ typedef struct Client { Visual visual; } Client; -typedef struct Column { - int width; - Client* clients; -} Column; - -typedef struct Workspace { - Client* floating; - Column columns[MAX_COL_COUNT]; - int ncolumns; -} Workspace; - -typedef struct Monitor { - int x, y, w, h, midx, midy; - Workspace* wspace; -} Monitor; - -typedef struct Location { - Monitor* monitor; - Workspace* workspace; - Column* column; - Client* client; -} Location; +//typedef struct Column { +// int width; +// Client* clients; +//} Column; +// +//typedef struct Workspace { +// Client* floating; +// Column columns[MAX_COL_COUNT]; +// int ncolumns; +//} Workspace; +// +//typedef struct Monitor { +// int x, y, w, h, midx, midy; +// Workspace* wspace; +//} Monitor; +// +//typedef struct Location { +// Monitor* monitor; +// Workspace* workspace; +// Column* column; +// Client* client; +//} Location; typedef union { int i; @@ -127,9 +127,9 @@ extern XConf X; extern int PtrX; extern int PtrY; -extern int Num_Monitors; -extern Monitor Monitors[10]; -extern Workspace Workspaces[10]; +//extern int Num_Monitors; +//extern Monitor Monitors[10]; +//extern Workspace Workspaces[10]; extern Client* Withdrawn; extern Client* Focused; @@ -148,24 +148,6 @@ void* list_last(void* list); void Keys_Init(void); void Keys_Process(XKeyEvent* ev); -/* mons.c */ -void mons_init(void); -void mons_layer(Monitor* mon); -void mons_addclient(Client* c); -void mons_delclient(Location* loc); -void mons_togglefloat(Location* loc); -int mons_find(Window win, Location* loc); -void mons_place(Client* c); -void mons_wspace(int i); -void mons_towspace(Client* c, int i); -void mons_raise(Monitor* mon, Client* c); -void mons_lower(Monitor* mon, Client* c); -void mons_colsplit(void); -void mons_coljoin(void); -void mons_coladjust(Monitor* mon, Column* col, int wdiff); -void mons_tilemove(Location* loc, int hdiff); -void mons_activate(Window win); - /* client.c */ void Client_InitAll(void); void Client_Create(Window win); @@ -174,30 +156,25 @@ void Client_Show(Window win); void Client_Hide(Window win); void Client_MoveResize(Client* c); -Client* client_add(Window win, XWindowAttributes* attr); -void client_draw(Client* c); -void client_move(Client* c, int xdiff, int ydiff); -void client_resize(Client* c, int xdiff, int ydiff); -void client_close(Client* c); -void client_focus(Client* c); -void client_show(Client* c, int show); -void client_readprops(Client* c); -void client_shade(Client* c); -void client_setshade(Client* c, int shade); +//Client* client_add(Window win, XWindowAttributes* attr); +//void client_draw(Client* c); +//void client_move(Client* c, int xdiff, int ydiff); +//void client_resize(Client* c, int xdiff, int ydiff); +//void client_close(Client* c); +//void client_focus(Client* c); +//void client_show(Client* c, int show); +//void client_readprops(Client* c); +//void client_shade(Client* c); +//void client_setshade(Client* c, int shade); /* mouse.c */ -void mouse_down(XButtonEvent* ev, Location* loc); -void mouse_up(XButtonEvent* ev, Location* loc); -void mouse_drag(XMotionEvent* ev, Location* loc); -void mouse_tocorner(Client* c); -void mouse_totitle(Client* c); -void mouse_get(int* ptrx, int* ptry); - -/* tile.c */ -void stacked_add(Location* loc); -void stacked_del(Location* loc); -void stacked_set(Location* loc); -void stacked_addheight(Location* loc, int amount); +void Mouse_Down(XButtonEvent* ev); +void Mouse_Up(XButtonEvent* ev); +void Mouse_Drag(XMotionEvent* ev); + +//void mouse_tocorner(Client* c); +//void mouse_totitle(Client* c); +//void mouse_get(int* ptrx, int* ptry); /* error.c */ extern int (*error_default)(Display* disp, XErrorEvent* ev); diff --git a/client.c b/client.c index 50c76e3..2efe912 100644 --- a/client.c +++ b/client.c @@ -305,101 +305,101 @@ void Client_InitAll(void) // } } -Client* client_add(Window win, XWindowAttributes* attr) -{ - Client* c = ecalloc(1, sizeof(Client)); - c->win = win; - c->x = attr->x; - c->y = attr->y; - c->w = attr->width + FRAME_WIDTH_SUM; - c->h = attr->height + FRAME_HEIGHT_SUM; - ReadProps(c); - - /* Reparent the window if applicable */ - c->frame = XCreateSimpleWindow(X.disp, X.root, c->x, c->y, c->w, c->h, 1, X.clr_bdr, X.clr_bg); - XSelectInput(X.disp, c->frame, - ExposureMask | EnterWindowMask | - ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | - SubstructureRedirectMask | SubstructureNotifyMask - ); - XSetWindowAttributes wa; - wa.event_mask = EnterWindowMask | PropertyChangeMask | FocusChangeMask; - wa.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask; - XChangeWindowAttributes(X.disp, c->win, CWEventMask | CWDontPropagate, &wa); - XReparentWindow(X.disp, c->win, c->frame, BORDER_WIDTH, MIN_HEIGHT); - - /* Map the window and draw the frame */ - XAddToSaveSet(X.disp, c->win); -// mons_addclient(c); - client_show(c, 1); - Redraw(c); - return c; -} - - - -void client_move(Client* c, int xdiff, int ydiff) -{ - c->x += xdiff; - c->y += ydiff; - Client_MoveResize(c); -} - -void client_resize(Client* c, int xdiff, int ydiff) -{ - c->w += xdiff; - c->h += ydiff; - Client_MoveResize(c); -} - -void client_close(Client* c) -{ - if (c->flags & F_WM_DELETE) - { - sendmsg(c->win, WM_PROTOCOLS, WM_DELETE_WINDOW); - } - else - { - XKillClient(X.disp, c->win); - } -} - -void client_focus(Client* c) -{ - Client* prev = Focused; - Focused = c; - XSetInputFocus(X.disp, c->win, RevertToPointerRoot, CurrentTime); - Redraw(Focused); - if (prev) - { - Redraw(prev); - } -} - -void client_show(Client* c, int show) -{ - int (*mapfn)(Display*,Window) = (show ? XMapWindow : XUnmapWindow); - mapfn(X.disp, c->frame); - mapfn(X.disp, c->win); -} - - -void client_shade(Client* c) -{ - client_setshade(c, ((c->flags & F_SHADED) ? 0 : 1)); - Client_MoveResize(c); -} - -void client_setshade(Client* c, int shade) -{ - if (!shade && (c->flags & F_SHADED)) - { - c->flags &= ~F_SHADED; - XMapWindow(X.disp, c->win); - } - else if (shade && !(c->flags & F_SHADED)) - { - c->flags |= F_SHADED; - XUnmapWindow(X.disp, c->win); - } -} +//Client* client_add(Window win, XWindowAttributes* attr) +//{ +// Client* c = ecalloc(1, sizeof(Client)); +// c->win = win; +// c->x = attr->x; +// c->y = attr->y; +// c->w = attr->width + FRAME_WIDTH_SUM; +// c->h = attr->height + FRAME_HEIGHT_SUM; +// ReadProps(c); +// +// /* Reparent the window if applicable */ +// c->frame = XCreateSimpleWindow(X.disp, X.root, c->x, c->y, c->w, c->h, 1, X.clr_bdr, X.clr_bg); +// XSelectInput(X.disp, c->frame, +// ExposureMask | EnterWindowMask | +// ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | +// SubstructureRedirectMask | SubstructureNotifyMask +// ); +// XSetWindowAttributes wa; +// wa.event_mask = EnterWindowMask | PropertyChangeMask | FocusChangeMask; +// wa.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask; +// XChangeWindowAttributes(X.disp, c->win, CWEventMask | CWDontPropagate, &wa); +// XReparentWindow(X.disp, c->win, c->frame, BORDER_WIDTH, MIN_HEIGHT); +// +// /* Map the window and draw the frame */ +// XAddToSaveSet(X.disp, c->win); +//// mons_addclient(c); +// client_show(c, 1); +// Redraw(c); +// return c; +//} +// +// +// +//void client_move(Client* c, int xdiff, int ydiff) +//{ +// c->x += xdiff; +// c->y += ydiff; +// Client_MoveResize(c); +//} +// +//void client_resize(Client* c, int xdiff, int ydiff) +//{ +// c->w += xdiff; +// c->h += ydiff; +// Client_MoveResize(c); +//} +// +//void client_close(Client* c) +//{ +// if (c->flags & F_WM_DELETE) +// { +// sendmsg(c->win, WM_PROTOCOLS, WM_DELETE_WINDOW); +// } +// else +// { +// XKillClient(X.disp, c->win); +// } +//} +// +//void client_focus(Client* c) +//{ +// Client* prev = Focused; +// Focused = c; +// XSetInputFocus(X.disp, c->win, RevertToPointerRoot, CurrentTime); +// Redraw(Focused); +// if (prev) +// { +// Redraw(prev); +// } +//} +// +//void client_show(Client* c, int show) +//{ +// int (*mapfn)(Display*,Window) = (show ? XMapWindow : XUnmapWindow); +// mapfn(X.disp, c->frame); +// mapfn(X.disp, c->win); +//} +// +// +//void client_shade(Client* c) +//{ +// client_setshade(c, ((c->flags & F_SHADED) ? 0 : 1)); +// Client_MoveResize(c); +//} +// +//void client_setshade(Client* c, int shade) +//{ +// if (!shade && (c->flags & F_SHADED)) +// { +// c->flags &= ~F_SHADED; +// XMapWindow(X.disp, c->win); +// } +// else if (shade && !(c->flags & F_SHADED)) +// { +// c->flags |= F_SHADED; +// XUnmapWindow(X.disp, c->win); +// } +//} diff --git a/keys.c b/keys.c index 709aa44..96fc186 100644 --- a/keys.c +++ b/keys.c @@ -52,7 +52,7 @@ static void killwin(Arg *arg) (void)arg; if (Focused) { - client_close(Focused); +// client_close(Focused); } } diff --git a/mouse.c b/mouse.c index 6490815..aa73104 100644 --- a/mouse.c +++ b/mouse.c @@ -1,179 +1,235 @@ #include "anvil.h" -static inline int PRESSED(int mods, int btn) -{ - return ((mods & (1 << (btn + 7))) == (1 << (btn + 7))); -} - -static inline int FLAGS_SET(int state, int flags) -{ - return ((!flags && !state) || ((state & flags) == flags)); -} - -typedef struct { - int mods; - int btn; - int type; - void(*func)(Location* loc); -} MouseAct; - -static void resize_frame(Location* loc) -{ - if (X.curr_ev->xbutton.y > MIN_HEIGHT) - { - X.mode = M_RESIZE; - mouse_tocorner(loc->client); - } -} - -static void toggle_float(Location* loc) -{ - (void)loc; -// mons_togglefloat(loc); -} - -static void close_client(Location* loc) -{ - client_close(loc->client); -} - -static void shade_client(Location* loc) -{ - client_shade(loc->client); -} - -static void lower_client(Location* loc) -{ - (void)loc; -// mons_lower(loc->monitor, loc->client); -} - -static void raise_client(Location* loc) -{ - (void)loc; -// mons_raise(loc->monitor, loc->client); -} - -static void stack_clients(Location* loc) -{ - (void)loc; -// stacked_set(loc); -} - -static void reposition_tile(Location* loc) -{ - (void)loc; - X.mode = (X.edge == E_TOP ? M_TILE_RESIZE : M_COL_RESIZE); -} - -MouseAct Floating[] = { - { 0, Button1, ButtonPress, resize_frame }, - { MODKEY|ShiftMask, Button2, ButtonPress, toggle_float }, - { MODKEY, Button2, ButtonPress, close_client }, - { 0, Button3, ButtonPress, shade_client }, - { 0, Button4, ButtonPress, lower_client }, - { 0, Button5, ButtonPress, raise_client } -}; - -MouseAct Stacked[] = { - { 0, Button1, ButtonPress, reposition_tile }, - { MODKEY|ShiftMask, Button2, ButtonPress, toggle_float }, - { MODKEY, Button2, ButtonPress, close_client }, - { 0, Button2, ButtonPress, stack_clients }, - { 0, Button3, ButtonPress, stack_clients }, -}; - -static void process(XButtonEvent* ev, Location* loc, MouseAct* actions, int nactions) -{ - for (int i = 0; i < nactions; i++) - { - MouseAct* act = &actions[i]; - int match = ( - (ev->type == act->type) && - ((int)ev->button == act->btn) && - FLAGS_SET(ev->state, act->mods) - ); - if (match) - { - X.curr_ev = (XEvent*)ev; - act->func(loc); - break; - } - } -} - -void mouse_down(XButtonEvent* ev, Location* loc) -{ - if (!loc->column) - { - process(ev, loc, Floating, sizeof(Floating)/sizeof(Floating[0])); - } - else - { - process(ev, loc, Stacked, sizeof(Stacked)/sizeof(Stacked[0])); - } -} - -static void float_drag(XMotionEvent* ev, Location* loc) -{ - if (PRESSED(ev->state, Button1)) - { - if (X.mode != M_RESIZE) - { - client_move(loc->client, ev->x_root - X.last_x, ev->y_root - X.last_y); - } - else - { - client_resize(loc->client, ev->x_root - X.last_x, ev->y_root - X.last_y); - } - } -} - -void mouse_up(XButtonEvent* ev, Location* loc) +//static inline int PRESSED(int mods, int btn) +//{ +// return ((mods & (1 << (btn + 7))) == (1 << (btn + 7))); +//} +// +//static inline int FLAGS_SET(int state, int flags) +//{ +// return ((!flags && !state) || ((state & flags) == flags)); +//} +// +//typedef struct { +// int mods; +// int btn; +// int type; +// void(*func)(Location* loc); +//} MouseAct; +// +//static void resize_frame(Location* loc) +//{ +// if (X.curr_ev->xbutton.y > MIN_HEIGHT) +// { +// X.mode = M_RESIZE; +// mouse_tocorner(loc->client); +// } +//} +// +//static void toggle_float(Location* loc) +//{ +// (void)loc; +//// mons_togglefloat(loc); +//} +// +//static void close_client(Location* loc) +//{ +// client_close(loc->client); +//} +// +//static void shade_client(Location* loc) +//{ +// client_shade(loc->client); +//} +// +//static void lower_client(Location* loc) +//{ +// (void)loc; +//// mons_lower(loc->monitor, loc->client); +//} +// +//static void raise_client(Location* loc) +//{ +// (void)loc; +//// mons_raise(loc->monitor, loc->client); +//} +// +//static void stack_clients(Location* loc) +//{ +// (void)loc; +//// stacked_set(loc); +//} +// +//static void reposition_tile(Location* loc) +//{ +// (void)loc; +// X.mode = (X.edge == E_TOP ? M_TILE_RESIZE : M_COL_RESIZE); +//} +// +//MouseAct Floating[] = { +// { 0, Button1, ButtonPress, resize_frame }, +// { MODKEY|ShiftMask, Button2, ButtonPress, toggle_float }, +// { MODKEY, Button2, ButtonPress, close_client }, +// { 0, Button3, ButtonPress, shade_client }, +// { 0, Button4, ButtonPress, lower_client }, +// { 0, Button5, ButtonPress, raise_client } +//}; +// +//MouseAct Stacked[] = { +// { 0, Button1, ButtonPress, reposition_tile }, +// { MODKEY|ShiftMask, Button2, ButtonPress, toggle_float }, +// { MODKEY, Button2, ButtonPress, close_client }, +// { 0, Button2, ButtonPress, stack_clients }, +// { 0, Button3, ButtonPress, stack_clients }, +//}; +// +//static void process(XButtonEvent* ev, Location* loc, MouseAct* actions, int nactions) +//{ +// for (int i = 0; i < nactions; i++) +// { +// MouseAct* act = &actions[i]; +// int match = ( +// (ev->type == act->type) && +// ((int)ev->button == act->btn) && +// FLAGS_SET(ev->state, act->mods) +// ); +// if (match) +// { +// X.curr_ev = (XEvent*)ev; +// act->func(loc); +// break; +// } +// } +//} +// +//void mouse_down(XButtonEvent* ev, Location* loc) +//{ +// if (!loc->column) +// { +// process(ev, loc, Floating, sizeof(Floating)/sizeof(Floating[0])); +// } +// else +// { +// process(ev, loc, Stacked, sizeof(Stacked)/sizeof(Stacked[0])); +// } +//} +// +//static void float_drag(XMotionEvent* ev, Location* loc) +//{ +// if (PRESSED(ev->state, Button1)) +// { +// if (X.mode != M_RESIZE) +// { +// client_move(loc->client, ev->x_root - X.last_x, ev->y_root - X.last_y); +// } +// else +// { +// client_resize(loc->client, ev->x_root - X.last_x, ev->y_root - X.last_y); +// } +// } +//} +// +//void mouse_up(XButtonEvent* ev, Location* loc) +//{ +// (void)ev; +// (void)loc; +// if (X.mode == M_TILE_RESIZE) +// { +//// mons_tilemove(loc, ev->y_root - X.start_y); +// } +// else if (X.mode == M_COL_RESIZE) +// { +//// mons_coladjust(loc->monitor, loc->column, ev->x_root - X.start_x); +// } +// else +// { +// /* nothing to do here */ +// } +// X.mode = M_IDLE; +//} +// +//void mouse_drag(XMotionEvent* ev, Location* loc) +//{ +// if (!loc->column) +// { +// float_drag(ev, loc); +// } +//} +// +//void mouse_tocorner(Client* c) +//{ +// int new_w = c->w - BORDER_WIDTH/2; +// int new_h = c->h - BORDER_WIDTH/2; +// XWarpPointer(X.disp, None, c->frame, 0, 0, 0, 0, new_w, new_h); +// X.last_x = c->x + new_w; +// X.last_y = c->y + new_h; +//} +// +//void mouse_totitle(Client* c) +//{ +// XWarpPointer(X.disp, None, X.root, 0, 0, 0, 0, (c->x + c->w/2), c->y + (MIN_HEIGHT/2)); +//} +// +//void mouse_get(int* ptrx, int* ptry) +//{ +// Window root = 0, child = 0; +// int winx = 0, winy = 0, mask = 0; +// XQueryPointer(X.disp, X.root, &root, &child, ptrx, ptry, &winx, &winy, (unsigned int*)&mask); +//} + + + + + +void Mouse_Down(XButtonEvent* ev) { (void)ev; - (void)loc; - if (X.mode == M_TILE_RESIZE) - { -// mons_tilemove(loc, ev->y_root - X.start_y); - } - else if (X.mode == M_COL_RESIZE) - { -// mons_coladjust(loc->monitor, loc->column, ev->x_root - X.start_x); - } - else - { - /* nothing to do here */ - } - X.mode = M_IDLE; -} - -void mouse_drag(XMotionEvent* ev, Location* loc) +// Location loc = {0}; +// if (mons_find(ev->window, &loc) && (loc.client->frame == ev->window)) +// { +// Client* c = loc.client; +// if (ev->y < MIN_HEIGHT) +// { +// X.edge = E_TOP; +// } +// else if (ev->y_root > (c->y + c->h - BORDER_WIDTH)) +// { +// X.edge = E_BOTTOM; +// } +// else if (ev->x < BORDER_WIDTH) +// { +// X.edge = E_LEFT; +// } +// else if (ev->x_root > (c->x + c->w - BORDER_WIDTH)) +// { +// X.edge = E_RIGHT; +// } +// else +// { +// X.edge = E_NONE; +// } +// mouse_down(ev, &loc); +// } + +} + +void Mouse_Up(XButtonEvent* ev) { - if (!loc->column) - { - float_drag(ev, loc); - } -} - -void mouse_tocorner(Client* c) -{ - int new_w = c->w - BORDER_WIDTH/2; - int new_h = c->h - BORDER_WIDTH/2; - XWarpPointer(X.disp, None, c->frame, 0, 0, 0, 0, new_w, new_h); - X.last_x = c->x + new_w; - X.last_y = c->y + new_h; -} - -void mouse_totitle(Client* c) -{ - XWarpPointer(X.disp, None, X.root, 0, 0, 0, 0, (c->x + c->w/2), c->y + (MIN_HEIGHT/2)); + (void)ev; +// Location loc = {0}; +// if (mons_find(ev->window, &loc) && (loc.client->frame == ev->window)) +// { +// mouse_up(ev, &loc); +// } } -void mouse_get(int* ptrx, int* ptry) +void Mouse_Drag(XMotionEvent* ev) { - Window root = 0, child = 0; - int winx = 0, winy = 0, mask = 0; - XQueryPointer(X.disp, X.root, &root, &child, ptrx, ptry, &winx, &winy, (unsigned int*)&mask); + (void)ev; +// Location loc = {0}; +// if (mons_find(ev->window, &loc) && (loc.client->frame == ev->window)) +// { +// mouse_drag(ev, &loc); +// } }