Merge pull request #12387 from santouits/x1111

Fix x11 boot logo position in fullscreen and in maximized
This commit is contained in:
Rémi Verschelde 2017-11-20 15:48:08 +01:00 committed by GitHub
commit 450bdda97a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 48 deletions

View file

@ -90,13 +90,15 @@ public:
bool fullscreen; bool fullscreen;
bool resizable; bool resizable;
bool borderless_window; bool borderless_window;
bool maximized;
float get_aspect() const { return (float)width / (float)height; } float get_aspect() const { return (float)width / (float)height; }
VideoMode(int p_width = 1024, int p_height = 600, bool p_fullscreen = false, bool p_resizable = true, bool p_borderless_window = false) { VideoMode(int p_width = 1024, int p_height = 600, bool p_fullscreen = false, bool p_resizable = true, bool p_borderless_window = false, bool p_maximized = false) {
width = p_width; width = p_width;
height = p_height; height = p_height;
fullscreen = p_fullscreen; fullscreen = p_fullscreen;
resizable = p_resizable; resizable = p_resizable;
borderless_window = p_borderless_window; borderless_window = p_borderless_window;
maximized = p_maximized;
} }
}; };

2
main/main.cpp Normal file → Executable file
View file

@ -427,6 +427,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
} else if (I->get() == "-m" || I->get() == "--maximized") { // force maximized window } else if (I->get() == "-m" || I->get() == "--maximized") { // force maximized window
init_maximized = true; init_maximized = true;
video_mode.maximized = true;
} else if (I->get() == "-w" || I->get() == "--windowed") { // force windowed window } else if (I->get() == "-w" || I->get() == "--windowed") { // force windowed window
init_windowed = true; init_windowed = true;
@ -748,6 +749,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
Engine::get_singleton()->set_editor_hint(true); Engine::get_singleton()->set_editor_hint(true);
main_args.push_back("--editor"); main_args.push_back("--editor");
init_maximized = true; init_maximized = true;
video_mode.maximized = true;
use_custom_res = false; use_custom_res = false;
} }

View file

@ -250,41 +250,13 @@ void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD)); visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD));
} }
if (current_videomode.maximized) {
// borderless fullscreen window mode current_videomode.maximized = false;
if (current_videomode.fullscreen) { set_window_maximized(true);
// set bypass compositor hint // borderless fullscreen window mode
Atom bypass_compositor = XInternAtom(x11_display, "_NET_WM_BYPASS_COMPOSITOR", False); } else if (current_videomode.fullscreen) {
unsigned long compositing_disable_on = 1; current_videomode.fullscreen = false;
XChangeProperty(x11_display, x11_window, bypass_compositor, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&compositing_disable_on, 1); set_window_fullscreen(true);
// needed for lxde/openbox, possibly others
Hints hints;
Atom property;
hints.flags = 2;
hints.decorations = 0;
property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True);
XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5);
XMapRaised(x11_display, x11_window);
XWindowAttributes xwa;
XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa);
XMoveResizeWindow(x11_display, x11_window, 0, 0, xwa.width, xwa.height);
// code for netwm-compliants
XEvent xev;
Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False);
Atom fullscreen = XInternAtom(x11_display, "_NET_WM_STATE_FULLSCREEN", False);
memset(&xev, 0, sizeof(xev));
xev.type = ClientMessage;
xev.xclient.window = x11_window;
xev.xclient.message_type = wm_state;
xev.xclient.format = 32;
xev.xclient.data.l[0] = 1;
xev.xclient.data.l[1] = fullscreen;
xev.xclient.data.l[2] = 0;
XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev);
} else if (current_videomode.borderless_window) { } else if (current_videomode.borderless_window) {
Hints hints; Hints hints;
Atom property; Atom property;
@ -467,8 +439,17 @@ void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
_ensure_user_data_dir(); _ensure_user_data_dir();
power_manager = memnew(PowerX11); power_manager = memnew(PowerX11);
XEvent xevent;
while (XCheckIfEvent(x11_display, &xevent, _check_window_events, NULL)) {
_window_changed(&xevent);
}
} }
int OS_X11::_check_window_events(Display *display, XEvent *event, char *arg) {
if (event->type == ConfigureNotify) return 1;
return 0;
}
void OS_X11::xim_destroy_callback(::XIM im, ::XPointer client_data, void OS_X11::xim_destroy_callback(::XIM im, ::XPointer client_data,
::XPointer call_data) { ::XPointer call_data) {
@ -648,6 +629,9 @@ void OS_X11::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) con
} }
void OS_X11::set_wm_fullscreen(bool p_enabled) { void OS_X11::set_wm_fullscreen(bool p_enabled) {
if (current_videomode.fullscreen == p_enabled)
return;
if (p_enabled && !is_window_resizable()) { if (p_enabled && !is_window_resizable()) {
// Set the window as resizable to prevent window managers to ignore the fullscreen state flag. // Set the window as resizable to prevent window managers to ignore the fullscreen state flag.
XSizeHints *xsh; XSizeHints *xsh;
@ -971,6 +955,9 @@ bool OS_X11::is_window_minimized() const {
} }
void OS_X11::set_window_maximized(bool p_enabled) { void OS_X11::set_window_maximized(bool p_enabled) {
if (is_window_maximized() == p_enabled)
return;
// Using EWMH -- Extended Window Manager Hints // Using EWMH -- Extended Window Manager Hints
XEvent xev; XEvent xev;
Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False); Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False);
@ -1417,6 +1404,20 @@ static Atom pick_target_from_atoms(Display *p_disp, Atom p_t1, Atom p_t2, Atom p
return None; return None;
} }
void OS_X11::_window_changed(XEvent *event) {
if (xic) {
// Not portable.
set_ime_position(Point2(0, 1));
}
if ((event->xconfigure.width == current_videomode.width) &&
(event->xconfigure.height == current_videomode.height))
return;
current_videomode.width = event->xconfigure.width;
current_videomode.height = event->xconfigure.height;
}
void OS_X11::process_xevents() { void OS_X11::process_xevents() {
//printf("checking events %i\n", XPending(x11_display)); //printf("checking events %i\n", XPending(x11_display));
@ -1498,18 +1499,7 @@ void OS_X11::process_xevents() {
break; break;
case ConfigureNotify: case ConfigureNotify:
if (xic) { _window_changed(&event);
// Not portable.
set_ime_position(Point2(0, 1));
}
/* call resizeGLScene only if our window-size changed */
if ((event.xconfigure.width == current_videomode.width) &&
(event.xconfigure.height == current_videomode.height))
break;
current_videomode.width = event.xconfigure.width;
current_videomode.height = event.xconfigure.height;
break; break;
case ButtonPress: case ButtonPress:
case ButtonRelease: { case ButtonRelease: {

View file

@ -187,6 +187,9 @@ protected:
virtual void set_main_loop(MainLoop *p_main_loop); virtual void set_main_loop(MainLoop *p_main_loop);
void _window_changed(XEvent *xevent);
static int _check_window_events(Display *display, XEvent *xevent, char *arg);
public: public:
virtual String get_name(); virtual String get_name();