Created
February 21, 2012 00:54
-
-
Save shurizzle/1872646 to your computer and use it in GitHub Desktop.
Don't blank, power off (or w/e) the screen while flash is playing in fullscreen
This file contains 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 <stdlib.h> | |
#include <string.h> | |
#include <X11/Xlib.h> | |
#include <stdio.h> | |
#define WINDOW_PROPERTY(prop) XGetWindowProperty(dpy,\ | |
w,\ | |
XInternAtom(dpy, (prop), True),\ | |
0,\ | |
(~0L),\ | |
False,\ | |
AnyPropertyType,\ | |
&actual_type,\ | |
&actual_format,\ | |
&nitems,\ | |
&bytes,\ | |
&data) | |
Atom _NET_WM_STATE_FULLSCREEN; | |
#define IS_FIREFOX_FLASH() ((title && !strcmp(title, "plugin-container")) && \ | |
(instance && !strcmp(instance, "plugin-container")) && \ | |
(class && !strcmp(class, "Plugin-container"))) | |
#define IS_CHROMIUM_FLASH() ((title && !strcmp(title, "exe")) && \ | |
(instance && !strcmp(instance, "exe")) && \ | |
(class && !strcmp(class, "Exe"))) | |
#define IS_OPERA_FLASH() ((title && !strcmp(title, "operapluginwrapper-native")) && \ | |
(instance && !strcmp(instance, "operapluginwrapper-native")) && \ | |
(class && !strcmp(class, "Operapluginwrapper-native"))) | |
int | |
is_state_ok(Atom *atoms, | |
unsigned int len) | |
{ | |
unsigned int i; | |
for (i = 0; i < len; ++i) { | |
if (atoms[i] == _NET_WM_STATE_FULLSCREEN) | |
{ | |
return 1; | |
} | |
} | |
return 0; | |
} | |
int | |
is_full_above(Display *dpy, Window w) | |
{ | |
Atom actual_type; | |
int actual_format; | |
unsigned long nitems, bytes; | |
unsigned char *data; | |
if (WINDOW_PROPERTY("_NET_WM_STATE") != Success) | |
return 0; | |
if (!is_state_ok((Atom*)data, nitems)) | |
{ | |
XFree(data); | |
return 0; | |
} else { XFree(data); } | |
return 1; | |
} | |
int | |
is_match(Display *dpy, Window w) | |
{ | |
Atom actual_type; | |
int actual_format; | |
unsigned long nitems, bytes; | |
unsigned char *data; | |
char *title, *instance = NULL, *class = NULL; | |
int res; | |
if (WINDOW_PROPERTY("_NET_WM_NAME") != Success) | |
return 0; | |
title = (char*)data; data = NULL; | |
if (WINDOW_PROPERTY("WM_CLASS") != Success) | |
{ | |
XFree(title); | |
return 0; | |
} | |
if (nitems > 0) | |
instance = (char*)data; | |
if (nitems > 1) | |
class = ((char*)(((unsigned int)data) + strlen((char *)data) + 1)); | |
res = IS_FIREFOX_FLASH() || IS_CHROMIUM_FLASH() || IS_OPERA_FLASH(); | |
XFree(title); | |
XFree(data); | |
return res; | |
} | |
int | |
main(void) | |
{ | |
Display *dpy; | |
XEvent ev; | |
Window flash_win = None, watching_win = None; | |
if (!(dpy = XOpenDisplay(getenv("DISPLAY")))) return 1; | |
XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureNotifyMask); | |
_NET_WM_STATE_FULLSCREEN = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False); | |
for (;;) { | |
XNextEvent(dpy, &ev); | |
if (ev.type == CreateNotify && | |
ev.xcreatewindow.window != None && | |
is_match(dpy, ev.xcreatewindow.window)) | |
{ | |
puts("OPEN"); | |
watching_win = ev.xcreatewindow.window; | |
} | |
else if (ev.type == ClientMessage && | |
flash_win == None && | |
ev.xclient.window != None && | |
ev.xclient.window == watching_win && | |
is_full_above(dpy, ev.xclient.window)) | |
{ | |
flash_win = watching_win; watching_win == None; | |
puts("PROPERTY"); | |
system("xset s off"); | |
system("xset dpms 0 0 0"); | |
} | |
else if (ev.type == DestroyNotify && | |
ev.xdestroywindow.window != None && | |
ev.xdestroywindow.window == flash_win) | |
{ | |
puts("CLOSE"); | |
flash_win = None; | |
system("xset s blank"); | |
system("xset s 600"); | |
system("xset dpms 1200 2400 4800"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment