Skip to content

Commit

Permalink
Restructured Thread Handler (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerjenigeUberMensch authored Aug 7, 2024
1 parent 5933986 commit dbb0fe4
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 121 deletions.
24 changes: 20 additions & 4 deletions include/getprop.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,29 @@

#include "XCB-TRL/xcb_trl.h"
#include "prop.h"
#include "queue.h"


typedef struct PropHandler PropHandler;

void PropInit(void);
void PropDestroy(void);
void PropListen(XCBDisplay *display, XCBWindow win, enum PropertyType type);
void PropListenArg(XCBDisplay *display, XCBWindow win, enum PropertyType type, PropArg arg);
struct
PropHandler
{
CQueue queue;
uint32_t use_threads;
uint32_t thread_length;
uint32_t thread_index;
pthread_t *threads;
GetPropCookie *queue_data;
uint32_t queue_length;
};


PropHandler *PropCreateStatic(void);
void PropInit(PropHandler *handler);
void PropDestroy(PropHandler *handler);
void PropListen(PropHandler *handler, XCBDisplay *display, XCBWindow win, enum PropertyType type);
void PropListenArg(PropHandler *handler, XCBDisplay *display, XCBWindow win, enum PropertyType type, PropArg arg);


#endif
2 changes: 2 additions & 0 deletions include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "desktop.h"
#include "monitor.h"
#include "prop.h"
#include "getprop.h"
#include "x.h"
#include "../tools/util.h"

Expand Down Expand Up @@ -111,6 +112,7 @@ struct WM
Monitor *mons; /* Monitors */
XCBKeySymbols *syms; /* keysym alloc */
char *wmname; /* WM_NAME */
PropHandler *handler; /* Prop Handler */

pthread_mutex_t mutex; /* Mutex for main thread */
uint8_t restart; /* Restart flag */
Expand Down
8 changes: 4 additions & 4 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1362,10 +1362,10 @@ setclientwtype(Client *c, XCBAtom atom, u8 state)
PropArg arg;
arg.ui[0] = atom;
if(state)
{ PropListenArg(_wm.dpy, c->win, PropSetWtype, arg);
{ PropListenArg(_wm.handler, _wm.dpy, c->win, PropSetWtype, arg);
}
else
{ PropListenArg(_wm.dpy, c->win, PropUnsetWtype, arg);
{ PropListenArg(_wm.handler, _wm.dpy, c->win, PropUnsetWtype, arg);
}
}

Expand All @@ -1375,10 +1375,10 @@ setclientnetstate(Client *c, XCBAtom atom, u8 state)
PropArg arg;
arg.ui[0] = atom;
if(state)
{ PropListenArg(_wm.dpy, c->win, PropSetWState, arg);
{ PropListenArg(_wm.handler, _wm.dpy, c->win, PropSetWState, arg);
}
else
{ PropListenArg(_wm.dpy, c->win, PropUnsetWState, arg);
{ PropListenArg(_wm.handler, _wm.dpy, c->win, PropUnsetWState, arg);
}
}

Expand Down
36 changes: 18 additions & 18 deletions src/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ maprequest(XCBGenericEvent *event)

/* map window first (illusion of responsiveness) */
XCBMapWindow(_wm.dpy, win);
PropListen(_wm.dpy, win, PropManage);
PropListen(_wm.handler, _wm.dpy, win, PropManage);

if(sync)
{ XCBFlush(_wm.dpy);
Expand Down Expand Up @@ -971,7 +971,7 @@ destroynotify(XCBGenericEvent *event)

u8 sync = 0;

PropListen(_wm.dpy, win, PropUnmanage);
PropListen(_wm.handler, _wm.dpy, win, PropUnmanage);

if(sync)
{ XCBFlush(_wm.dpy);
Expand Down Expand Up @@ -1043,7 +1043,7 @@ unmapnotify(XCBGenericEvent *event)

u8 sync = 0;

PropListen(_wm.dpy, win, PropUnmanage);
PropListen(_wm.handler, _wm.dpy, win, PropUnmanage);

if(sync)
{ XCBFlush(_wm.dpy);
Expand Down Expand Up @@ -1402,57 +1402,57 @@ propertynotify(XCBGenericEvent *event)
switch(atom)
{
case XCB_ATOM_WM_TRANSIENT_FOR:
PropListen(_wm.dpy, win, PropTransient);
PropListen(_wm.handler, _wm.dpy, win, PropTransient);
break;
case XCB_ATOM_WM_HINTS:
PropListen(_wm.dpy, win, PropWMHints);
PropListen(_wm.handler, _wm.dpy, win, PropWMHints);
break;
case XCB_ATOM_WM_NORMAL_HINTS:
PropListen(_wm.dpy, win, PropSizeHints);
PropListen(_wm.handler, _wm.dpy, win, PropSizeHints);
break;
case XCB_ATOM_WM_NAME:
PropListen(_wm.dpy, win, PropWMName);
PropListen(_wm.handler, _wm.dpy, win, PropWMName);
break;
case XCB_ATOM_WM_ICON_NAME:
/* ignore */
break;
case XCB_ATOM_WM_CLASS:
PropListen(_wm.dpy, win, PropWMClass);
PropListen(_wm.handler, _wm.dpy, win, PropWMClass);
break;
case XCB_ATOM_WM_CLIENT_MACHINE:
/* ignore */
break;
default:
/* other atoms */
if(atom == motifatom)
{ PropListen(_wm.dpy, win, PropMotifHints);
{ PropListen(_wm.handler, _wm.dpy, win, PropMotifHints);
}
else if(atom == netatom[NetWMName])
{ PropListen(_wm.dpy, win, PropNetWMName);
{ PropListen(_wm.handler, _wm.dpy, win, PropNetWMName);
}
else if(atom == netatom[NetWMWindowType])
{ PropListen(_wm.dpy, win, PropWindowType);
{ PropListen(_wm.handler, _wm.dpy, win, PropWindowType);
}
else if(atom == netatom[NetWMState])
{ PropListen(_wm.dpy, win, PropWindowState);
{ PropListen(_wm.handler, _wm.dpy, win, PropWindowState);
}
else if(atom == wmatom[WMProtocols])
{ PropListen(_wm.dpy, win, PropWMProtocol);
{ PropListen(_wm.handler, _wm.dpy, win, PropWMProtocol);
}
else if(atom == netatom[NetWMStrut])
{ PropListen(_wm.dpy, win, PropStrut);
{ PropListen(_wm.handler, _wm.dpy, win, PropStrut);
}
else if(atom == netatom[NetWMStrutPartial])
{ PropListen(_wm.dpy, win, PropStrutp);
{ PropListen(_wm.handler, _wm.dpy, win, PropStrutp);
}
else if(atom == netatom[NetWMPid])
{ PropListen(_wm.dpy, win, PropPid);
{ PropListen(_wm.handler, _wm.dpy, win, PropPid);
}
else if(atom == netatom[NetWMIcon])
{ PropListen(_wm.dpy, win, PropIcon);
{ PropListen(_wm.handler, _wm.dpy, win, PropIcon);
}
else if(atom == motifatom)
{ PropListen(_wm.dpy, win, PropMotifHints);
{ PropListen(_wm.handler, _wm.dpy, win, PropMotifHints);
}
break;
}
Expand Down
Loading

0 comments on commit dbb0fe4

Please sign in to comment.