diff --git a/client.h b/client.h index 03169ad..2638873 100644 --- a/client.h +++ b/client.h @@ -7,6 +7,8 @@ #include +typedef struct Desktop Desktop; + /* kill client type */ enum KillType { @@ -40,9 +42,16 @@ enum ManageCookies }; typedef struct Client Client; -typedef struct Monitor Monitor; -typedef struct Desktop Desktop; typedef struct Decoration Decoration; +typedef struct Monitor Monitor; + +struct Decoration +{ + /* TODO */ + uint16_t w; + uint16_t h; + XCBWindow win; +}; struct Client { @@ -274,8 +283,6 @@ void setclientstate(Client *c, uint8_t state); void setdecorvisible(Client *c, uint8_t state); /* Sets the desktop count rolling back any clients to previous desktops. */ void setdesktopcount(Monitor *m, uint16_t desktops); -/* Sets the desktops layouts, (not automatic arrange must be called after to apply changes.) */ -void setdesktoplayout(Desktop *desk, uint8_t layout); /* Sets the currently selected desktop */ void setdesktopsel(Monitor *mon, Desktop *desksel); /* Sets the flag to disable border >>CHANGES<< for a client. */ diff --git a/desktop.c b/desktop.c new file mode 100644 index 0000000..ca11ba1 --- /dev/null +++ b/desktop.c @@ -0,0 +1,733 @@ + +#include "client.h" +#include "desktop.h" +#include "dwm.h" + + + +extern WM _wm; +extern UserSettings _cfg; +extern XCBAtom netatom[]; + + +void +arrangeq(Desktop *desk) +{ + arrangedesktop(desk); +} + +void +arrange(Desktop *desk) +{ + /* bar stuff */ + updatebargeom(desk->mon); + updatebarpos(desk->mon); + + reorder(desk); + arrangeq(desk); + restack(desk); +} + +void +arrangedesktop(Desktop *desk) +{ + if(layouts[desk->layout].arrange) + { layouts[desk->layout].arrange(desk); + } +} + + +/* Macro helper */ +#define __attach_helper(STRUCT, HEAD, NEXT, PREV, LAST) do \ + { \ + STRUCT->NEXT = STRUCT->HEAD; \ + STRUCT->HEAD = STRUCT; \ + if(STRUCT->NEXT) \ + { STRUCT->NEXT->PREV = STRUCT; \ + } \ + else \ + { STRUCT->LAST = STRUCT; \ + } \ + /* prevent circular linked list */ \ + STRUCT->PREV = NULL; \ + } while(0) + +#define __attach_after(START, AFTER, NEXT, PREV, HEAD, LAST) do \ + { \ + AFTER->NEXT = START->NEXT; \ + AFTER->PREV = START; \ + if(!START->NEXT) \ + { LAST = START; \ + } \ + else \ + { START->NEXT->PREV = AFTER; \ + } \ + START->NEXT = AFTER; \ + } while(0) +#define __attach_before(START, BEFORE, NEXT, PREV, HEAD, LAST, ATTACH) do \ + { \ + if(!START->PREV) \ + { ATTACH(BEFORE); \ + } \ + else \ + { \ + BEFORE->PREV = START->PREV; \ + BEFORE->NEXT = START; \ + START->PREV->NEXT = BEFORE; \ + START->PREV = BEFORE; \ + } \ + } while(0) + +/* Too hard to implement */ +/* +#define __detach_helper(TYPE, STRUCT, HEAD, NEXT, PREV, LAST) do \ + { \ + TYPE **tc; \ + for(tc = &STRUCT->HEAD; *tc && *tc != STRUCT; tc = &(*tc)->NEXT); \ + *tc = STRUCT->NEXT; \ + if(!(*tc)) \ + { STRUCT->LAST = STRUCT->PREV; \ + } \ + else if(STRUCT->NEXT) \ + { STRUCT->NEXT->PREV = STRUCT->PREV; \ + } \ + else if(STRUCT->PREV) \ + { \ + STRUCT->LAST = STRUCT->PREV; \ + STRUCT->PREV->NEXT = NULL; \ + } \ + STRUCT->NEXT = NULL; \ + STRUCT->PREV = NULL; \ + } while(0) +*/ + +void +attach(Client *c) +{ + if(ISOVERRIDEREDIRECT(c)) + { return; + } + __attach_helper(c, desktop->clients, next, prev, desktop->clast); +} + +void +attachstack(Client *c) +{ + if(ISOVERRIDEREDIRECT(c)) + { return; + } + __attach_helper(c, desktop->stack, snext, sprev, desktop->slast); +} + +void +attachrestack(Client *c) +{ + if(ISOVERRIDEREDIRECT(c)) + { return; + } + __attach_helper(c, desktop->rstack, rnext, rprev, desktop->rlast); +} + +void +attachfocus(Client *c) +{ + if(ISOVERRIDEREDIRECT(c)) + { return; + } + __attach_helper(c, desktop->focus, fnext, fprev, desktop->flast); +} + +void +attachfocusafter(Client *start, Client *after) +{ + if(ISOVERRIDEREDIRECT(after)) + { return; + } + Desktop *desk = start->desktop; + detachfocus(after); + __attach_after(start, after, fnext, fprev, desk->focus, desk->slast); +} + +void +attachfocusbefore(Client *start, Client *after) +{ + if(ISOVERRIDEREDIRECT(after)) + { return; + } + Desktop *desk = start->desktop; + detachfocus(after); + __attach_before(start, after, fnext, fprev, desk->focus, desk->slast, attachfocus); +} + +void +detach(Client *c) +{ + if(!c) + { DEBUG0("No client to detach FIXME"); + return; + } + if(!c->desktop) + { DEBUG0("No desktop in client FIXME"); + return; + } + if(!c->desktop->clients) + { DEBUG0("No clients in desktop FIXME"); + return; + } + Client **tc; + for (tc = &c->desktop->clients; *tc && *tc != c; tc = &(*tc)->next); + *tc = c->next; + if(!(*tc)) + { + c->desktop->clast = c->prev; + } + else if(c->next) + { c->next->prev = c->prev; + } + else if(c->prev) + { /* This should be UNREACHABLE but in case we do reach it then this should suffice*/ + c->desktop->clast = c->prev; + c->prev->next = NULL; + } + c->next = NULL; + c->prev = NULL; +} + +void +detachcompletely(Client *c) +{ + detach(c); + detachstack(c); + detachfocus(c); + detachrestack(c); +} + +void +detachstack(Client *c) +{ + if(!c) + { DEBUG0("No client to detach FIXME"); + return; + } + if(!c->desktop) + { DEBUG0("No desktop in client FIXME"); + return; + } + if(!c->desktop->stack) + { DEBUG0("No clients in desktop FIXME"); + return; + } + Desktop *desk = c->desktop; + Client **tc; + + for(tc = &desk->stack; *tc && *tc != c; tc = &(*tc)->snext); + *tc = c->snext; + if(!(*tc)) + { + desk->slast = c->sprev; + } + else if(c->snext) + { + c->snext->sprev = c->sprev; + } + else if(c->sprev) + { /* this should be UNREACHABLE but if it does this should suffice */ + desk->slast = c->sprev; + c->sprev->snext = NULL; + } + c->sprev = NULL; + c->snext = NULL; +} + +void +detachrestack(Client *c) +{ + if(!c) + { DEBUG0("No client to detach FIXME"); + return; + } + if(!c->desktop) + { DEBUG0("No desktop in client FIXME"); + return; + } + if(!c->desktop->rstack) + { DEBUG0("No clients in desktop FIXME"); + return; + } + Desktop *desk = c->desktop; + Client **tc; + + for(tc = &desk->rstack; *tc && *tc != c; tc = &(*tc)->rnext); + *tc = c->rnext; + if(!(*tc)) + { + desk->rlast = c->rprev; + } + else if(c->rnext) + { + c->rnext->rprev = c->rprev; + } + else if(c->rprev) + { /* this should be UNREACHABLE but if it does this should suffice */ + desk->rlast = c->rprev; + c->rprev->rnext = NULL; + } + + c->rprev = NULL; + c->rnext = NULL; +} + +void +detachfocus(Client *c) +{ + if(!c) + { DEBUG0("No client to detach FIXME"); + return; + } + if(!c->desktop) + { DEBUG0("No desktop in client FIXME"); + return; + } + if(!c->desktop->focus) + { DEBUG0("No clients in desktop FIXME"); + return; + } + Desktop *desk = c->desktop; + Client **tc, *t; + + for(tc = &desk->focus; *tc && *tc != c; tc = &(*tc)->fnext); + *tc = c->fnext; + if(!(*tc)) + { + desk->flast = c->fprev; + } + else if(c->fnext) + { + c->fnext->fprev = c->fprev; + } + else if(c->fprev) + { /* this should be UNREACHABLE but if it does this should suffice */ + desk->flast = c->fprev; + c->fprev->fnext = NULL; + } + + /* this just updates desktop->sel */ + if (c == c->desktop->sel) + { + for (t = c->desktop->focus; t && !ISVISIBLE(t); t = t->fnext); + c->desktop->sel = t; + } + + c->fprev = NULL; + c->fnext = NULL; +} + +void +cleanupdesktop(Desktop *desk) +{ + Client *c = NULL; + Client *next = NULL; + c = desk->clients; + while(c) + { + next = c->next; + cleanupclient(c); + c = next; + } + free(desk->settings); + free(desk); + desk = NULL; +} + +Desktop * +createdesktop(void) +{ + Desktop *desk = calloc(1, sizeof(Desktop)); + if(!desk) + { + DEBUG("%s", "WARN: FAILED TO CREATE DESKTOP"); + return NULL; + } + desk->layout = 0; + desk->olayout= 0; + desk->clients= NULL; + desk->clast = NULL; + desk->stack = NULL; + desk->slast = NULL; + desk->mon = NULL; + desk->settings = calloc(1, sizeof(UserSettings)); + if(!desk->settings) + { + DEBUG("%s", "WARN: FAILED TO CREATE SETTINGS."); + free(desk); + return NULL; + } + return desk; +} + +void +floating(Desktop *desk) +{ + /* for now just check in restack for it */ + monocle(desk); +} + +void +grid(Desktop *desk) +{ + const float bgwr = USGetGapRatio(&_cfg); + + i32 n, cols, rows, cn, rn, i, cx, cy, cw, ch; + i32 nx, ny; + i32 nw, nh; + Client *c; + Monitor *m = desk->mon; + + for(n = 0, c = nexttiled(desk->stack); c; c = nexttiled(c->snext), n++); + if(n == 0) + { return; + } + + /* grid dimensions */ + for(cols = 0; cols <= n/2; cols++) + { + if(cols*cols >= n) + { break; + } + } + /* set layout against the general calculation: not 1:2:2, but 2:3 */ + if(n == 5) + { cols = 2; + } + rows = n / cols; + + /* window geometries */ + cw = m->ww / (cols + !cols); + /* current column number */ + cn = 0; + /* current row number */ + rn = 0; + for(i = 0, c = nexttiled(desk->stack); c; i++, c = nexttiled(c->snext)) + { + if((i / rows) + 1 > cols - (n % cols)) + { rows = n/cols + 1; + } + ch = m->wh / (rows + !rows); + cx = m->wx + cn * cw; + cy = m->wy + rn * ch; + + nx = cx; + ny = cy; + nw = cw - (WIDTH(c) - c->w); + nh = ch - (HEIGHT(c) - c->h); + + nx += (nw - (nw * bgwr)) / 2; + ny += (nh - (nh * bgwr)) / 2; + nw *= bgwr; + nh *= bgwr; + + resize(c, nx, ny, nw, nh, 0); + ++rn; + if(rn >= rows) + { + rn = 0; + ++cn; + } + } +} + +void +monocle(Desktop *desk) +{ + Client *c; + Monitor *m = desk->mon; + i32 nw, nh; + const i32 nx = m->wx; + const i32 ny = m->wy; + + for(c = nexttiled(desk->stack); c; c = nexttiled(c->snext)) + { + nw = m->ww - (c->bw * 2); + nh = m->wh - (c->bw * 2); + resize(c, nx, ny, nw, nh, 0); + } +} + +Desktop * +nextdesktop(Desktop *desk) +{ + return desk ? desk->next : desk; +} + +Monitor * +nextmonitor(Monitor *m) +{ + return m ? m->next : m; +} + +Desktop * +prevdesktop(Desktop *desk) +{ + return desk ? desk->prev : desk; +} + +void +restack(Desktop *desk) +{ + XCBWindowChanges wc; + + wc.stack_mode = XCB_STACK_MODE_BELOW; + + if(desk->mon->bar && !ISHIDDEN(desk->mon->bar)) + { wc.sibling = desk->mon->bar->win; + } + else + { /* TODO: Maybe use wc.sibling = _wm.root? That causes error to be generated though. */ + wc.sibling = _wm.wmcheckwin; + } + + Client *c; + Client *cprev; + u8 config = 0; + u8 instack = 0; + + c = desk->stack; + cprev = NULL; + while(c) + { + instack = c->rprev || c->rnext; + /* Client holds both lists so we just check if the next's are the same if not configure it */ + config = c->rnext != c->snext || !instack; + if(config) + { + XCBConfigureWindow(_wm.dpy, c->win, XCB_CONFIG_WINDOW_SIBLING|XCB_CONFIG_WINDOW_STACK_MODE, &wc); + DEBUG("Configured window: %s", c->netwmname); + } + wc.sibling = c->win; + /* apply reorder without detaching/attaching */ + cprev = c; + c = nextstack(c); + cprev->rprev = cprev->sprev; + cprev->rnext = cprev->snext; + } + desk->rstack = desk->stack; + desk->rlast = cprev; +} + +void +reorder(Desktop *desk) +{ + updatestackpriorityfocus(desk); + MERGE_SORT_LINKED_LIST(Client, stackpriority, desk->stack, desk->slast, snext, sprev, 1, 0); +} + +/* how to return. + * reference point is c1. + * + * sort order is 1,2,3,4,5,6 + */ +static int +__stack_priority_helper_above(unsigned int x1, unsigned int x2) +{ + return x1 < x2; +} +/* how to return. + * reference point is c1. + * + * sort order is 6,5,4,3,2,1 + */ +static int +__stack_priority_helper_below(unsigned int x1, unsigned int x2) +{ + return x1 > x2; +} + +void +setdesktoplayout(Desktop *desk, uint8_t layout) +{ + desk->olayout = desk->layout; + desk->layout = layout; +} + +int +stackpriority(Client *c1, Client *c2) +{ + const unsigned int dock1 = ISDOCK(c1); + const unsigned int dock2 = ISDOCK(c2); + + const unsigned int above1 = ISALWAYSONTOP(c1); + const unsigned int above2 = ISALWAYSONTOP(c2); + + const unsigned int float1 = ISFAKEFLOATING(c1); + const unsigned int float2 = ISFAKEFLOATING(c2); + + const unsigned int below1 = ISBELOW(c1); + const unsigned int below2 = ISBELOW(c2); + + const unsigned int hidden1 = ISHIDDEN(c1); + const unsigned int hidden2 = ISHIDDEN(c2); + + /* Bottom Restacking */ + if(below1 ^ below2) + { + DEBUG0("BELOW"); + return __stack_priority_helper_below(below1, below2); + } + else if(hidden1 ^ hidden2) + { + DEBUG0("HIDDEN"); + return __stack_priority_helper_below(hidden1, hidden2); + } + /* Regular restacking */ + else if(dock1 ^ dock2) + { + DEBUG0("DOCK"); + return __stack_priority_helper_above(dock1, dock2); + } + else if(above1 ^ above2) + { + DEBUG0("ABOVE"); + return __stack_priority_helper_above(above1, above2); + } + else if(float1 ^ float2) + { + DEBUG0("FLOAT"); + return __stack_priority_helper_above(float1, float2); + } + + DEBUG0("FOCUS"); + /* focus is forward order so, we must calculate reversely */ + return __stack_priority_helper_above(c2->rstacknum, c1->rstacknum); +} + +void +tile(Desktop *desk) +{ + const u16 nmaster = USGetMCount(&_cfg); + const float mfact = USGetMFact(&_cfg); + const float bgwr = USGetGapRatio(&_cfg); + + i32 h, mw, my, ty; + i32 n, i; + i32 nx, ny; + i32 nw, nh; + + Client *c = NULL; + Monitor *m = desk->mon; + + n = 0; + for(c = desk->stack; c; c = nextstack(c)) + { n += !ISFLOATING(c); + } + + if(!n) + { return; + } + + if(n > nmaster) + { mw = nmaster ? m->ww * mfact: 0; + } + else + { mw = m->ww; + } + + i = my = ty = 0; + for (c = desk->stack; c; c = nextstack(c)) + { + if(ISFLOATING(c)) + { continue; + } + if (i < nmaster) + { + h = (m->wh - my) / (MIN(n, nmaster) - i); + nx = m->wx; + ny = m->wy + my; + nw = mw - c->bw * 2; + nh = h - c->bw * 2; + + nx += (nw - (nw * bgwr)) / 2; + ny += (nh - (nh * bgwr)) / 2; + nw *= bgwr; + nh *= bgwr; + + resize(c, nx, ny, nw, nh, 0); + if (my + HEIGHT(c) < m->wh) + { my += HEIGHT(c); + } + } + else + { + h = (m->wh - ty) / (n - i); + nx = m->wx + mw; + ny = m->wy + ty; + nw = m->ww - mw - c->bw * 2; + nh = h - c->bw * 2; + + nx += (nw - (nw * bgwr)) / 2; + ny += (nh - (nh * bgwr)) / 2; + nw *= bgwr; + nh *= bgwr; + + resize(c, nx, ny, nw, nh, 0); + if (ty + HEIGHT(c) < m->wh) + { ty += HEIGHT(c); + } + } + ++i; + } +} + +void +updatedesktop(void) +{ + u32 data = _wm.selmon->desksel->num; + XCBChangeProperty(_wm.dpy, _wm.root, netatom[NetCurrentDesktop], XCB_ATOM_CARDINAL, 32, XCB_PROP_MODE_REPLACE, (unsigned char *)&data, 1); +} + +void +updatedesktopnames(void) +{ + XCBChangeProperty(_wm.dpy, _wm.root, netatom[NetDesktopNames], XCB_ATOM_STRING, 8, XCB_PROP_MODE_REPLACE, "~0", _wm.selmon->deskcount); +} + +void +updatedesktopnum(void) +{ + i32 data = _wm.selmon->deskcount; + XCBChangeProperty(_wm.dpy, _wm.root, netatom[NetNumberOfDesktops], XCB_ATOM_CARDINAL, 32, XCB_PROP_MODE_REPLACE, (unsigned char *)&data, 1); +} + +void +updatestackpriorityfocus(Desktop *desk) +{ + Client *c; + int i = 0; + for(c = desk->focus; c; c = nextfocus(c)) + { + c->rstacknum = ++i; + if(ISFLOATING(c) && DOCKED(c)) + { setfloating(c, 0); + } + } +} + +void +updateviewport(void) +{ + i32 data[2] = { 0, 0 }; + XCBChangeProperty(_wm.dpy, _wm.root, netatom[NetDesktopViewport], XCB_ATOM_CARDINAL, 32, XCB_PROP_MODE_REPLACE, (unsigned char *)data, 2); +} + + + + + + + + + + + + + + diff --git a/desktop.h b/desktop.h new file mode 100644 index 0000000..4701861 --- /dev/null +++ b/desktop.h @@ -0,0 +1,154 @@ +#ifndef _WM_DESKTOP_H +#define _WM_DESKTOP_H + +#include "client.h" +/* layout(s) */ +enum LayoutType +{ + Tiled, Floating, Monocle, Grid, LayoutTypeLAST +}; + +typedef struct Desktop Desktop; +typedef struct Layout Layout; +typedef struct UserSettings UserSettings; + +struct Desktop +{ + int16_t num; /* The Desktop Number */ + + uint8_t layout; /* The Layout Index */ + uint8_t olayout; /* The Previous Layout Index */ + + Monitor *mon; /* Desktop Monitor */ + Client *clients; /* First Client in linked list */ + Client *clast; /* Last Client in linked list */ + Client *stack; /* Client Stack Order */ + Client *slast; /* Last Client in Stack */ + Client *rstack; /* restack Client order */ + Client *rlast; /* Last restack Client */ + Client *focus; /* Client Focus Order */ + Client *flast; /* Client Last Focus */ + Client *sel; /* Selected Client */ + Desktop *next; /* Next Client in linked list */ + Desktop *prev; /* Previous Client in list */ + UserSettings *settings; /* User settings data */ +}; + +struct Layout +{ + void (*arrange)(Desktop *); +}; + + +/* quickly calculate arrange stuff */ +void arrangeq(Desktop *desk); +/* Arranges and restacks the windows in the specified desktop. +*/ +void arrange(Desktop *desk); +/* Arranges the windows in the specified desktop. + * + * NOTE: Does not restack windows. + */ +void arrangedesktop(Desktop *desk); +/* Adds Client to clients desktop linked list. +*/ +void attach(Client *c); +/* Adds Client to rendering stack order in desktop linked list. +*/ +void attachstack(Client *c); +/* Adds Client to previous rendering stack order. + */ +void attachrestack(Client *c); +/* Adds Client to focus linked list. + */ +void attachfocus(Client *c); +/* Adds Client to focus linked list after specified "start" Client */ +void attachfocusafter(Client *start, Client *after); +/* Adds Client to focus linked list before specified "start" Client */ +void attachfocusbefore(Client *start, Client *after); +/* Removes Client from clients desktop linked list. +*/ +void detach(Client *c); +/* Removes all connections from clients desktop linked list + * Analagous to detachstack(c) and detach(c); +*/ +void detachcompletely(Client *c); +/* Removes Client from desktop rendering stack order. +*/ +void detachstack(Client *c); +/* Removes Client from previous restack order. (rstack); + */ +void detachrestack(Client *c); +/* Removes Client from desktop focus order. +*/ +void detachfocus(Client *c); +/* Frees desktop and allocated desktop properties. +*/ +void cleanupdesktop(Desktop *desk); +/* Allocates a desktop and desktop properties with all data set to 0 or to the adress of any newly allocated data. + * RETURN: Desktop * on Success. + * RETURN: NULL on Failure. + */ +Desktop *createdesktop(void); +/* Sets the "floating" layout for the specified desktop. + * Floating -> Windows overlap each other AKA default win10 window behaviour. + */ +void floating(Desktop *desk); +/* Sets the "grid" layout for the specified desktop. + * grid -> windows are sorted in a grid like formation, like those ones in hacker movies. + */ +void grid(Desktop *desk); +/* Sets the "monocle" layout for the specified desktop. + * monocle -> Windows are maximized to the screen avaible area, + * while floating windows are always raised above all others. + */ +void monocle(Desktop *desk); +/* Returns the next Desktop avaible. + * RETURN: Desktop* on Success. + * RETURN: NULL on Failure. + */ +Desktop *nextdesktop(Desktop *desktop); +/* Returns the previous desktop avaible. + * RETURN: Desktop * on Success. + * RETURN: NULL on Failure. + */ +Desktop *prevdesktop(Desktop *desk); +/* Reorders(restacks) clients in current desk->stack */ +void restack(Desktop *desk); +/* "Restacks" clients on from linked list no effect unless restack called*/ +void reorder(Desktop *desk); +/* Sets the desktops layouts, (not automatic arrange must be called after to apply changes.) */ +void setdesktoplayout(Desktop *desk, uint8_t layout); +/* reference point is c1. + * so if c1 has higher priority return 1. + * RETURN: 1 on higher priority. + * RETURN: 0 on lesser priority. + */ +int stackpriority(Client *c1, Client *c2); +/* Sets the "Tiled" layout for the specified desktop. + * Tiled -> Windows tile in a grid like patter where there is 1 Big window to the left, + * and "stacking" on top of each other smaller windows on the right. + */ +void tile(Desktop *desk); +/* Updates the XServer to the Current destop */ +void updatedesktop(void); +/* Updates the desktop names if they have changed */ +void updatedesktopnames(void); +/* Updates the current desktop count AKA how many desktops we got to the XServer */ +void updatedesktopnum(void); +/* Updates focus order when before reorder() */ +void updatestackpriorityfocus(Desktop *desk); +/* updates the viewport property to the XServer */ +void updateviewport(void); + + +static const Layout layouts[LayoutTypeLAST] = +{ + /* Name arrange */ + [Tiled] = { tile }, + [Floating] = { floating }, + [Monocle] = { monocle }, + [Grid] = { grid }, +}; + +#endif diff --git a/dwm.c b/dwm.c index d4ad9fc..2d396a1 100644 --- a/dwm.c +++ b/dwm.c @@ -274,25 +274,6 @@ argcvhandler(int argc, char *argv[]) } } - -void -arrangeq(Desktop *desk) -{ - arrangedesktop(desk); -} - -void -arrange(Desktop *desk) -{ - /* bar stuff */ - updatebargeom(desk->mon); - updatebarpos(desk->mon); - - reorder(desk); - arrangeq(desk); - restack(desk); -} - void arrangemon(Monitor *m) { @@ -302,7 +283,6 @@ arrangemon(Monitor *m) } } - void arrangemons(void) { @@ -312,92 +292,22 @@ arrangemons(void) } } -void -arrangedesktop(Desktop *desk) -{ - if(layouts[desk->layout].arrange) - { layouts[desk->layout].arrange(desk); - } -} - -/* Macro helper */ -#define __attach_helper(STRUCT, HEAD, NEXT, PREV, LAST) do \ - { \ - STRUCT->NEXT = STRUCT->HEAD; \ - STRUCT->HEAD = STRUCT; \ - if(STRUCT->NEXT) \ - { STRUCT->NEXT->PREV = STRUCT; \ - } \ - else \ - { STRUCT->LAST = STRUCT; \ - } \ - /* prevent circular linked list */ \ - STRUCT->PREV = NULL; \ - } while(0) -#define __attach_after(START, AFTER, NEXT, PREV, HEAD, LAST) do \ - { \ - AFTER->NEXT = START->NEXT; \ - AFTER->PREV = START; \ - if(!START->NEXT) \ - { LAST = START; \ - } \ - else \ - { START->NEXT->PREV = AFTER; \ - } \ - START->NEXT = AFTER; \ - } while(0) -#define __attach_before(START, BEFORE, NEXT, PREV, HEAD, LAST, ATTACH) do \ - { \ - if(!START->PREV) \ - { ATTACH(BEFORE); \ - } \ - else \ - { \ - BEFORE->PREV = START->PREV; \ - BEFORE->NEXT = START; \ - START->PREV->NEXT = BEFORE; \ - START->PREV = BEFORE; \ - } \ - } while(0) - -/* Too hard to implement */ -/* -#define __detach_helper(TYPE, STRUCT, HEAD, NEXT, PREV, LAST) do \ - { \ - TYPE **tc; \ - for(tc = &STRUCT->HEAD; *tc && *tc != STRUCT; tc = &(*tc)->NEXT); \ - *tc = STRUCT->NEXT; \ - if(!(*tc)) \ - { STRUCT->LAST = STRUCT->PREV; \ - } \ - else if(STRUCT->NEXT) \ - { STRUCT->NEXT->PREV = STRUCT->PREV; \ - } \ - else if(STRUCT->PREV) \ - { \ - STRUCT->LAST = STRUCT->PREV; \ - STRUCT->PREV->NEXT = NULL; \ - } \ - STRUCT->NEXT = NULL; \ - STRUCT->PREV = NULL; \ - } while(0) -*/ -void -attach(Client *c) -{ - if(ISOVERRIDEREDIRECT(c)) - { return; - } - __attach_helper(c, desktop->clients, next, prev, desktop->clast); -} - /* NOT RECOMMENDED AS REQUIRES MANUAL SETTING OF DESKTOP->NUM */ void attachdesktop(Monitor *m, Desktop *desktop) { desktop->mon = m; desktop->num = 0; - __attach_helper(desktop, mon->desktops, next, prev, mon->desklast); + /* can use attach helper here */ + desktop->next = m->desktops; + m->desktops = desktop; + if(desktop->next) + { desktop->next->prev = desktop; + } + else + { m->desklast = desktop; + } + desktop->prev = NULL; } void @@ -417,98 +327,6 @@ attachdesktoplast(Monitor *m, Desktop *desk) desk->num = m->deskcount++; } -void -attachstack(Client *c) -{ - if(ISOVERRIDEREDIRECT(c)) - { return; - } - __attach_helper(c, desktop->stack, snext, sprev, desktop->slast); -} - -void -attachrestack(Client *c) -{ - if(ISOVERRIDEREDIRECT(c)) - { return; - } - __attach_helper(c, desktop->rstack, rnext, rprev, desktop->rlast); -} - -void -attachfocus(Client *c) -{ - if(ISOVERRIDEREDIRECT(c)) - { return; - } - __attach_helper(c, desktop->focus, fnext, fprev, desktop->flast); -} - -void -attachfocusafter(Client *start, Client *after) -{ - if(ISOVERRIDEREDIRECT(after)) - { return; - } - Desktop *desk = start->desktop; - detachfocus(after); - __attach_after(start, after, fnext, fprev, desk->focus, desk->slast); -} - -void -attachfocusbefore(Client *start, Client *after) -{ - if(ISOVERRIDEREDIRECT(after)) - { return; - } - Desktop *desk = start->desktop; - detachfocus(after); - __attach_before(start, after, fnext, fprev, desk->focus, desk->slast, attachfocus); -} - -void -detach(Client *c) -{ - if(!c) - { DEBUG0("No client to detach FIXME"); - return; - } - if(!c->desktop) - { DEBUG0("No desktop in client FIXME"); - return; - } - if(!c->desktop->clients) - { DEBUG0("No clients in desktop FIXME"); - return; - } - Client **tc; - for (tc = &c->desktop->clients; *tc && *tc != c; tc = &(*tc)->next); - *tc = c->next; - if(!(*tc)) - { - c->desktop->clast = c->prev; - } - else if(c->next) - { c->next->prev = c->prev; - } - else if(c->prev) - { /* This should be UNREACHABLE but in case we do reach it then this should suffice*/ - c->desktop->clast = c->prev; - c->prev->next = NULL; - } - c->next = NULL; - c->prev = NULL; -} - -void -detachcompletely(Client *c) -{ - detach(c); - detachstack(c); - detachfocus(c); - detachrestack(c); -} - void detachdesktop(Monitor *m, Desktop *desktop) { @@ -535,126 +353,6 @@ detachdesktop(Monitor *m, Desktop *desktop) desktop->mon = NULL; } -void -detachstack(Client *c) -{ - if(!c) - { DEBUG0("No client to detach FIXME"); - return; - } - if(!c->desktop) - { DEBUG0("No desktop in client FIXME"); - return; - } - if(!c->desktop->stack) - { DEBUG0("No clients in desktop FIXME"); - return; - } - Desktop *desk = c->desktop; - Client **tc; - - for(tc = &desk->stack; *tc && *tc != c; tc = &(*tc)->snext); - *tc = c->snext; - if(!(*tc)) - { - desk->slast = c->sprev; - } - else if(c->snext) - { - c->snext->sprev = c->sprev; - } - else if(c->sprev) - { /* this should be UNREACHABLE but if it does this should suffice */ - desk->slast = c->sprev; - c->sprev->snext = NULL; - } - c->sprev = NULL; - c->snext = NULL; -} - -void -detachrestack(Client *c) -{ - if(!c) - { DEBUG0("No client to detach FIXME"); - return; - } - if(!c->desktop) - { DEBUG0("No desktop in client FIXME"); - return; - } - if(!c->desktop->rstack) - { DEBUG0("No clients in desktop FIXME"); - return; - } - Desktop *desk = c->desktop; - Client **tc; - - for(tc = &desk->rstack; *tc && *tc != c; tc = &(*tc)->rnext); - *tc = c->rnext; - if(!(*tc)) - { - desk->rlast = c->rprev; - } - else if(c->rnext) - { - c->rnext->rprev = c->rprev; - } - else if(c->rprev) - { /* this should be UNREACHABLE but if it does this should suffice */ - desk->rlast = c->rprev; - c->rprev->rnext = NULL; - } - - c->rprev = NULL; - c->rnext = NULL; -} - -void -detachfocus(Client *c) -{ - if(!c) - { DEBUG0("No client to detach FIXME"); - return; - } - if(!c->desktop) - { DEBUG0("No desktop in client FIXME"); - return; - } - if(!c->desktop->focus) - { DEBUG0("No clients in desktop FIXME"); - return; - } - Desktop *desk = c->desktop; - Client **tc, *t; - - for(tc = &desk->focus; *tc && *tc != c; tc = &(*tc)->fnext); - *tc = c->fnext; - if(!(*tc)) - { - desk->flast = c->fprev; - } - else if(c->fnext) - { - c->fnext->fprev = c->fprev; - } - else if(c->fprev) - { /* this should be UNREACHABLE but if it does this should suffice */ - desk->flast = c->fprev; - c->fprev->fnext = NULL; - } - - /* this just updates desktop->sel */ - if (c == c->desktop->sel) - { - for (t = c->desktop->focus; t && !ISVISIBLE(t); t = t->fnext); - c->desktop->sel = t; - } - - c->fprev = NULL; - c->fnext = NULL; -} - uint8_t checknewbar(Monitor *m, Client *c, uint8_t has_strut_or_strutp) { @@ -735,23 +433,6 @@ cleanup(void) } } -void -cleanupdesktop(Desktop *desk) -{ - Client *c = NULL; - Client *next = NULL; - c = desk->clients; - while(c) - { - next = c->next; - cleanupclient(c); - c = next; - } - free(desk->settings); - free(desk); - desk = NULL; -} - void cleanupcursors(void) { @@ -793,32 +474,6 @@ cleanupmons(void) } } -Desktop * -createdesktop(void) -{ - Desktop *desk = calloc(1, sizeof(Desktop)); - if(!desk) - { - DEBUG("%s", "WARN: FAILED TO CREATE DESKTOP"); - return NULL; - } - desk->layout = 0; - desk->olayout= 0; - desk->clients= NULL; - desk->clast = NULL; - desk->stack = NULL; - desk->slast = NULL; - desk->mon = NULL; - desk->settings = calloc(1, sizeof(UserSettings)); - if(!desk->settings) - { - DEBUG("%s", "WARN: FAILED TO CREATE SETTINGS."); - free(desk); - return NULL; - } - return desk; -} - Monitor * createmon(void) { @@ -891,13 +546,6 @@ exithandler(void) DEBUG("%s", "Process Terminated Successfully."); } -void -floating(Desktop *desk) -{ - /* for now just check in restack for it */ - monocle(desk); -} - void getnamefromreply(XCBWindowProperty *namerep, char **str_return) { @@ -997,105 +645,6 @@ getrootptr(i16 *x, i16 *y) return samescr; } -void -grid(Desktop *desk) -{ - const float bgwr = USGetGapRatio(&_cfg); - - i32 n, cols, rows, cn, rn, i, cx, cy, cw, ch; - i32 nx, ny; - i32 nw, nh; - Client *c; - Monitor *m = desk->mon; - - for(n = 0, c = nexttiled(desk->stack); c; c = nexttiled(c->snext), n++); - if(n == 0) - { return; - } - - /* grid dimensions */ - for(cols = 0; cols <= n/2; cols++) - { - if(cols*cols >= n) - { break; - } - } - /* set layout against the general calculation: not 1:2:2, but 2:3 */ - if(n == 5) - { cols = 2; - } - rows = n / cols; - - /* window geometries */ - cw = m->ww / (cols + !cols); - /* current column number */ - cn = 0; - /* current row number */ - rn = 0; - for(i = 0, c = nexttiled(desk->stack); c; i++, c = nexttiled(c->snext)) - { - if((i / rows) + 1 > cols - (n % cols)) - { rows = n/cols + 1; - } - ch = m->wh / (rows + !rows); - cx = m->wx + cn * cw; - cy = m->wy + rn * ch; - - nx = cx; - ny = cy; - nw = cw - (WIDTH(c) - c->w); - nh = ch - (HEIGHT(c) - c->h); - - nx += (nw - (nw * bgwr)) / 2; - ny += (nh - (nh * bgwr)) / 2; - nw *= bgwr; - nh *= bgwr; - - resize(c, nx, ny, nw, nh, 0); - ++rn; - if(rn >= rows) - { - rn = 0; - ++cn; - } - } -} - -void -monocle(Desktop *desk) -{ - Client *c; - Monitor *m = desk->mon; - i32 nw, nh; - const i32 nx = m->wx; - const i32 ny = m->wy; - - for(c = nexttiled(desk->stack); c; c = nexttiled(c->snext)) - { - nw = m->ww - (c->bw * 2); - nh = m->wh - (c->bw * 2); - resize(c, nx, ny, nw, nh, 0); - } -} - -Desktop * -nextdesktop(Desktop *desk) -{ - return desk ? desk->next : desk; -} - -Monitor * -nextmonitor(Monitor *m) -{ - return m ? m->next : m; -} - -Desktop * -prevdesktop(Desktop *desk) -{ - return desk ? desk->prev : desk; -} - void quit(void) { @@ -1519,56 +1068,6 @@ recttomon(i16 x, i16 y, u16 w, u16 h) return r; } -void -restack(Desktop *desk) -{ - XCBWindowChanges wc; - - wc.stack_mode = XCB_STACK_MODE_BELOW; - - if(desk->mon->bar && !ISHIDDEN(desk->mon->bar)) - { wc.sibling = desk->mon->bar->win; - } - else - { /* TODO: Maybe use wc.sibling = _wm.root? That causes error to be generated though. */ - wc.sibling = _wm.wmcheckwin; - } - - Client *c; - Client *cprev; - u8 config = 0; - u8 instack = 0; - - c = desk->stack; - cprev = NULL; - while(c) - { - instack = c->rprev || c->rnext; - /* Client holds both lists so we just check if the next's are the same if not configure it */ - config = c->rnext != c->snext || !instack; - if(config) - { - XCBConfigureWindow(_wm.dpy, c->win, XCB_CONFIG_WINDOW_SIBLING|XCB_CONFIG_WINDOW_STACK_MODE, &wc); - DEBUG("Configured window: %s", c->netwmname); - } - wc.sibling = c->win; - /* apply reorder without detaching/attaching */ - cprev = c; - c = nextstack(c); - cprev->rprev = cprev->sprev; - cprev->rnext = cprev->snext; - } - desk->rstack = desk->stack; - desk->rlast = cprev; -} - -void -reorder(Desktop *desk) -{ - updatestackpriorityfocus(desk); - MERGE_SORT_LINKED_LIST(Client, stackpriority, desk->stack, desk->slast, snext, sprev, 1, 0); -} - void restart(void) { @@ -1902,13 +1401,6 @@ setdesktopcount(Monitor *m, uint16_t desktops) } } -void -setdesktoplayout(Desktop *desk, uint8_t layout) -{ - desk->olayout = desk->layout; - desk->layout = layout; -} - void setdesktopsel(Monitor *mon, Desktop *desksel) { @@ -2114,33 +1606,6 @@ setupcfgdefaults(void) bs->bottom.y = 1.0f - bs->bottom.h; } -void -updatedesktop(void) -{ - u32 data = _wm.selmon->desksel->num; - XCBChangeProperty(_wm.dpy, _wm.root, netatom[NetCurrentDesktop], XCB_ATOM_CARDINAL, 32, XCB_PROP_MODE_REPLACE, (unsigned char *)&data, 1); -} - -void -updatedesktopnames(void) -{ - XCBChangeProperty(_wm.dpy, _wm.root, netatom[NetDesktopNames], XCB_ATOM_STRING, 8, XCB_PROP_MODE_REPLACE, "~0", _wm.selmon->deskcount); -} - -void -updatedesktopnum(void) -{ - i32 data = _wm.selmon->deskcount; - XCBChangeProperty(_wm.dpy, _wm.root, netatom[NetNumberOfDesktops], XCB_ATOM_CARDINAL, 32, XCB_PROP_MODE_REPLACE, (unsigned char *)&data, 1); -} - -void -updateviewport(void) -{ - i32 data[2] = { 0, 0 }; - XCBChangeProperty(_wm.dpy, _wm.root, netatom[NetDesktopViewport], XCB_ATOM_CARDINAL, 32, XCB_PROP_MODE_REPLACE, (unsigned char *)data, 2); -} - void sigchld(int signo) /* signal */ { @@ -2279,78 +1744,6 @@ specialconds(int argc, char *argv[]) } } -/* how to return. - * reference point is c1. - * - * sort order is 1,2,3,4,5,6 - */ -static int -__stack_priority_helper_above(unsigned int x1, unsigned int x2) -{ - return x1 < x2; -} -/* how to return. - * reference point is c1. - * - * sort order is 6,5,4,3,2,1 - */ -static int -__stack_priority_helper_below(unsigned int x1, unsigned int x2) -{ - return x1 > x2; -} - -int -stackpriority(Client *c1, Client *c2) -{ - const unsigned int dock1 = ISDOCK(c1); - const unsigned int dock2 = ISDOCK(c2); - - const unsigned int above1 = ISALWAYSONTOP(c1); - const unsigned int above2 = ISALWAYSONTOP(c2); - - const unsigned int float1 = ISFAKEFLOATING(c1); - const unsigned int float2 = ISFAKEFLOATING(c2); - - const unsigned int below1 = ISBELOW(c1); - const unsigned int below2 = ISBELOW(c2); - - const unsigned int hidden1 = ISHIDDEN(c1); - const unsigned int hidden2 = ISHIDDEN(c2); - - /* Bottom Restacking */ - if(below1 ^ below2) - { - DEBUG0("BELOW"); - return __stack_priority_helper_below(below1, below2); - } - else if(hidden1 ^ hidden2) - { - DEBUG0("HIDDEN"); - return __stack_priority_helper_below(hidden1, hidden2); - } - /* Regular restacking */ - else if(dock1 ^ dock2) - { - DEBUG0("DOCK"); - return __stack_priority_helper_above(dock1, dock2); - } - else if(above1 ^ above2) - { - DEBUG0("ABOVE"); - return __stack_priority_helper_above(above1, above2); - } - else if(float1 ^ float2) - { - DEBUG0("FLOAT"); - return __stack_priority_helper_above(float1, float2); - } - - DEBUG0("FOCUS"); - /* focus is forward order so, we must calculate reversely */ - return __stack_priority_helper_above(c2->rstacknum, c1->rstacknum); -} - void startup(void) { @@ -2380,83 +1773,6 @@ startup(void) #endif } -void -tile(Desktop *desk) -{ - const u16 nmaster = USGetMCount(&_cfg); - const float mfact = USGetMFact(&_cfg); - const float bgwr = USGetGapRatio(&_cfg); - - i32 h, mw, my, ty; - i32 n, i; - i32 nx, ny; - i32 nw, nh; - - Client *c = NULL; - Monitor *m = desk->mon; - - n = 0; - for(c = desk->stack; c; c = nextstack(c)) - { n += !ISFLOATING(c); - } - - if(!n) - { return; - } - - if(n > nmaster) - { mw = nmaster ? m->ww * mfact: 0; - } - else - { mw = m->ww; - } - - i = my = ty = 0; - for (c = desk->stack; c; c = nextstack(c)) - { - if(ISFLOATING(c)) - { continue; - } - if (i < nmaster) - { - h = (m->wh - my) / (MIN(n, nmaster) - i); - nx = m->wx; - ny = m->wy + my; - nw = mw - c->bw * 2; - nh = h - c->bw * 2; - - nx += (nw - (nw * bgwr)) / 2; - ny += (nh - (nh * bgwr)) / 2; - nw *= bgwr; - nh *= bgwr; - - resize(c, nx, ny, nw, nh, 0); - if (my + HEIGHT(c) < m->wh) - { my += HEIGHT(c); - } - } - else - { - h = (m->wh - ty) / (n - i); - nx = m->wx + mw; - ny = m->wy + ty; - nw = m->ww - mw - c->bw * 2; - nh = h - c->bw * 2; - - nx += (nw - (nw * bgwr)) / 2; - ny += (nh - (nh * bgwr)) / 2; - nw *= bgwr; - nh *= bgwr; - - resize(c, nx, ny, nw, nh, 0); - if (ty + HEIGHT(c) < m->wh) - { ty += HEIGHT(c); - } - } - ++i; - } -} - #ifdef XINERAMA static int isuniquegeom(XCBXineramaScreenInfo *unique, size_t n, XCBXineramaScreenInfo *info) @@ -2844,20 +2160,6 @@ updatenumlockmask(void) free(reply); } -void -updatestackpriorityfocus(Desktop *desk) -{ - Client *c; - int i = 0; - for(c = desk->focus; c; c = nextfocus(c)) - { - c->rstacknum = ++i; - if(ISFLOATING(c) && DOCKED(c)) - { setfloating(c, 0); - } - } -} - void wakeupconnection(XCBDisplay *display, int screen) { diff --git a/dwm.h b/dwm.h index 7645103..b8d3d82 100644 --- a/dwm.h +++ b/dwm.h @@ -9,6 +9,7 @@ #include "settings.h" #include "pannel.h" #include "client.h" +#include "desktop.h" #include "XCB-TRL/xcb_trl.h" #include "XCB-TRL/xcb_winutil.h" #include "XCB-TRL/xcb_gtk.h" @@ -52,6 +53,7 @@ enum SchemeType SchemeNorm, SchemeSel }; + /* clicks */ enum ClkType { @@ -64,12 +66,6 @@ enum ClkType ClkLast }; -/* layout(s) */ -enum LayoutType -{ - Tiled, Floating, Monocle, Grid, LayoutTypeLAST -}; - enum ClientListModes { ClientListAdd, ClientListRemove, ClientListReload, @@ -85,10 +81,6 @@ typedef union Arg Arg; typedef struct Key Key; typedef struct Button Button; typedef struct Monitor Monitor; -typedef struct Decoration Decoration; -typedef struct Stack Stack; -typedef struct Layout Layout; -typedef struct Desktop Desktop; typedef struct WM WM; typedef struct MotifWmHints MotifWmHints; @@ -122,15 +114,6 @@ struct Button Arg arg; /* Argument */ }; - -struct Decoration -{ - /* TODO */ - uint16_t w; - uint16_t h; - XCBWindow win; -}; - struct Monitor { int16_t mx; /* Monitor X (Screen Area) */ @@ -153,33 +136,6 @@ struct Monitor uint8_t pad0[6]; }; -struct Layout -{ - void (*arrange)(Desktop *); -}; - -struct Desktop -{ - int16_t num; /* The Desktop Number */ - - uint8_t layout; /* The Layout Index */ - uint8_t olayout; /* The Previous Layout Index */ - - Monitor *mon; /* Desktop Monitor */ - Client *clients; /* First Client in linked list */ - Client *clast; /* Last Client in linked list */ - Client *stack; /* Client Stack Order */ - Client *slast; /* Last Client in Stack */ - Client *rstack; /* restack Client order */ - Client *rlast; /* Last restack Client */ - Client *focus; /* Client Focus Order */ - Client *flast; /* Client Last Focus */ - Client *sel; /* Selected Client */ - Desktop *next; /* Next Client in linked list */ - Desktop *prev; /* Previous Client in list */ - UserSettings *settings; /* User settings data */ -}; - struct WM { int screen; /* Screen id */ @@ -217,58 +173,18 @@ struct MotifWmHints /* Handles the main(int argc, char **argv) arguments. */ void argcvhandler(int argc, char *argv[]); -/* quickly calculate arrange stuff */ -void arrangeq(Desktop *desk); -/* Arranges and restacks the windows in the specified desktop. -*/ -void arrange(Desktop *desk); /* Arranges and restacks all the windows for every deskop in the specified monitor. */ void arrangemon(Monitor *m); /* Arrange and restacks every window on all monitors. */ void arrangemons(void); -/* Arranges the windows in the specified desktop. - * - * NOTE: Does not restack windows. - */ -void arrangedesktop(Desktop *desk); /* Adds desktop to specified monitor linked list. */ void attachdesktop(Monitor *m, Desktop *desk); /* Removes desktop fromt specified monitor linked list. */ void detachdesktop(Monitor *m, Desktop *desk); -/* Adds Client to clients desktop linked list. -*/ -void attach(Client *c); -/* Adds Client to rendering stack order in desktop linked list. -*/ -void attachstack(Client *c); -/* Adds Client to previous rendering stack order. - */ -void attachrestack(Client *c); -/* Adds Client to focus linked list. - */ -void attachfocus(Client *c); -void attachfocusafter(Client *start, Client *after); -void attachfocusbefore(Client *start, Client *after); -/* Removes Client from clients desktop linked list. -*/ -void detach(Client *c); -/* Removes all connections from clients desktop linked list - * Analagous to detachstack(c) and detach(c); -*/ -void detachcompletely(Client *c); -/* Removes Client from desktop rendering stack order. -*/ -void detachstack(Client *c); -/* Removes Client from previous restack order. (rstack); - */ -void detachrestack(Client *c); -/* Removes Client from desktop focus order. -*/ -void detachfocus(Client *c); /* Checks given the provided information if a window is eligible to be a new bar. * if it is then it becomes the new bar. * RETURN: 0 on Success. @@ -289,20 +205,12 @@ void cleanup(void); /* Frees allocated cursors. */ void cleanupcursors(void); -/* Frees desktop and allocated desktop properties. -*/ -void cleanupdesktop(Desktop *desk); /* Frees Monitor and allocated Monitor properties. */ void cleanupmon(Monitor *m); /* Frees all monitors and allocated Monitor properties. */ void cleanupmons(void); -/* Allocates a desktop and desktop properties with all data set to 0 or to the adress of any newly allocated data. - * RETURN: Desktop * on Success. - * RETURN: NULL on Failure. - */ -Desktop *createdeskop(void); /* Allocates a Monitor and Monitor properties with all data set to 0 or to the adress of any newly allocated data. * RETURN: Monitor * on Success. * RETURN: exit(1) on Failure. @@ -324,38 +232,15 @@ void eventhandler(XCBGenericEvent *ev); /* handles atexit. */ void exithandler(void); -/* Sets the "floating" layout for the specified desktop. - * Floating -> Windows overlap each other AKA default win10 window behaviour. - */ -void floating(Desktop *desk); /* Allocates memory and resturns the pointer in **str_return from the specified XCBWindowProperty. */ void getnamefromreply(XCBWindowProperty *namerep, char **str_return); /* Gets the icon property from the specified XCBWindowProperty. */ uint32_t *geticonprop(XCBWindowProperty *iconreply); -/* Sets the "grid" layout for the specified desktop. - * grid -> windows are sorted in a grid like formation, like those ones in hacker movies. - */ -void grid(Desktop *desk); -/* Sets the "monocle" layout for the specified desktop. - * monocle -> Windows are maximized to the screen avaible area, - * while floating windows are always raised above all others. - */ -void monocle(Desktop *desk); -/* Returns the next Desktop avaible. - * RETURN: Desktop* on Success. - * RETURN: NULL on Failure. - */ -Desktop *nextdesktop(Desktop *desktop); /* Returns the next Monitor avaible. * RETURN: Monitor* on Success. * RETURN: NULL on Failure. */ Monitor *nextmonitor(Monitor *monitor); -/* Returns the previous desktop avaible. - * RETURN: Desktop * on Success. - * RETURN: NULL on Failure. - */ -Desktop *prevdesktop(Desktop *desk); /* Sends a event to the main event loop to stop running. */ void quit(void); @@ -369,10 +254,6 @@ Desktop *restoredesktopsession(Monitor *m, char *buff, uint16_t len); Monitor *restoremonsession(char *buff, uint16_t len); /* Searches through every monitor for a possible big enough size to fit rectangle parametors specified */ Monitor *recttomon(int16_t x, int16_t y, uint16_t width, uint16_t height); -/* Reorders(restacks) clients in current desk->stack */ -void restack(Desktop *desk); -/* "Restacks" clients on from linked list no effect unless restack called*/ -void reorder(Desktop *desk); /* Flags RESTART and sets running to 0; * results in execvp(self) and "restarts" */ @@ -417,21 +298,10 @@ void sigterm(int signo); * NOTE: This is only checked when the program is about to exit. */ void specialconds(int argc, char *argcv[]); -/* reference point is c1. - * so if c1 has higher priority return 1. - * RETURN: 1 on higher priority. - * RETURN: 0 on lesser priority. - */ -int stackpriority(Client *c1, Client *c2); /* Setups most vital data for the context. * Calls exit(1) on Failure. */ void startup(void); -/* Sets the "Tiled" layout for the specified desktop. - * Tiled -> Windows tile in a grid like patter where there is 1 Big window to the left, - * and "stacking" on top of each other smaller windows on the right. - */ -void tile(Desktop *desk); /* updates the Status Bar Position from given monitor */ void updatebarpos(Monitor *m); /* updates the bar geometry from the given monitor */ @@ -442,19 +312,10 @@ void updatebargeom(Monitor *m); * 2 Reloads the entire list. * _NET_WM_CLIENT_LIST */ void updateclientlist(XCBWindow win, uint8_t type); -/* Updates the XServer to the Current destop */ -void updatedesktop(void); -/* Updates the desktop names if they have changed */ -void updatedesktopnames(void); -/* Updates the current desktop count AKA how many desktops we got to the XServer */ -void updatedesktopnum(void); /* Updates Geometry for external monitors based on if they have different geometry */ int updategeom(void); /* checks and updates mask if numlock is active */ void updatenumlockmask(void); -void updatestackpriorityfocus(Desktop *desk); -/* updates the viewport property to the XServer */ -void updateviewport(void); /* Wakups the current X connection by sending a event to it */ void wakeupconnection(XCBDisplay *display, int screen); /* Returns the Monitor if found from the specified window @@ -470,14 +331,4 @@ int COULDBEBAR(Client *c, uint8_t strut); enum BarSides GETBARSIDE(Monitor *m, Client *bar, uint8_t get_prev_side); - -static const Layout layouts[LayoutTypeLAST] = -{ - /* Name arrange */ - [Tiled] = { tile }, - [Floating] = { floating }, - [Monocle] = { monocle }, - [Grid] = { grid }, -}; - #endif