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

Logic and currency Fixes #495

Merged
merged 1 commit into from
Jan 6, 2025
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
5 changes: 5 additions & 0 deletions include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,9 @@ void NonNull wakeupconnection(XCBDisplay *display, int screen);
/* Error handler */
void NonNullArg(1) xerror(XCBDisplay *display, XCBGenericError *error);


int LOCK_WM(void);
int UNLOCK_WM(void);


#endif
67 changes: 0 additions & 67 deletions include/safebool.h

This file was deleted.

4 changes: 2 additions & 2 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ extern XCBAtom motifatom;

/* Macro definitions */

u16 OLDWIDTH(Client *c) { return (c->oldw + (c->bw * 2)); }
u16 OLDHEIGHT(Client *c) { return (c->oldw + (c->bw * 2)); }
u16 OLDWIDTH(Client *c) { return (c->oldw + (c->oldbw * 2)); }
u16 OLDHEIGHT(Client *c) { return (c->oldw + (c->oldbw * 2)); }
u16 WIDTH(Client *c) { return (c->w + (c->bw * 2)); }
u16 HEIGHT(Client *c) { return (c->h + (c->bw * 2)); }
/* Our custom states */
Expand Down
42 changes: 29 additions & 13 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,28 @@
#include "keybinds.h"
/* for HELP/DebugGING see under main() or the bottom */

extern void (*handler[XCBLASTEvent]) (XCBGenericEvent *);
int LOCK_WM(void) {
extern WM _wm;
int ret = EXIT_SUCCESS;
if(_wm.use_threads)
{ ret = pthread_mutex_lock(&_wm.mutex);
}
return ret;
}
int UNLOCK_WM(void) {
extern WM _wm;
int ret = EXIT_SUCCESS;
if(_wm.use_threads)
{ ret = pthread_mutex_unlock(&_wm.mutex);
}
return ret;
}





extern void (*handler[XCBLASTEvent]) (XCBGenericEvent *);

WM _wm;
UserSettings _cfg;
Expand Down Expand Up @@ -120,21 +140,17 @@ cleanup(void)
void __HOT__
eventhandler(XCBGenericEvent *ev)
{
/* TODO: Remove references to other clients, and move _wm.use_threads to run() instead. */
if(_wm.use_threads)
{ pthread_mutex_lock(&_wm.mutex);
}
/* int for speed */
const int cleanev = XCB_EVENT_RESPONSE_TYPE(ev);
/* Debug("%s", XCBGetEventName(cleanev)); */
if(LENGTH(handler) > cleanev)
{ handler[cleanev](ev);
}

/* TODO: Remove references to other clients, and move _wm.use_threads to run() instead. */
if(_wm.use_threads)
{ pthread_mutex_unlock(&_wm.mutex);
if(LENGTH(handler) < cleanev || cleanev <= -1)
{ return;
}

LOCK_WM();

handler[cleanev](ev);

UNLOCK_WM();
}

void
Expand Down
39 changes: 38 additions & 1 deletion src/toggle.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,20 @@ DragWindow(
else
{ XCBRaiseWindow(_wm.dpy, win);
}

XCBFlush(_wm.dpy);
XCBGenericEvent *ev = NULL;
running = 1;
XCBMotionNotifyEvent *mev = NULL;
XCBTimestamp lasttime = 0;

/* Unlock as was previous locked */
UNLOCK_WM();
do
{
if(ev)
{
LOCK_WM();
eventhandler(ev);
switch(XCB_EVENT_RESPONSE_TYPE(ev))
{
Expand Down Expand Up @@ -381,9 +386,14 @@ DragWindow(
}
break;
}
UNLOCK_WM();
free(ev);
}
} while(_wm.running && running && !XCBNextEvent(_wm.dpy, &ev));

/* relock to prevent race conditions */
LOCK_WM();

running = 0;
XCBUngrabPointer(_wm.dpy, XCB_CURRENT_TIME);
Monitor *m;
Expand All @@ -403,6 +413,8 @@ DragWindow(

arrange(_wm.selmon->desksel);
XCBFlush(_wm.dpy);

/* No unlock as lock previous state was locked, (aka no double lock) */
}

void
Expand Down Expand Up @@ -573,10 +585,15 @@ ResizeWindow(const Arg *arg)
ev = NULL;
XCBMotionNotifyEvent *mev = NULL;
XCBTimestamp lasttime = 0;

/* Unlock as was previous locked */
UNLOCK_WM();

do
{
if(ev)
{
LOCK_WM();
eventhandler(ev);
switch(XCB_EVENT_RESPONSE_TYPE(ev))
{
Expand Down Expand Up @@ -637,9 +654,14 @@ ResizeWindow(const Arg *arg)
}
break;
}
UNLOCK_WM();
free(ev);
}
} while(_wm.running && running && !XCBNextEvent(_wm.dpy, &ev));

/* relock to prevent race conditions */
LOCK_WM();

running = 0;
XCBUngrabPointer(_wm.dpy, XCB_CURRENT_TIME);
Monitor *m;
Expand All @@ -658,6 +680,7 @@ ResizeWindow(const Arg *arg)
}
arrange(_wm.selmon->desksel);
XCBFlush(_wm.dpy);
/* No unlock as lock previous state was locked, (aka no double lock) */
}

void
Expand Down Expand Up @@ -793,10 +816,14 @@ ResizeWindowAlt(const Arg *arg)
running = 1;
ev = NULL;
XCBMotionNotifyEvent *mev = NULL;

/* Unlock as was previous locked */
UNLOCK_WM();
do
{
if(ev)
{
LOCK_WM();
eventhandler(ev);
switch(XCB_EVENT_RESPONSE_TYPE(ev))
{
Expand Down Expand Up @@ -839,9 +866,14 @@ ResizeWindowAlt(const Arg *arg)
}
break;
}
UNLOCK_WM();
free(ev);
}
} while(_wm.running && running && !XCBNextEvent(_wm.dpy, &ev));

/* relock to prevent race conditions */
LOCK_WM();

running = 0;
XCBUngrabPointer(_wm.dpy, XCB_CURRENT_TIME);
Monitor *m;
Expand All @@ -860,6 +892,7 @@ ResizeWindowAlt(const Arg *arg)
}
arrange(_wm.selmon->desksel);
XCBFlush(_wm.dpy);
/* No unlock as lock previous state was locked, (aka no double lock) */
}


Expand Down Expand Up @@ -918,7 +951,11 @@ SpawnWindow(const Arg *arg)
perror("setsid");
_exit(EXIT_FAILURE);
}


close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);

sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sa.sa_handler = SIG_DFL;
Expand Down
7 changes: 7 additions & 0 deletions tools/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <stdint.h>
#include <stdio.h>

#include "safebool.h"

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
Expand All @@ -16,6 +18,11 @@ typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;

typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

typedef int8_t byte;
typedef uint8_t ubyte;

Expand Down