FDH2 / UxPlay

AirPlay Unix mirroring server
GNU General Public License v3.0
1.35k stars 72 forks source link

add F11 shortcut to toggle into fullscreen mode #150

Closed G3rb closed 1 year ago

G3rb commented 1 year ago

I added a function to toggle into fullscreen mode with F11 (during the stream). Developped on Ubuntu 20.04 (I couldn't test it on win and osx). I used the x_display_fix.h so to activate this function you have to compile with the -DZOOMFIX=ON.

Maybe need to be tested on OSX and Win and to be improved. I'm available to improve it if needed

fduncanh commented 1 year ago

which gstreamer videosinks does this work with? I guess just ximagesink and or xvimagesink?

why is ZOOMFIX needed? can this be separated from ZOOMFIX which is obsolete for GStreamer-1.20 or later?

void set_fullscreen(Display* dpy, Window win, const char * name, bool* fullscreen)

it looks like the reason is that this is X11-specific, and needs to get the Display and window from X?

This uses gst_navigation it seems? this is probably just to register the F11 key press? (why F11? , a Windows driver does it with alt-enter)

So this (below) is the essential code, which needs X11 Display and Window ID's, as in ZOOMFIX. This is X11 specific like ZOOMFIX , so not relevant for MacOS or MS Windows.

// 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);
    }
}
fduncanh commented 1 year ago

I have created a UxPlay branch "x11fullscreen"

Please resubmit/change your Pull request to be against that branch

There are "whitespace" flaws in your PR (extra tabs added, extra blank lines) in places where the code is not changed. can you clean them up.

(Or I can add your changes to the x11fullscreen branch, but then it will not record you as contributor) Thanks

The testing should not be in the main UxPlay branch until its finished, and more changes will be needed first.

fduncanh commented 1 year ago

I got it working in branch "testing". Good work! If you just make a pull request to branch "x11fullscreen", I'll add the cleanups I am making before merging it to "master" branch, if you want your github username associated with it (If not I'll just use the "testing" version).

fduncanh commented 1 year ago

It will need a bit of work to limit response to F11 to when the window is X11. It seems to crash OpenGL windows. I'm looking into it.

EDIT: fixed.

fduncanh commented 1 year ago

The fully integrated and cleaned +adapted patch is in the "testing" branch. Please test it!

https://github.com/FDH2/UxPlay/tree/testing

G3rb commented 1 year ago

which gstreamer videosinks does this work with? I guess just ximagesink and or xvimagesink?

why is ZOOMFIX needed? can this be separated from ZOOMFIX which is obsolete for GStreamer-1.20 or later?

void set_fullscreen(Display* dpy, Window win, const char * name, bool* fullscreen)

it looks like the reason is that this is X11-specific, and needs to get the Display and window from X?

This uses gst_navigation it seems? this is probably just to register the F11 key press? (why F11? , a Windows driver does it with alt-enter)

So this (below) is the essential code, which needs X11 Display and Window ID's, as in ZOOMFIX. This is X11 specific like ZOOMFIX , so not relevant for MacOS or MS Windows.

// 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);
    }
}

Thank you for your consideration. F11 is the default key to "kiosk mode" As you can have on web browsers for example (even in windows). I'm sorry, I am not a C, C++ developper so I did it as I could, it can certainly be cleaner. And this is almost my second contrib to a github project. Maybe I dont push, create my pull request the right way. Sorry.