Skip to content

Commit

Permalink
WIP: RRScreenChangeNotify
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasAdam committed Mar 10, 2018
1 parent 9a69dad commit 7be6062
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
19 changes: 18 additions & 1 deletion fvwm/events.c
Expand Up @@ -101,6 +101,10 @@
#ifdef HAVE_STROKE
#include "stroke.h"
#endif /* HAVE_STROKE */
#ifdef HAVE_XRANDR
#include <X11/extensions/Xrandr.h>
#include "libs/FScreen.h"
#endif

/* ---------------------------- local definitions -------------------------- */

Expand Down Expand Up @@ -1787,6 +1791,13 @@ static void __refocus_stolen_focus_win(const evh_args_t *ea)

/* ---------------------------- event handlers ----------------------------- */

#ifdef HAVE_XRANDR
void HandleRRScreenChangeNotify(XEvent *e)
{
FScreenInit(dpy);
}
#endif

void HandleButtonPress(const evh_args_t *ea)
{
DBUG("HandleButtonPress", "Routine Entered");
Expand Down Expand Up @@ -4089,7 +4100,6 @@ void InitEventHandlerJumpTable(void)
}
}


return;
}

Expand All @@ -4103,6 +4113,13 @@ void dispatch_event(XEvent *e)
DBUG("dispatch_event", "Routine Entered");

XFlush(dpy);

#if HAVE_XRANDR
if (e->type - randr_event == RRScreenChangeNotify) {
HandleRRScreenChangeNotify(e);
}
#endif

if (w == Scr.Root)
{
switch (e->type)
Expand Down
5 changes: 5 additions & 0 deletions fvwm/fvwm.c
Expand Up @@ -2205,7 +2205,12 @@ int main(int argc, char **argv)
g_argv[argc++] = "-s";
g_argv[argc] = NULL;
}

/* Allocate for monitors. */
TAILQ_INIT(&monitor_q);

FScreenInit(dpy);
FScreenSelect(dpy);
x_fd = XConnectionNumber(dpy);

#ifdef HAVE_X11_FD
Expand Down
36 changes: 31 additions & 5 deletions libs/FScreen.c
Expand Up @@ -52,6 +52,7 @@ static struct monitor *monitor_get_current(void);
static struct monitor *monitor_new(void);
static void monitor_create_randr_region(struct monitor *m,
const char *, struct coord *, int);
static int monitor_check_stale(struct monitor *);

static void GetMouseXY(XEvent *eventp, int *x, int *y)
{
Expand Down Expand Up @@ -106,6 +107,12 @@ monitor_by_name(const char *name)
return (NULL);
}

void
FScreenSelect(Display *dpy)
{
XRRSelectInput(disp, DefaultRootWindow(disp), RRScreenChangeNotifyMask);
}

void FScreenInit(Display *dpy)
{
XRRScreenResources *res = NULL;
Expand All @@ -114,15 +121,14 @@ void FScreenInit(Display *dpy)
RROutput rr_output, rr_output_primary;
struct monitor *m;
struct coord coord;
int err_base = 0, event = 0;
int err_base = 0;
int is_randr_present = 0;
int iscres, is_primary = 0;

disp = dpy;
randr_event = 0;

TAILQ_INIT(&monitor_q);

is_randr_present = XRRQueryExtension(dpy, &event, &err_base);
is_randr_present = XRRQueryExtension(dpy, &randr_event, &err_base);

if (FScreenIsEnabled() && !is_randr_present) {
/* Something went wrong. */
Expand Down Expand Up @@ -205,6 +211,9 @@ monitor_create_randr_region(struct monitor *m, const char *name,
name, is_primary ? "(PRIMARY)" : "",
coord->x, coord->y, coord->w, coord->h);

if (monitor_check_stale(m))
free(m->name);

m->name = xstrdup(name);
memcpy(&m->coord, coord, sizeof(*coord));

Expand All @@ -213,8 +222,25 @@ monitor_create_randr_region(struct monitor *m, const char *name,
} else {
TAILQ_INSERT_TAIL(&monitor_q, m, entry);
}
}

XRRSelectInput(disp, DefaultRootWindow(disp), RRScreenChangeNotifyMask);
static int
monitor_check_stale(struct monitor *m)
{
struct monitor *mcheck = NULL;

TAILQ_FOREACH(mcheck, &monitor_q, entry) {
if (m == NULL || mcheck == NULL)
break;
if (m->name == NULL || mcheck->name == NULL) {
/* Shouldn't happen. */
break;
}
if (strcmp(mcheck->name, m->name) == 0)
return (1);
}

return (0);
}

/* Intended to be called by modules. Simply pass in the parameter from the
Expand Down
2 changes: 2 additions & 0 deletions libs/FScreen.h
Expand Up @@ -46,10 +46,12 @@ struct monitor *monitor_by_name(const char *);

#define FSCREEN_MANGLE_USPOS_HINTS_MAGIC ((short)-32109)

int randr_event;

/* Control */
Bool FScreenIsEnabled(void);
void FScreenInit(Display *dpy);
void FScreenSelect(Display *dpy);
/* Intended to be called by modules. Simply pass in the parameter from the
* config string sent by fvwm. */
void FScreenConfigureModule(char *args);
Expand Down

0 comments on commit 7be6062

Please sign in to comment.