Skip to content

Commit

Permalink
ppb_flash_fullscreen: add config options for fullscreen window geometry
Browse files Browse the repository at this point in the history
If there is no window manager, nobody will interpret WM hints.
  • Loading branch information
i-rinat committed Jun 15, 2018
1 parent ce233f6 commit 2f9b5cc
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 9 deletions.
4 changes: 4 additions & 0 deletions data/freshwrapper.conf.example
Expand Up @@ -65,6 +65,10 @@ fullscreen_height = 0
fullscreen_horz_maximize_atom = 1
fullscreen_vert_maximize_atom = 1

# When set, forces full screen window to have exact position and size.
# Separated by commas: left, top, width, height.
# fullscreen_window_geometry = "0,0,1920,1080"

# Enables DNS query case randomization to partially protect against DNS
# poisoning attacks. It was reported that some Mikrotik routers do not
# support this trick. Set parameter to 0 if you have an affected model
Expand Down
3 changes: 3 additions & 0 deletions src/config.c
Expand Up @@ -48,6 +48,7 @@ static struct fpp_config_s default_config = {
.fullscreen_height = 0,
.fullscreen_horz_maximize_atom = 1,
.fullscreen_vert_maximize_atom = 1,
.fullscreen_window_geometry = NULL,
.randomize_dns_case = 0,
.device_scale = 1.0,
.enable_windowed_mode = 1,
Expand Down Expand Up @@ -90,6 +91,7 @@ static cfg_opt_t opts[] = {
CFG_SIMPLE_INT("fullscreen_height", &config.fullscreen_height),
CFG_SIMPLE_INT("fullscreen_horz_maximize_atom", &config.fullscreen_horz_maximize_atom),
CFG_SIMPLE_INT("fullscreen_vert_maximize_atom", &config.fullscreen_vert_maximize_atom),
CFG_SIMPLE_STR("fullscreen_window_geometry", &config.fullscreen_window_geometry),
CFG_SIMPLE_INT("randomize_dns_case", &config.randomize_dns_case),
CFG_SIMPLE_FLOAT("device_scale", &config.device_scale),
CFG_SIMPLE_INT("enable_windowed_mode", &config.enable_windowed_mode),
Expand Down Expand Up @@ -239,6 +241,7 @@ fpp_config_destroy(void)
FREE_IF_CHANGED(pepperflash_path);
FREE_IF_CHANGED(flash_command_line);
FREE_IF_CHANGED(jack_server_name);
FREE_IF_CHANGED(fullscreen_window_geometry);
g_free(pepper_data_dir);
g_free(pepper_salt_file_name);
initialized = 0;
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Expand Up @@ -40,6 +40,7 @@ struct fpp_config_s {
int fullscreen_height;
int fullscreen_horz_maximize_atom;
int fullscreen_vert_maximize_atom;
char *fullscreen_window_geometry;
int randomize_dns_case;
double device_scale;
int enable_windowed_mode;
Expand Down
57 changes: 48 additions & 9 deletions src/ppb_flash_fullscreen.c
Expand Up @@ -223,6 +223,31 @@ craft_graphicsexpose_event(XEvent *ev, Display *dpy, struct pp_instance_s *pp_i)
ev->xgraphicsexpose.height = pp_i->fs_height;
}

static int
get_window_geometry_from_string(const char *str, struct PP_Rect *out)
{
struct PP_Rect res = {};

gchar **parts = g_strsplit(str, ",", -1);
unsigned int n = 0;
for (gchar **ptr = parts; *ptr != NULL; ptr++)
n += 1;

if (n < 4) {
g_strfreev(parts);
return -1;
}

res.point.x = MIN(G_MAXINT32, g_ascii_strtoull(parts[0], NULL, 10));
res.point.y = MIN(G_MAXINT32, g_ascii_strtoull(parts[1], NULL, 10));
res.size.width = MIN(G_MAXINT32, g_ascii_strtoull(parts[2], NULL, 10));
res.size.height = MIN(G_MAXINT32, g_ascii_strtoull(parts[3], NULL, 10));

g_strfreev(parts);
*out = res;
return 0;
}

static
void
fullscreen_window_thread_int(Display *dpy, struct thread_param_s *tp)
Expand All @@ -240,15 +265,29 @@ fullscreen_window_thread_int(Display *dpy, struct thread_param_s *tp)
// get current mouse pointer position
XQueryPointer(dpy, DefaultRootWindow(dpy), &root, &child, &px, &py, &rel_x, &rel_y, &mask);

// create tiny window where mouse pointer is
// Create a window for the fullscreen content. By default, it's a small window just under
// mouse cursor. That hint a window manager on which monitor to expand the window.
struct PP_Rect fs_wnd_rect = {
.point = {.x = px - wnd_size / 2, .y = py - wnd_size / 2},
.size = {.width = wnd_size, .height = wnd_size},
};

if (config.fullscreen_window_geometry != NULL)
get_window_geometry_from_string(config.fullscreen_window_geometry, &fs_wnd_rect);

printf("fs_wnd_rect: %d %d %d %d\n", fs_wnd_rect.point.x,
fs_wnd_rect.point.y, fs_wnd_rect.size.width, fs_wnd_rect.size.height);

XSetWindowAttributes attrs = {
.background_pixel = 0x000000,
.backing_store = Always,
};
pp_i->fs_wnd = XCreateWindow(dpy, DefaultRootWindow(dpy),
px - wnd_size / 2, py - wnd_size / 2, wnd_size, wnd_size,
0, DefaultDepth(dpy, screen), InputOutput,
DefaultVisual(dpy, screen), CWBackPixel | CWBackingStore, &attrs);

pp_i->fs_wnd = XCreateWindow(
dpy, DefaultRootWindow(dpy), fs_wnd_rect.point.x, fs_wnd_rect.point.y,
fs_wnd_rect.size.width, fs_wnd_rect.size.height, 0,
DefaultDepth(dpy, screen), InputOutput, DefaultVisual(dpy, screen),
CWBackPixel | CWBackingStore, &attrs);

XSelectInput(dpy, pp_i->fs_wnd, KeyPressMask | KeyReleaseMask | ButtonPressMask |
ButtonReleaseMask | PointerMotionMask | ExposureMask |
Expand All @@ -257,8 +296,8 @@ fullscreen_window_thread_int(Display *dpy, struct thread_param_s *tp)
// tell window manager we want exact position
XSizeHints size_hints = {
.flags = USPosition,
.x = px - wnd_size / 2,
.y = py - wnd_size / 2,
.x = fs_wnd_rect.point.x,
.y = fs_wnd_rect.point.y,
};
XSetWMNormalHints(dpy, pp_i->fs_wnd, &size_hints);

Expand Down Expand Up @@ -338,8 +377,8 @@ fullscreen_window_thread_int(Display *dpy, struct thread_param_s *tp)

pthread_mutex_lock(&display.lock);
pp_i->is_fullscreen = 1;
pp_i->fs_width_current = wnd_size;
pp_i->fs_height_current = wnd_size;
pp_i->fs_width_current = fs_wnd_rect.size.width;
pp_i->fs_height_current = fs_wnd_rect.size.height;
pthread_mutex_unlock(&display.lock);

int called_did_change_view = 0;
Expand Down

0 comments on commit 2f9b5cc

Please sign in to comment.