Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to hide and unhide OS-level window (X11) #741

Closed
diovudau opened this issue Nov 11, 2022 · 4 comments
Closed

How to hide and unhide OS-level window (X11) #741

diovudau opened this issue Nov 11, 2022 · 4 comments

Comments

@diovudau
Copy link

Hello,

I want to hide and unhide the complete program window. The program is controlled through an external MIDI controller, directly connected to the program, which sends the signals to hide and show. I am personally on X11 where this is called Unmap() and Map(), but other OSes need something else of course.

I would need to access the following functions, but I don't want to edit the library source files themselves.

_SOKOL_PRIVATE bool _sapp_x11_window_visible(void)
_SOKOL_PRIVATE void _sapp_x11_show_window(void)
_SOKOL_PRIVATE void _sapp_x11_hide_window(void)

Any recommendations how to do this?

@floooh
Copy link
Owner

floooh commented Nov 12, 2022

Hmm, interesting, _sapp_x11_hide_window() doesn't seem to be called anywhere... I wonder why I don't get a warning for an unused static function there... but anyway:

The X11 backend is currently missing public functions to expose the relevant X11 handles (similar to sapp_win32_get_hwnd(), for X11 that would be sapp_x11_get_display() and sapp_x11_get_window(), that way you could implement the missing features yourself outside of sokol_app.h).

But there's also a handy workaround to access the 'private' implementation code, you can create an 'extension header' which must be included after the implementation of sokol_app.h, and which "re-exports" additional functions (or you can write entirely new functions which can access the global _sapp state object), for instance let's say the following header is called sokol_app_ext.h:

#pragma once 

// new public function declarations
bool sapp_x11_window_visible(void);
void sapp_x11_show_window(void);
void sapp_x11_hide_window(void);

#if defined(SOKOL_APP_IMPL)
#if defined(_SAPP_LINUX)

// "re-export" private functions
bool sapp_x11_window_visible(void0 {
    return _sapp_x11_window_visible();
}

void sapp_x11_show_window(void) {
    _sapp_x11_show_window();
}

void sapp_x11_hide_window(void) {
    _sapp_x11_hide_window();
}

#endif // _SAPP_LINUX
#endif // SOKOL_APP_IMPL

...and then in the place where you include the sokol_app.h implementation, include this header after sokol_app.h:

#define SOKOL_APP_IMPL
#include "sokol_app.h"
#include "sokol_app_ext.h"

...and anywhere else where you need to access that new functionality, include the sokol_app_ext.h header (if the declarations depend on public sokol_app.h types, also after including sokol_app.h):

#include "sokol_app.h"
#include "sokol_app_ext.h"

void bla(void) {
    if (sapp_x11_window_visible()) {
        sapp_x11_hide_window();
    }
    else {
        sapp_x11_show_window();
    }
}

@floooh
Copy link
Owner

floooh commented Nov 12, 2022

PS: providing more window manipulation functions in sokol_app.h is still on the menu (taken from the abandondend multiwindow-branch), even if multi-window-support most likely won't happen anytime soon.

@diovudau
Copy link
Author

I tested it with the minimal sokol example from your README and it works. Thanks!

Integrating it into my real program has to wait, because I need to learn Sokol for real first :)
I fell victim to the lure of convenience and started development with https://github.com/pplux/imgui-app .
The method you described here will not work with that. And it's hardcoded to imgui+sokol. I take this as opportunity to try nuklear as well.

@floooh
Copy link
Owner

floooh commented Nov 13, 2022

You can also have a look at my own minimal ImGui 'starter kit', it's using the cimgui C-API wrapper, but that can easily be kicked out if you favour the Dear ImGui C++ APIs: https://github.com/floooh/cimgui-sokol-starterkit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants