add F11 shortcut to toggle into fullscreen mode

This commit is contained in:
gerbon
2022-12-08 14:26:52 +01:00
committed by F. Duncanh
parent c04987725d
commit 01ae7d580c
2 changed files with 57 additions and 0 deletions

View File

@@ -20,6 +20,7 @@
#include "video_renderer.h"
#include <gst/gst.h>
#include <gst/app/gstappsrc.h>
#include <gst/video/navigation.h>
#ifdef X_DISPLAY_FIX
#include "x_display_fix.h"
@@ -95,6 +96,10 @@ static video_renderer_t *renderer = NULL;
static logger_t *logger = NULL;
static unsigned short width, height, width_source, height_source; /* not currently used */
static bool first_packet = false;
#ifdef X_DISPLAY_FIX
XEvent e;
static bool fullscreen = false;
#endif
/* apple uses colorimetry=1:3:5:1 (not recognized by gstreamer v4l2) *
* See .../gst-libs/gst/video/video-color.h in gst-plugins-base *
@@ -289,6 +294,31 @@ gboolean gstreamer_pipeline_bus_callback(GstBus *bus, GstMessage *message, gpoin
logger_log(logger, LOGGER_INFO, "GStreamer: End-Of-Stream");
// g_main_loop_quit( (GMainLoop *) loop);
break;
#ifdef X_DISPLAY_FIX
case GST_MESSAGE_ELEMENT: ;
GstNavigationMessageType mtype = gst_navigation_message_get_type (message);
if (mtype == GST_NAVIGATION_MESSAGE_EVENT) {
GstEvent *ev = NULL;
if (gst_navigation_message_parse_event (message, &ev)) {
GstNavigationEventType e_type = gst_navigation_event_get_type (ev);
switch (e_type) {
case GST_NAVIGATION_EVENT_KEY_PRESS: ;
const gchar *key;
if (gst_navigation_event_parse_key_event (ev, &key)) {
if (strcmp (key, "F11") == 0)
{
fullscreen = !(fullscreen);
set_fullscreen(renderer->gst_window->display, renderer->gst_window->window, renderer->server_name, &fullscreen);
}
}
break;
default:
break;
}
}
}
break;
#endif
default:
/* unhandled message */
break;

View File

@@ -64,6 +64,33 @@ Window enum_windows(const char * str, Display * display, Window window, int dept
return (Window) NULL;
}
// Fullscreen mod
void set_fullscreen(Display* dpy, Window win, const char * name, bool* fullscreen)
{
// *fullscreen = !(*fullscreen);
XClientMessageEvent msg = {
.type = ClientMessage,
.display = dpy,
.window = win,
.message_type = XInternAtom(dpy, "_NET_WM_STATE", True),
.format = 32,
.data = { .l = {
*fullscreen,
XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", True),
None,
0,
1
}}
};
Window root = XDefaultRootWindow(dpy);
win = enum_windows(name, dpy, root, 0);
if (win) {
XSendEvent(dpy, XRootWindow(dpy, XDefaultScreen(dpy)), False, SubstructureRedirectMask | SubstructureNotifyMask, (XEvent*) &msg);
XSync(dpy, False);
}
}
void fix_x_window_name(X11_Window_t * X11, const char * name) {
Window root = XDefaultRootWindow(X11->display);
X11->window = enum_windows(name, X11->display, root, 0);