mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
Fullscreen toggling
This commit is contained in:
parent
b59d5a2887
commit
478a28bb77
@ -76,7 +76,9 @@ x11GraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe,
|
|||||||
_xwindow = (Window)NULL;
|
_xwindow = (Window)NULL;
|
||||||
_ic = (XIC)NULL;
|
_ic = (XIC)NULL;
|
||||||
_visual_info = NULL;
|
_visual_info = NULL;
|
||||||
|
#ifdef HAVE_XRANDR
|
||||||
_orig_size_id = -1;
|
_orig_size_id = -1;
|
||||||
|
#endif
|
||||||
_awaiting_configure = false;
|
_awaiting_configure = false;
|
||||||
_dga_mouse_enabled = false;
|
_dga_mouse_enabled = false;
|
||||||
_wm_delete_window = x11_pipe->_wm_delete_window;
|
_wm_delete_window = x11_pipe->_wm_delete_window;
|
||||||
@ -448,40 +450,88 @@ set_properties_now(WindowProperties &properties) {
|
|||||||
x11GraphicsPipe *x11_pipe;
|
x11GraphicsPipe *x11_pipe;
|
||||||
DCAST_INTO_V(x11_pipe, _pipe);
|
DCAST_INTO_V(x11_pipe, _pipe);
|
||||||
|
|
||||||
// A coordinate of -2 means to center the window on screen.
|
// Handle fullscreen mode.
|
||||||
if (properties.has_origin() && (properties.get_x_origin() == -2
|
|
||||||
|| properties.get_y_origin() == -2)) {
|
|
||||||
int x_origin = properties.get_x_origin();
|
|
||||||
int y_origin = properties.get_y_origin();
|
|
||||||
if (properties.has_size()) {
|
|
||||||
if (x_origin == -2) {
|
|
||||||
x_origin = 0.5 * (x11_pipe->get_display_width() - properties.get_x_size());
|
|
||||||
}
|
|
||||||
if (y_origin == -2) {
|
|
||||||
y_origin = 0.5 * (x11_pipe->get_display_height() - properties.get_y_size());
|
|
||||||
}
|
|
||||||
properties.set_origin(x_origin, y_origin);
|
|
||||||
} else {
|
|
||||||
// I'm not sure what to do in this case, when no size is specified.
|
|
||||||
// Using XGetGeometry results for me in a BadDrawable here.
|
|
||||||
// I guess we can just ignore this case (when no size is specified).
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fullscreen mode is implemented with a hint to the window manager.
|
|
||||||
// However, we also implicitly set the origin to (0, 0) and request
|
|
||||||
// undecorated mode, in case the user has a less-capable
|
|
||||||
// window manager (or no window manager at all).
|
|
||||||
if (properties.has_fullscreen()) {
|
if (properties.has_fullscreen()) {
|
||||||
if (properties.get_fullscreen()) {
|
if (properties.get_fullscreen()) {
|
||||||
properties.set_undecorated(true);
|
|
||||||
properties.set_origin(0, 0);
|
properties.set_origin(0, 0);
|
||||||
#ifndef HAVE_XRANDR
|
#ifdef HAVE_XRANDR
|
||||||
|
XRRScreenConfiguration* conf = XRRGetScreenInfo(_display, x11_pipe->get_root());
|
||||||
|
if (_orig_size_id == (SizeID) -1) {
|
||||||
|
_orig_size_id = XRRConfigCurrentConfiguration(conf, &_orig_rotation);
|
||||||
|
}
|
||||||
|
int num_sizes, reqsizex, reqsizey, new_size_id = -1;
|
||||||
|
if (properties.has_size()) {
|
||||||
|
reqsizex = properties.get_x_size();
|
||||||
|
reqsizey = properties.get_y_size();
|
||||||
|
} else {
|
||||||
|
reqsizex = _properties.get_x_size();
|
||||||
|
reqsizey = _properties.get_y_size();
|
||||||
|
}
|
||||||
|
XRRScreenSize *xrrs;
|
||||||
|
xrrs = XRRSizes(_display, 0, &num_sizes);
|
||||||
|
for (int i = 0; i < num_sizes; ++i) {
|
||||||
|
if (xrrs[i].width == properties.get_x_size() &&
|
||||||
|
xrrs[i].height == properties.get_y_size()) {
|
||||||
|
new_size_id = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (new_size_id == -1) {
|
||||||
|
x11display_cat.error()
|
||||||
|
<< "Videocard has no supported display resolutions at specified res ("
|
||||||
|
<< reqsizex << " x " << reqsizey <<")\n";
|
||||||
|
_orig_size_id = -1;
|
||||||
|
}
|
||||||
|
if (new_size_id != _orig_size_id) {
|
||||||
|
XRRSetScreenConfig(_display, conf, x11_pipe->get_root(), new_size_id, _orig_rotation, CurrentTime);
|
||||||
|
_properties.set_fullscreen(true);
|
||||||
|
properties.clear_fullscreen();
|
||||||
|
} else {
|
||||||
|
_orig_size_id = -1;
|
||||||
|
_properties.set_fullscreen(true);
|
||||||
|
properties.clear_fullscreen();
|
||||||
|
}
|
||||||
|
#else
|
||||||
// If we don't have Xrandr support, we fake the fullscreen
|
// If we don't have Xrandr support, we fake the fullscreen
|
||||||
// support by setting the window size to the desktop size.
|
// support by setting the window size to the desktop size.
|
||||||
properties.set_size(x11_pipe->get_display_width(),
|
properties.set_size(x11_pipe->get_display_width(),
|
||||||
x11_pipe->get_display_height());
|
x11_pipe->get_display_height());
|
||||||
#endif
|
#endif
|
||||||
|
} else {
|
||||||
|
#ifdef HAVE_XRANDR
|
||||||
|
// Change the resolution back to what it was.
|
||||||
|
// Don't remove the SizeID typecast!
|
||||||
|
if (_orig_size_id != (SizeID) -1) {
|
||||||
|
XRRScreenConfiguration* conf = XRRGetScreenInfo(_display, x11_pipe->get_root());
|
||||||
|
XRRSetScreenConfig(_display, conf, x11_pipe->get_root(), _orig_size_id, _orig_rotation, CurrentTime);
|
||||||
|
_orig_size_id = -1;
|
||||||
|
}
|
||||||
|
_properties.set_fullscreen(false);
|
||||||
|
properties.clear_fullscreen();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (properties.has_origin()) {
|
||||||
|
// A coordinate of -2 means to center the window on screen.
|
||||||
|
if (properties.get_x_origin() == -2 || properties.get_y_origin() == -2) {
|
||||||
|
int x_origin = properties.get_x_origin();
|
||||||
|
int y_origin = properties.get_y_origin();
|
||||||
|
if (properties.has_size()) {
|
||||||
|
if (x_origin == -2) {
|
||||||
|
x_origin = 0.5 * (x11_pipe->get_display_width() - properties.get_x_size());
|
||||||
|
}
|
||||||
|
if (y_origin == -2) {
|
||||||
|
y_origin = 0.5 * (x11_pipe->get_display_height() - properties.get_y_size());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (x_origin == -2) {
|
||||||
|
x_origin = 0.5 * (x11_pipe->get_display_width() - _properties.get_x_size());
|
||||||
|
}
|
||||||
|
if (y_origin == -2) {
|
||||||
|
y_origin = 0.5 * (x11_pipe->get_display_height() - _properties.get_y_size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
properties.set_origin(x_origin, y_origin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -505,12 +555,6 @@ set_properties_now(WindowProperties &properties) {
|
|||||||
properties.clear_title();
|
properties.clear_title();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ditto for fullscreen mode.
|
|
||||||
if (properties.has_fullscreen()) {
|
|
||||||
_properties.set_fullscreen(properties.get_fullscreen());
|
|
||||||
properties.clear_fullscreen();
|
|
||||||
}
|
|
||||||
|
|
||||||
// The size and position of an already-open window are changed via
|
// The size and position of an already-open window are changed via
|
||||||
// explicit X calls. These may still get intercepted by the window
|
// explicit X calls. These may still get intercepted by the window
|
||||||
// manager. Rather than changing _properties immediately, we'll
|
// manager. Rather than changing _properties immediately, we'll
|
||||||
@ -525,12 +569,14 @@ set_properties_now(WindowProperties &properties) {
|
|||||||
if (changes.y != -1) value_mask |= CWY;
|
if (changes.y != -1) value_mask |= CWY;
|
||||||
properties.clear_origin();
|
properties.clear_origin();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (properties.has_size()) {
|
if (properties.has_size()) {
|
||||||
changes.width = properties.get_x_size();
|
changes.width = properties.get_x_size();
|
||||||
changes.height = properties.get_y_size();
|
changes.height = properties.get_y_size();
|
||||||
value_mask |= (CWWidth | CWHeight);
|
value_mask |= (CWWidth | CWHeight);
|
||||||
properties.clear_size();
|
properties.clear_size();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (properties.has_z_order()) {
|
if (properties.has_z_order()) {
|
||||||
// We'll send the classic stacking request through the standard
|
// We'll send the classic stacking request through the standard
|
||||||
// interface, for users of primitive window managers; but we'll
|
// interface, for users of primitive window managers; but we'll
|
||||||
@ -678,10 +724,19 @@ close_window() {
|
|||||||
// Change the resolution back to what it was.
|
// Change the resolution back to what it was.
|
||||||
// Don't remove the SizeID typecast!
|
// Don't remove the SizeID typecast!
|
||||||
if (_orig_size_id != (SizeID) -1) {
|
if (_orig_size_id != (SizeID) -1) {
|
||||||
x11GraphicsPipe *x11_pipe;
|
Window root;
|
||||||
DCAST_INTO_V(x11_pipe, _pipe);
|
if (_pipe != NULL) {
|
||||||
XRRScreenConfiguration* conf = XRRGetScreenInfo(_display, x11_pipe->get_root());
|
x11GraphicsPipe *x11_pipe;
|
||||||
XRRSetScreenConfig(_display, conf, x11_pipe->get_root(), _orig_size_id, _orig_rotation, CurrentTime);
|
DCAST_INTO_V(x11_pipe, _pipe);
|
||||||
|
root = x11_pipe->get_root();
|
||||||
|
} else {
|
||||||
|
// Oops. Looks like the pipe was destroyed
|
||||||
|
// before the window gets closed. Oh well,
|
||||||
|
// let's get the root window by ourselves.
|
||||||
|
root = RootWindow(_display, _screen);
|
||||||
|
}
|
||||||
|
XRRScreenConfiguration* conf = XRRGetScreenInfo(_display, root);
|
||||||
|
XRRSetScreenConfig(_display, conf, root, _orig_size_id, _orig_rotation, CurrentTime);
|
||||||
_orig_size_id = -1;
|
_orig_size_id = -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -716,10 +771,11 @@ open_window() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_XRANDR
|
#ifdef HAVE_XRANDR
|
||||||
_orig_size_id = -1;
|
|
||||||
if (_properties.get_fullscreen()) {
|
if (_properties.get_fullscreen()) {
|
||||||
XRRScreenConfiguration* conf = XRRGetScreenInfo(_display, x11_pipe->get_root());
|
XRRScreenConfiguration* conf = XRRGetScreenInfo(_display, x11_pipe->get_root());
|
||||||
_orig_size_id = XRRConfigCurrentConfiguration(conf, &_orig_rotation);
|
if (_orig_size_id == (SizeID) -1) {
|
||||||
|
_orig_size_id = XRRConfigCurrentConfiguration(conf, &_orig_rotation);
|
||||||
|
}
|
||||||
int num_sizes, new_size_id = -1;
|
int num_sizes, new_size_id = -1;
|
||||||
XRRScreenSize *xrrs;
|
XRRScreenSize *xrrs;
|
||||||
xrrs = XRRSizes(_display, 0, &num_sizes);
|
xrrs = XRRSizes(_display, 0, &num_sizes);
|
||||||
@ -741,7 +797,6 @@ open_window() {
|
|||||||
} else {
|
} else {
|
||||||
_orig_size_id = -1;
|
_orig_size_id = -1;
|
||||||
}
|
}
|
||||||
_properties.set_origin(0, 0);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -82,8 +82,10 @@ protected:
|
|||||||
XIC _ic;
|
XIC _ic;
|
||||||
XVisualInfo *_visual_info;
|
XVisualInfo *_visual_info;
|
||||||
|
|
||||||
|
#ifdef HAVE_XRANDR
|
||||||
Rotation _orig_rotation;
|
Rotation _orig_rotation;
|
||||||
SizeID _orig_size_id;
|
SizeID _orig_size_id;
|
||||||
|
#endif
|
||||||
|
|
||||||
long _event_mask;
|
long _event_mask;
|
||||||
bool _awaiting_configure;
|
bool _awaiting_configure;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user