Created
September 26, 2020 21:42
-
-
Save nikp123/3cb64ede0982c73728ff22d9c6922580 to your computer and use it in GitHub Desktop.
FIxes a dumb wallpaper bug when using i3 with MATE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <X11/X.h> | |
#include <X11/Xlib.h> | |
#include <X11/extensions/Xrandr.h> | |
static XEvent xEvent; | |
static Display *XDisplay; | |
static Screen *XScreen; | |
static Window XRoot; | |
static Bool xavaSupportsRR; | |
static int xavaRREventBase; | |
static int XScreenNumber; | |
int init_window_x(void) { | |
// connect to the X server | |
XDisplay = XOpenDisplay(NULL); | |
if(XDisplay == NULL) { | |
fprintf(stderr, "cannot open X display\n"); | |
return 1; | |
} | |
XScreen = DefaultScreenOfDisplay(XDisplay); | |
XScreenNumber = DefaultScreen(XDisplay); | |
XRoot = RootWindow(XDisplay, XScreenNumber); | |
XStoreName(XDisplay, XRoot, "Dumb wallpaper fixer 9000"); | |
XSelectInput(XDisplay, XRoot, RRScreenChangeNotifyMask | VisibilityChangeMask | StructureNotifyMask | ExposureMask | KeyPressMask | KeymapNotify); | |
// query for the RR extension in X11 | |
int error; | |
xavaSupportsRR = XRRQueryExtension(XDisplay, &xavaRREventBase, &error); | |
if(xavaSupportsRR) { | |
int rr_major, rr_minor; | |
if(XRRQueryVersion(XDisplay, &rr_major, &rr_minor)) { | |
int rr_mask = RRScreenChangeNotifyMask; | |
if(rr_major == 1 && rr_minor <= 1) { | |
rr_mask &= ~(RRCrtcChangeNotifyMask | | |
RROutputChangeNotifyMask | | |
RROutputPropertyNotifyMask); | |
} | |
// listen for display configure events only if enabled | |
XRRSelectInput(XDisplay, XRoot, rr_mask); | |
} | |
} | |
return 0; | |
} | |
void draw_graphical_x(void) { | |
XSync(XDisplay, 0); | |
return; | |
} | |
void cleanup_graphical_x(void) { | |
// make sure that all events are dead by this point | |
XSync(XDisplay, 1); | |
XCloseDisplay(XDisplay); | |
return; | |
} | |
int main(int argc, char *argv[]) { | |
init_window_x(); | |
while(1) { | |
XNextEvent(XDisplay, &xEvent); | |
if(xEvent.type == xavaRREventBase + RRScreenChangeNotify) { | |
printf("Display change detected - Fixing wallpaper...\n"); | |
// this is done by simply toggling it off and on | |
system("gsettings set org.mate.background draw-background false"); | |
system("gsettings set org.mate.background draw-background true"); | |
} | |
draw_graphical_x(); | |
} | |
// this is never run, lol | |
cleanup_graphical_x(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment