From: Mike Lowis Date: Mon, 13 Mar 2023 20:27:45 +0000 (-0400) Subject: added some more mouse hooks X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=152f3a484c94ed0b7c4d3cad4170b54c198bfa80;p=proto%2Faos.git added some more mouse hooks --- diff --git a/bin/winmgr/mons.c b/bin/winmgr/mons.c index 3c3543e..69fa19c 100644 --- a/bin/winmgr/mons.c +++ b/bin/winmgr/mons.c @@ -2,15 +2,16 @@ #include int PtrX = 0, PtrY = 0; -static Monitor* pickmon(void); + +//static Monitor* pickmon(void); //static Column* pickcol(Column* cols, int relx); -static Workspace* pickws(Monitor* mon, int wsid); -static void client_visibility(Workspace* wspace, int show); -static Client* client_find(Client* clients, Window win); -static void add_client(Monitor* mon, Client* c, int ptrx); -static void remove_client(Location* loc, Client* c); +//static Workspace* pickws(Monitor* mon, int wsid); +//static void client_visibility(Workspace* wspace, int show); +//static Client* client_find(Client* clients, Window win); +//static void add_client(Monitor* mon, Client* c, int ptrx); +//static void remove_client(Location* loc, Client* c); //static void adjust_all(Column* col, int xoff); -static void change_wspace(Monitor* mon, Workspace* wspace); +//static void change_wspace(Monitor* mon, Workspace* wspace); Monitor Monitors[MAX_MONITORS]; @@ -90,99 +91,99 @@ void mons_init(void) int mons_find(Window win, Location* loc) { - for (int m = 0; m < MAX_MONITORS; m++) - { - for (int i = 0; i < NUM_WORKSPACES; i++) - { - Workspace* wspace = &(Monitors[m].wspaces[i]); - Column* column = NULL; - Client* client = client_find(wspace->floating, win); - if (!client) - { - for (int i =0; i < wspace->ncolumns; i++) - { - Column* column = &wspace->columns[i]; - if ( (client = client_find(column->clients, win)) ) - { - break; - } - } - } - /* return the client location if we found it */ - if (client) - { - loc->monitor = &Monitors[m]; - loc->workspace = wspace; - loc->column = column; - loc->client = client; - return 1; - } - } - } +// for (int m = 0; m < MAX_MONITORS; m++) +// { +// for (int i = 0; i < NUM_WORKSPACES; i++) +// { +// Workspace* wspace = &(Monitors[m].wspaces[i]); +// Column* column = NULL; +// Client* client = client_find(wspace->floating, win); +// if (!client) +// { +// for (int i =0; i < wspace->ncolumns; i++) +// { +// Column* column = &wspace->columns[i]; +// if ( (client = client_find(column->clients, win)) ) +// { +// break; +// } +// } +// } +// /* return the client location if we found it */ +// if (client) +// { +// loc->monitor = &Monitors[m]; +// loc->workspace = wspace; +// loc->column = column; +// loc->client = client; +// return 1; +// } +// } +// } return 0; } /* adds a new client to the most appropriate monitor */ void mons_addclient(Client* c) { - Monitor* mon = pickmon(); - add_client(mon, c, PtrX); - mouse_totitle(c); +// Monitor* mon = pickmon(); +// add_client(mon, c, PtrX); +// mouse_totitle(c); } void mons_delclient(Location* loc) { - if (Focused == loc->client) - { - Focused = NULL; - } - remove_client(loc, loc->client); - xfree(loc->client->name); - XDestroyWindow(X.disp, loc->client->frame); - free(loc->client); +// if (Focused == loc->client) +// { +// Focused = NULL; +// } +// remove_client(loc, loc->client); +// xfree(loc->client->name); +// XDestroyWindow(X.disp, loc->client->frame); +// free(loc->client); } void mons_layer(Monitor* mon) { - int nwins = 0; - Window* wins = NULL; - Client* c; - Column* col; - LIST_FOR_EACH(c, mon->cspace->floating) - { - wins = realloc(wins, ++nwins * sizeof(Window)); - wins[nwins-1] = c->frame; - } - - /* first lower all of the tiled windows */ - for (int i =0; i < mon->cspace->ncolumns; i++) - { - col = &mon->cspace->columns[i]; - LIST_FOR_EACH(c, col->clients) - { - wins = realloc(wins, ++nwins * sizeof(Window)); - wins[nwins-1] = c->frame; - } - } - if (nwins) - { - XRestackWindows(X.disp, wins, nwins); - } - xfree(wins); +// int nwins = 0; +// Window* wins = NULL; +// Client* c; +// Column* col; +// LIST_FOR_EACH(c, mon->cspace->floating) +// { +// wins = realloc(wins, ++nwins * sizeof(Window)); +// wins[nwins-1] = c->frame; +// } +// +// /* first lower all of the tiled windows */ +// for (int i =0; i < mon->cspace->ncolumns; i++) +// { +// col = &mon->cspace->columns[i]; +// LIST_FOR_EACH(c, col->clients) +// { +// wins = realloc(wins, ++nwins * sizeof(Window)); +// wins[nwins-1] = c->frame; +// } +// } +// if (nwins) +// { +// XRestackWindows(X.disp, wins, nwins); +// } +// xfree(wins); } void mons_togglefloat(Location* loc) { - remove_client(loc, loc->client); - if (loc->client->flags & (F_FLOATING)) - { - loc->client->flags &= ~F_FLOATING; - } - else - { - loc->client->flags |= F_FLOATING; - } - mons_addclient(loc->client); +// remove_client(loc, loc->client); +// if (loc->client->flags & (F_FLOATING)) +// { +// loc->client->flags &= ~F_FLOATING; +// } +// else +// { +// loc->client->flags |= F_FLOATING; +// } +// mons_addclient(loc->client); } /* find the best monitor to own the window by calculating the overlap */ @@ -193,51 +194,51 @@ void mons_place(Client* c) void mons_wspace(int wsid) { - Monitor* mon = pickmon(); - change_wspace(mon, pickws(mon, wsid)); +// Monitor* mon = pickmon(); +// change_wspace(mon, pickws(mon, wsid)); } void mons_towspace(Client* c, int wsid) { - Location loc = {0}; - if (mons_find(c->win, &loc)) - { - mouse_get(&PtrX, &PtrY); - Workspace* wspace = pickws(loc.monitor, wsid); - if (wspace != loc.workspace) - { - remove_client(&loc, c); -// client_show(c, 0); - Workspace* prev = loc.monitor->cspace; - loc.monitor->cspace = wspace; - add_client(loc.monitor, c, PtrX); - loc.monitor->cspace = prev; - } - } +// Location loc = {0}; +// if (mons_find(c->win, &loc)) +// { +// mouse_get(&PtrX, &PtrY); +// Workspace* wspace = pickws(loc.monitor, wsid); +// if (wspace != loc.workspace) +// { +// remove_client(&loc, c); +//// client_show(c, 0); +// Workspace* prev = loc.monitor->cspace; +// loc.monitor->cspace = wspace; +// add_client(loc.monitor, c, PtrX); +// loc.monitor->cspace = prev; +// } +// } } void mons_raise(Monitor* mon, Client* c) { - mon->cspace->floating = list_del(mon->cspace->floating, c); - c->next = mon->cspace->floating; - mon->cspace->floating = c; - mons_layer(mon); +// mon->cspace->floating = list_del(mon->cspace->floating, c); +// c->next = mon->cspace->floating; +// mon->cspace->floating = c; +// mons_layer(mon); } void mons_lower(Monitor* mon, Client* c) { - mon->cspace->floating = list_del(mon->cspace->floating, c); - c->next = NULL; - if (mon->cspace->floating) - { - Client* curr = list_last(mon->cspace->floating); - curr->next = c; - } - else - { - mon->cspace->floating = c; - } - mons_layer(mon); +// mon->cspace->floating = list_del(mon->cspace->floating, c); +// c->next = NULL; +// if (mon->cspace->floating) +// { +// Client* curr = list_last(mon->cspace->floating); +// curr->next = c; +// } +// else +// { +// mon->cspace->floating = c; +// } +// mons_layer(mon); } void mons_colsplit(void) @@ -335,34 +336,34 @@ void mons_tilemove(Location* loc, int hdiff) void mons_activate(Window win) { - Location loc; - if (mons_find(win, &loc)) - { - change_wspace(loc.monitor, loc.workspace); - if (!loc.column) - { - mons_raise(loc.monitor, loc.client); - } - } +// Location loc; +// if (mons_find(win, &loc)) +// { +// change_wspace(loc.monitor, loc.workspace); +// if (!loc.column) +// { +// mons_raise(loc.monitor, loc.client); +// } +// } } -static Monitor* pickmon(void) -{ - mouse_get(&PtrX, &PtrY); - int m = 0; - Monitor* mon; - for (; m < MAX_MONITORS; m++) - { - mon = &Monitors[m]; - if ((mon->x <= PtrX && PtrX < mon->x+mon->w) && - (mon->y <= PtrY && PtrY < mon->y+mon->h)) - { - break; - } - } - mon = (m < MAX_MONITORS ? mon : &Monitors[0]); - return mon; -} +//static Monitor* pickmon(void) +//{ +// mouse_get(&PtrX, &PtrY); +// int m = 0; +// Monitor* mon; +// for (; m < MAX_MONITORS; m++) +// { +// mon = &Monitors[m]; +// if ((mon->x <= PtrX && PtrX < mon->x+mon->w) && +// (mon->y <= PtrY && PtrY < mon->y+mon->h)) +// { +// break; +// } +// } +// mon = (m < MAX_MONITORS ? mon : &Monitors[0]); +// return mon; +//} //static Column* pickcol(Column* cols, int relx) //{ @@ -385,75 +386,75 @@ static Monitor* pickmon(void) // return col; //} -static Workspace* pickws(Monitor* mon, int wsid) -{ - return &(mon->wspaces[wsid]); -} - -static void client_visibility(Workspace* wspace, int show) -{ - Column* col; - Client* client; - LIST_FOR_EACH(client, wspace->floating) - { -// client_show(client, show); - } - for (int i = 0; i < wspace->ncolumns; i++) - { - col = &(wspace->columns[i]); - LIST_FOR_EACH(client, col->clients) - { -// client_show(client, show); - } - } -} - -static Client* client_find(Client* clients, Window win) -{ - Client* client; - LIST_FOR_EACH_UNTIL(client, clients, - (client->frame == win || client->win == win)); - return client; -} - -static void add_client(Monitor* mon, Client* c, int ptrx) -{ - if (X.mode == M_INIT || c->flags & (F_DIALOG|F_FLOATING)) - { - c->next = mon->cspace->floating; - mon->cspace->floating = c; - c->x = mon->midx - c->w/2; - c->y = mon->midy - c->h/2; - Client_AdjustSize(c); - } - else - { - /* find first empty column, and fill that first, otherwise use the last column we find */ - Column* col = NULL; - for (int i = 0; i < mon->cspace->ncolumns; i++) - { - col = &(mon->cspace->columns[i]); - if (col->clients == NULL) - { - break; - } - } - tile_add(&(Location){mon, NULL, col, c}); - } - mons_layer(mon); -} - -static void remove_client(Location* loc, Client* c) -{ - if (!loc->column) - { - loc->workspace->floating = list_del(loc->workspace->floating, c); - } - else - { - tile_del(loc); - } -} +//static Workspace* pickws(Monitor* mon, int wsid) +//{ +// return &(mon->wspaces[wsid]); +//} +// +//static void client_visibility(Workspace* wspace, int show) +//{ +// Column* col; +// Client* client; +// LIST_FOR_EACH(client, wspace->floating) +// { +//// client_show(client, show); +// } +// for (int i = 0; i < wspace->ncolumns; i++) +// { +// col = &(wspace->columns[i]); +// LIST_FOR_EACH(client, col->clients) +// { +//// client_show(client, show); +// } +// } +//} +// +//static Client* client_find(Client* clients, Window win) +//{ +// Client* client; +// LIST_FOR_EACH_UNTIL(client, clients, +// (client->frame == win || client->win == win)); +// return client; +//} +// +//static void add_client(Monitor* mon, Client* c, int ptrx) +//{ +// if (X.mode == M_INIT || c->flags & (F_DIALOG|F_FLOATING)) +// { +// c->next = mon->cspace->floating; +// mon->cspace->floating = c; +// c->x = mon->midx - c->w/2; +// c->y = mon->midy - c->h/2; +// Client_AdjustSize(c); +// } +// else +// { +// /* find first empty column, and fill that first, otherwise use the last column we find */ +// Column* col = NULL; +// for (int i = 0; i < mon->cspace->ncolumns; i++) +// { +// col = &(mon->cspace->columns[i]); +// if (col->clients == NULL) +// { +// break; +// } +// } +// tile_add(&(Location){mon, NULL, col, c}); +// } +// mons_layer(mon); +//} +// +//static void remove_client(Location* loc, Client* c) +//{ +// if (!loc->column) +// { +// loc->workspace->floating = list_del(loc->workspace->floating, c); +// } +// else +// { +// tile_del(loc); +// } +//} //static void adjust_all(Column* col, int xoff) //{ @@ -466,12 +467,12 @@ static void remove_client(Location* loc, Client* c) // } //} -static void change_wspace(Monitor* mon, Workspace* wspace) -{ - if (mon->cspace != wspace) - { - client_visibility(mon->cspace, 0); - client_visibility(wspace, 1); - mon->cspace = wspace; - } -} +//static void change_wspace(Monitor* mon, Workspace* wspace) +//{ +// if (mon->cspace != wspace) +// { +// client_visibility(mon->cspace, 0); +// client_visibility(wspace, 1); +// mon->cspace = wspace; +// } +//} diff --git a/bin/winmgr/mouse.c b/bin/winmgr/mouse.c index 3f55f4c..270bc73 100644 --- a/bin/winmgr/mouse.c +++ b/bin/winmgr/mouse.c @@ -16,36 +16,36 @@ typedef struct { int mods; int btn; int type; - void(*func)(Location* loc); + void(*func)(Client* client); } MouseAct; -static void resize_frame(Location* loc) +static void resize_frame(Client* client) { if (Current->xbutton.y > MIN_HEIGHT) { X.mode = M_RESIZE; - Mouse_ToCorner(loc->client); + Mouse_ToCorner(client); } } -//static void toggle_float(Location* loc) +//static void toggle_float(Client* client) //{ -// mons_togglefloat(loc); +// mons_togglefloat(cient); //} -static void close_client(Location* loc) +static void close_client(Client* client) { - Client_Close(loc->client); + Client_Close(client); } -static void stack_clients(Location* loc) +static void stack_clients(Client* client) { - tile_set(loc); +// tile_set(loc); } -static void reposition_tile(Location* loc) +static void reposition_tile(Client* client) { - (void)loc; + (void)client; X.mode = (X.edge == E_TOP ? M_TILE_RESIZE : M_COL_RESIZE); } @@ -62,7 +62,7 @@ MouseAct Stacked[] = { { 0, Button2, ButtonPress, stack_clients }, }; -static void process(XButtonEvent* ev, Location* loc, MouseAct* actions, int nactions) +static void process(XButtonEvent* ev, Client* client, MouseAct* actions, int nactions) { for (int i = 0; i < nactions; i++) { @@ -75,52 +75,23 @@ static void process(XButtonEvent* ev, Location* loc, MouseAct* actions, int nact if (match) { Current = (XEvent*)ev; - act->func(loc); + act->func(client); 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])); - } -} - -void mouse_up(XButtonEvent* ev, Location* 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_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_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_ToCorner(Client* client) { @@ -133,10 +104,31 @@ void Mouse_ToCorner(Client* client) void Mouse_Down(XButtonEvent* ev, Client* client) { +// if (!loc->column) +// { +// process(ev, loc, Floating, sizeof(Floating)/sizeof(Floating[0])); +// } +// else + { + process(ev, client, Stacked, sizeof(Stacked)/sizeof(Stacked[0])); + } } void Mouse_Up(XButtonEvent* ev, Client* client) { +// 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, Client* client) diff --git a/bin/winmgr/winmgr.c b/bin/winmgr/winmgr.c index a3018d4..2b7d461 100644 --- a/bin/winmgr/winmgr.c +++ b/bin/winmgr/winmgr.c @@ -38,7 +38,7 @@ static void xmaprequest(XEvent* e) static void xunmapnotify(XEvent* e) { XUnmapEvent* ev = &(e->xunmap); - //printf("UNMAP(e: 0x%lx w: 0x%lx %d)\n", ev->event, ev->window, ev->from_configure); + printf("UNMAP(e: 0x%lx w: 0x%lx %d)\n", ev->event, ev->window, ev->from_configure); Client* client = Client_Find(ev->window); if (client) @@ -58,7 +58,7 @@ static void xunmapnotify(XEvent* e) static void xdestroynotify(XEvent* e) { XDestroyWindowEvent* ev = &(e->xdestroywindow); - //printf("DESTROY(w: 0x%lx)\n", ev->window); + printf("DESTROY(w: 0x%lx)\n", ev->window); Client* client = Client_Find(ev->window); if (client) @@ -106,7 +106,7 @@ static void xconfigrequest(XEvent* e) static void xclientmsg(XEvent* e) { XClientMessageEvent* ev = &(e->xclient); - //printf("CLIENT_MSG(w: 0x%lx a: '%s')\n", ev->window, XGetAtomName(X.disp, ev->message_type)); + printf("CLIENT_MSG(w: 0x%lx a: '%s')\n", ev->window, XGetAtomName(X.disp, ev->message_type)); if (ev->message_type == atom("_NET_ACTIVE_WINDOW")) { @@ -118,7 +118,7 @@ static void xclientmsg(XEvent* e) static void xpropnotify(XEvent* e) { XPropertyEvent* ev = &(e->xproperty); - //printf("PROP_NOTIFY(w: 0x%lx)\n", ev->window); + printf("PROP_NOTIFY(w: 0x%lx)\n", ev->window); Client* client = Client_Find(ev->window); if (client) @@ -132,7 +132,7 @@ static void xpropnotify(XEvent* e) static void xenternotify(XEvent* e) { XCrossingEvent* ev = &(e->xcrossing); - //printf("ENTER(w: 0x%lx s: %d m: %d d: %d)\n", ev->window, ev->state, ev->mode, ev->detail); + printf("ENTER(w: 0x%lx s: %d m: %d d: %d)\n", ev->window, ev->state, ev->mode, ev->detail); Client* client = Client_Find(ev->window); if (client) @@ -147,7 +147,7 @@ static void xexpose(XEvent* e) XExposeEvent* ev = &(e->xexpose); if (ev->count == 0) { - //printf("EXPOSE(w: 0x%lx)\n", ev->window); + printf("EXPOSE(w: 0x%lx)\n", ev->window); Client* client = Client_Find(ev->window); if (client) { @@ -197,7 +197,7 @@ static void xbtnpress(XEvent* e) 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); + 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); Client* client = Client_Find(ev->window); if (client && (client->frame == ev->window)) @@ -212,7 +212,7 @@ static void xbtnmotion(XEvent* e) { /* make sure we get just the latest event */ 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); + 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)); Client* client = Client_Find(ev->window);