Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed NETMoveResizeWindow, Fixed settings, Somewhat fixed bar calculations #96

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bar.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ BarResizeBuff(
char *buff = realloc(bar->writebuff, newsize);
if(buff)
{
bar->writebuff = buff;
bar->writebuff = (uint32_t *)buff;
bar->buffsize = newsize;
}
return !buff;
Expand Down
2 changes: 1 addition & 1 deletion bar.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct Bar
unsigned int screen;

size_t buffsize;
char *writebuff;
uint32_t *writebuff;
};


Expand Down
59 changes: 34 additions & 25 deletions dwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ int HASWMDELETEWINDOW(Client *c){ return c->wstateflags & _STATE_SUPPORTED_WM_DE

enum BarSides GETBARSIDE(Monitor *m, Bar *bar)
{
const u8 sidebar = bar->w <= m->mw / 2 || bar->h >= m->mh / 2;
const u8 sidebar = bar->w < bar->h;
const u8 left = bar->x + bar->w / 2 <= m->mx + m->mw / 2;
const u8 top = bar->y + bar->h / 2 >= m->my + m->mh / 2;
const u8 top = bar->y <= m->my + (m->mh / 2);
enum BarSides side;
if(sidebar)
{
Expand All @@ -147,7 +147,7 @@ enum BarSides GETBARSIDE(Monitor *m, Bar *bar)
{ side = BarSideTop;
}
else
{ side = BarSideRight;
{ side = BarSideBottom;
}
}
return side;
Expand Down Expand Up @@ -1266,7 +1266,7 @@ grabkeys(void)
void
grid(Desktop *desk)
{
const u16 bgw = 0;
const u16 bgw = USGetGapWidth(&_cfg);

i32 i, n, cw, ch, aw, ah, cols, rows;
i32 nx, ny, nw, nh;
Expand Down Expand Up @@ -1360,7 +1360,7 @@ killclient(Client *c, enum KillType type)
ev.pad1[0] = 0;
ev.pad1[1] = 0;
ev.pad1[2] = 0;
XCBSendEvent(_wm.dpy, win, 0, XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY, (const char *)&ev);
XCBSendEvent(_wm.dpy, _wm.root, 0, XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY, (const char *)&ev);
}
}

Expand Down Expand Up @@ -1500,7 +1500,9 @@ managereply(XCBWindow win, XCBCookie requests[MANAGE_CLIENT_COOKIE_COUNT])
if(checkbar && COULDBEBAR(c, strutp || strut))
{
Bar *bar = managebar(_wm.selmon, win);
resizebar(bar, c->x, c->y, c->w, c->h);
if(bar)
{ resizebar(bar, c->x, c->y, c->w, c->h);
}
free(c);
c = NULL;
DEBUG("Found a bar: [%d]", win);
Expand Down Expand Up @@ -1544,6 +1546,7 @@ managereply(XCBWindow win, XCBCookie requests[MANAGE_CLIENT_COOKIE_COUNT])
if(c->desktop)
{ HASH_ADD_INT(c->desktop->mon->__hash, win, c);
}
updatedecor(c);
/* propagates border_width, if size doesn't change */
configure(c);
goto CLEANUP;
Expand Down Expand Up @@ -1579,6 +1582,13 @@ managebar(Monitor *m, XCBWindow win)
if(!win)
{ return NULL;
}
if(!m->bar)
{ m->bar = createbar();
DEBUG0("No bar alloced this should not be possible");
}
if(!m->bar)
{ return NULL;
}
m->bar->win = win;

DEBUG("New bar: [%d]", win);
Expand Down Expand Up @@ -2030,7 +2040,8 @@ restoremonsession(char *buff, u16 len)
Monitor *target = NULL;
const u8 errorleeway = 5;
Monitor *possible[errorleeway];
memset(possible, 0, errorleeway * sizeof(Monitor *));
int i;
for(i = 0; i < errorleeway; ++i) { possible[i] = NULL; }
u8 possibleInterator = 0;

for(pullm = _wm.mons; pullm; pullm = nextmonitor(pullm))
Expand Down Expand Up @@ -2058,7 +2069,6 @@ restoremonsession(char *buff, u16 len)
pullm = target;
if(!pullm)
{
u8 i;
for(i = 0; i < errorleeway; ++i)
{
if(possible[i])
Expand All @@ -2074,7 +2084,12 @@ restoremonsession(char *buff, u16 len)
}
if(pullm)
{
managebar(pullm, BarId);
Bar *b = wintobar(BarId, 0);
if(b)
{
unmanagebar(b);
managebar(pullm, BarId);
}
/* TODO */
setdesktopcount(pullm, DeskCount);
if(DeskSelNum != pullm->desksel->num)
Expand All @@ -2085,8 +2100,8 @@ restoremonsession(char *buff, u16 len)
{ setmondesktop(pullm, desk);
}
}
DEBUG("Restored Monitor: [%p]", (void *)pullm);
}
DEBUG("Restored Monitor: [%d]", pullm ? pullm->bar->win : 0);
return pullm;
}
else
Expand Down Expand Up @@ -3128,20 +3143,13 @@ seturgent(Client *c, uint8_t state)
}

void
updatedecor(Client *c, XCBGetWindowAttributes *wa)
updatedecor(Client *c)
{
XCBWindow win = c->decor->win;
return;
XCBWindow win = c->decor->win;
if(!win)
{
XCBCreateWindowValueList values =
{
.override_redirect = 1,
};
win = XCBCreateWindow(_wm.dpy, _wm.root, c->x, c->y - 15, c->w, c->h + 15, 0,
XCB_COPY_FROM_PARENT, XCB_WINDOW_CLASS_INPUT_ONLY, XCBGetScreen(_wm.dpy)->root_visual, XCB_CW_OVERRIDE_REDIRECT, &values);
XCBReparentWindow(_wm.dpy, c->win, win, c->x, c->y);
DEBUG("%u %u", c->win ,win);
win = XCBCreateSimpleWindow(_wm.dpy, c->win, c->x, c->y - 15, c->w, 15, 0, 0, 0);
XCBMapWindow(_wm.dpy, win);
c->decor->win = win;
}
Expand Down Expand Up @@ -3366,9 +3374,9 @@ startup(void)
void
tile(Desktop *desk)
{
const u16 nmaster = 0;
const float mfact = 0.0f;
const u16 bgw = 0;
const u16 nmaster = USGetMCount(&_cfg);
const float mfact = USGetMFact(&_cfg);
const u16 bgw = USGetGapWidth(&_cfg);

i32 h = 0, mw = 0, my = 0, ty = 0;
i32 n = 0, i = 0;
Expand Down Expand Up @@ -3636,9 +3644,10 @@ unmanagebar(Bar *bar)
{
Monitor *m = wintobar(bar->win, 1);
if(bar)
{ memset(bar, 0, sizeof(Bar));
{
memset(bar, 0, sizeof(Bar));
setshowbar(bar, 0);
}

if(m)
{
updatebarpos(m);
Expand Down
5 changes: 4 additions & 1 deletion dwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "uthash.h"
#include "bar.h"
#include "settings.h"
#include "pannel.h"
#include "XCB-TRL/xcb_trl.h"
#include "XCB-TRL/xcb_winutil.h"

Expand Down Expand Up @@ -254,6 +255,8 @@ struct Monitor

uint16_t deskcount; /* Desktop Counter */
uint8_t pad[2];
uint8_t pad0[4];

Client *__hash; /* Hashed clients */
};

Expand Down Expand Up @@ -770,7 +773,7 @@ void updateclass(Client *c, XCBWMClass *_class);
* 2 Reloads the entire list.
* _NET_WM_CLIENT_LIST */
void updateclientlist(XCBWindow win, uint8_t type);
void updatedecor(Client *c, XCBGetWindowAttributes *wa);
void updatedecor(Client *c);
/* Updates the XServer to the Current destop */
void updatedesktop(void);
/* Updates the desktop names if they have changed */
Expand Down
13 changes: 12 additions & 1 deletion events.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "keybinds.h"
#include "dwm.h"


extern WM _wm;
extern XCBAtom netatom[NetLast];
extern XCBAtom wmatom[WMLast];
Expand Down Expand Up @@ -229,6 +230,8 @@ buttonpress(XCBGenericEvent *event)
if(_wm.selmon->desksel->sel)
{ unfocus(_wm.selmon->desksel->sel, 1);
}
XCBSetInputFocus(_wm.dpy, eventwin, XCB_INPUT_FOCUS_POINTER_ROOT, XCB_CURRENT_TIME);
XCBChangeProperty(_wm.dpy, _wm.root, netatom[NetActiveWindow], XCB_ATOM_WINDOW, 32, XCB_PROP_MODE_REPLACE, (unsigned char *)&(eventwin), 1);
}
int i;
for(i = 0; i < LENGTH(buttons); ++i)
Expand Down Expand Up @@ -613,7 +616,6 @@ configurerequest(XCBGenericEvent *event)
const XCBWindow parent = ev->parent;
const XCBWindow sibling = ev->sibling;


(void)parent;

Client *c;
Expand Down Expand Up @@ -1139,6 +1141,13 @@ clientmessage(XCBGenericEvent *event)
else if(atom == netatom[NetMoveResize])
{
const int netwmstate = l2;
XCBButtonPressEvent bev;
bev.root = _wm.root;
bev.time = XCB_CURRENT_TIME;
bev.child = 0;
bev.event = win;
Arg arg;
arg.v = &bev;
/* TODO */
switch(netwmstate)
{
Expand All @@ -1150,8 +1159,10 @@ clientmessage(XCBGenericEvent *event)
case _NET_WM_MOVERESIZE_SIZE_BOTTOM:
case _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT:
case _NET_WM_MOVERESIZE_SIZE_LEFT:
ResizeWindow(&arg);
break;
case _NET_WM_MOVERESIZE_MOVE:
DragWindow(&arg);
break;
case _NET_WM_MOVERESIZE_SIZE_KEYBOARD:
break;
Expand Down
3 changes: 0 additions & 3 deletions keybinds.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ static const Key keys[] =
{ XCBKeyPress, SUPER, XK_c, SetWindowLayout, {Monocle} },
{ XCBKeyPress, SUPER, XK_g, SetWindowLayout, {Grid} },
{ XCBKeyPress, 0, XF11, ToggleFullscreen, {0} },
{ XCBKeyPress, SUPER, XK_f, SetBorderWidth, {.i = +1}},
{ XCBKeyPress, SUPER, XK_v, SetBorderWidth, {.i = -1}},
{ XCBKeyPress, ALT, TAB, AltTab, {0} },

/* multimedia keys */
{ XCBKeyPress, 0, XAudioMute, SpawnWindow, {.v = mute_vol } },
Expand Down
1 change: 0 additions & 1 deletion toggle.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "dwm.h"


uint8_t ToggleInit(void);
void Toggle(void (*func) (void *data), void *data);

void ToggleExit(void);
Expand Down