aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2019-07-12 21:45:40 +0100
committerHarry Jeffery <harry@exec64.co.uk>2019-07-12 21:45:40 +0100
commitd4bb4bd6437fa4222e5de38671d1fe9b5dc5c716 (patch)
treec32cbac6825d7fd6fcd2544ad2de53b380573de8 /src
parent3200b8f9db552db31fa90411c1ce7f851832d01c (diff)
downloadimv-d4bb4bd6437fa4222e5de38671d1fe9b5dc5c716.tar.gz
Fullscreen support
Diffstat (limited to 'src')
-rw-r--r--src/imv.c36
-rw-r--r--src/window.c30
-rw-r--r--src/window.h4
3 files changed, 37 insertions, 33 deletions
diff --git a/src/imv.c b/src/imv.c
index b5bd933..b81d9a8 100644
--- a/src/imv.c
+++ b/src/imv.c
@@ -92,8 +92,8 @@ struct imv {
/* indicates a new image is being loaded */
bool loading;
- /* fullscreen state */
- bool fullscreen;
+ /* initial fullscreen state */
+ bool start_fullscreen;
/* initial window dimensions */
int initial_width;
@@ -105,9 +105,6 @@ struct imv {
/* method for scaling up images: interpolate or nearest neighbour */
enum upscaling_method upscaling_method;
- /* for multiple monitors, should we stay fullscreen if we lose focus? */
- bool stay_fullscreen_on_focus_loss;
-
/* dirty state flags */
bool need_redraw;
bool need_rescale;
@@ -776,7 +773,7 @@ bool imv_parse_args(struct imv *imv, int argc, char **argv)
/* TODO getopt_long */
while ((o = getopt(argc, argv, "frdwWxhvlu:s:n:b:t:")) != -1) {
switch(o) {
- case 'f': imv->fullscreen = true; break;
+ case 'f': imv->start_fullscreen = true; break;
case 'r': imv->recursive_load = true; break;
case 'd': imv->overlay_enabled = true; break;
case 'w': imv->resize_mode = RESIZE_ONLY; break;
@@ -1091,10 +1088,6 @@ static bool setup_window(struct imv *imv)
return false;
}
- /* allow fullscreen to be maintained even when focus is lost */
- /* glfwWindowHint(GLFW_AUTO_ICONIFY, */
- /* imv->stay_fullscreen_on_focus_loss ? GLFW_FALSE : GLFW_TRUE); */
-
{
int ww, wh, bw, bh;
imv_window_get_size(imv->window, &ww, &wh);
@@ -1103,11 +1096,7 @@ static bool setup_window(struct imv *imv)
}
/* put us in fullscren mode to begin with if requested */
- if (imv->fullscreen) {
- /* GLFWmonitor* monitor = glfwGetPrimaryMonitor(); */
- /* const GLFWvidmode* mode = glfwGetVideoMode(monitor); */
- /* glfwSetWindowMonitor(imv->window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate); */
- }
+ imv_window_set_fullscreen(imv->window, imv->start_fullscreen);
{
imv->keyboard = imv_keyboard_create();
@@ -1328,7 +1317,7 @@ static int handle_ini_value(void *user, const char *section, const char *name,
if (!strcmp(section, "options")) {
if (!strcmp(name, "fullscreen")) {
- imv->fullscreen = parse_bool(value);
+ imv->start_fullscreen = parse_bool(value);
return 1;
}
@@ -1354,11 +1343,6 @@ static int handle_ini_value(void *user, const char *section, const char *name,
return parse_upscaling_method(imv, value);
}
- if (!strcmp(name, "stay_fullscreen_on_focus_loss")) {
- imv->stay_fullscreen_on_focus_loss = parse_bool(value);
- return 1;
- }
-
if (!strcmp(name, "recursive")) {
imv->recursive_load = parse_bool(value);
return 1;
@@ -1561,15 +1545,7 @@ static void command_fullscreen(struct list *args, const char *argstr, void *data
(void)argstr;
struct imv *imv = data;
- /* if (glfwGetWindowMonitor(imv->window)) { */
- /* glfwSetWindowMonitor(imv->window, NULL, 0, 0, imv->initial_width, imv->initial_height, GLFW_DONT_CARE); */
- /* imv->fullscreen = false; */
- /* } else { */
- /* GLFWmonitor* monitor = glfwGetPrimaryMonitor(); */
- /* const GLFWvidmode* mode = glfwGetVideoMode(monitor); */
- /* glfwSetWindowMonitor(imv->window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate); */
- /* imv->fullscreen = true; */
- /* } */
+ imv_window_set_fullscreen(imv->window, !imv_window_is_fullscreen(imv->window));
}
static void command_overlay(struct list *args, const char *argstr, void *data)
diff --git a/src/window.c b/src/window.c
index c330f84..34c5da1 100644
--- a/src/window.c
+++ b/src/window.c
@@ -1,10 +1,10 @@
#include "window.h"
#include <assert.h>
-#include <stdlib.h>
+#include <pthread.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
-#include <pthread.h>
#include <wayland-client.h>
#include <wayland-egl.h>
@@ -30,6 +30,7 @@ struct imv_window {
int width;
int height;
+ bool fullscreen;
int scale;
struct {
@@ -84,7 +85,9 @@ static void keyboard_key(void *data, struct wl_keyboard *keyboard,
uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
{
(void)serial;
+ (void)keyboard;
(void)time;
+
struct imv_window *window = data;
struct imv_event e = {
.type = IMV_EVENT_KEYBOARD,
@@ -215,11 +218,18 @@ static void toplevel_configure(void *data, struct xdg_toplevel *toplevel,
int width, int height, struct wl_array *states)
{
(void)toplevel;
- (void)states;
struct imv_window *window = data;
window->width = width;
window->height = height;
+ window->fullscreen = false;
+
+ enum xdg_toplevel_state *state;
+ wl_array_for_each(state, states) {
+ if (*state == XDG_TOPLEVEL_STATE_FULLSCREEN) {
+ window->fullscreen = true;
+ }
+ }
wl_egl_window_resize(window->egl_window, width, height, 0, 0);
struct imv_event e = {
@@ -370,6 +380,20 @@ void imv_window_set_title(struct imv_window *window, const char *title)
xdg_toplevel_set_title(window->wl_xdg_toplevel, title);
}
+bool imv_window_is_fullscreen(struct imv_window *window)
+{
+ return window->fullscreen;
+}
+
+void imv_window_set_fullscreen(struct imv_window *window, bool fullscreen)
+{
+ if (window->fullscreen && !fullscreen) {
+ xdg_toplevel_unset_fullscreen(window->wl_xdg_toplevel);
+ } else if (!window->fullscreen && fullscreen) {
+ xdg_toplevel_set_fullscreen(window->wl_xdg_toplevel, NULL);
+ }
+}
+
void imv_window_present(struct imv_window *window)
{
eglSwapBuffers(window->egl_display, window->egl_surface);
diff --git a/src/window.h b/src/window.h
index 0973049..be85a26 100644
--- a/src/window.h
+++ b/src/window.h
@@ -48,6 +48,10 @@ void imv_window_get_framebuffer_size(struct imv_window *window, int *w, int *h);
void imv_window_set_title(struct imv_window *window, const char *title);
+bool imv_window_is_fullscreen(struct imv_window *window);
+
+void imv_window_set_fullscreen(struct imv_window *window, bool fullscreen);
+
void imv_window_present(struct imv_window *window);
void imv_window_resize(struct imv_window *window, int w, int h);