A window position of (-1, -1) will mean to let the WM choose a default position, and with (-2, -2) the window will be centered on screen.

This commit is contained in:
rdb 2009-12-16 09:37:43 +00:00
parent 98281d31c6
commit eb16fccbf5
6 changed files with 57 additions and 23 deletions

View File

@ -80,11 +80,14 @@ set_wparams(const P3DWindowParams &wparams) {
Rect r;
r.top = _wparams.get_win_y();
r.left = _wparams.get_win_x();
if (r.top == 0 && r.left == 0) {
// These are the same defaults used by Panda's osxGraphicsWindow.
r.top = 50;
r.left = 10;
}
// These are the same defaults used by Panda's osxGraphicsWindow.
if (r.left == -1) r.left == 10;
if (r.top == -1) r.top == 50;
// A coordinate of -2 means to center the window on the screen.
CGRect display_bounds = CGDisplayBounds(kCGDirectMainDisplay);
if (r.left == -2) r.left == 0.5 * (CGRectGetWidth(display_bounds) - _win_width);
if (r.top == -2) r.top == 0.5 * (CGRectGetHeight(display_bounds) - _win_height);
r.right = r.left + _win_width;
r.bottom = r.top + _win_height;

View File

@ -434,6 +434,20 @@ make_window() {
register_window_class();
HINSTANCE application = GetModuleHandle(NULL);
int width = 320;
int height = 240;
if (_wparams.get_win_width() != 0 && _wparams.get_win_height() != 0) {
width = _wparams.get_win_width();
height = _wparams.get_win_height();
}
int x = _wparams.get_win_x();
int y = _wparams.get_win_y();
if (x == -1) x = CW_USEDEFAULT;
if (y == -1) y = CW_USEDEFAULT;
if (x == -2) x = 0.5 * (GetSystemMetrics(SM_CXBORDER) - width);
if (y == -2) y = 0.5 * (GetSystemMetrics(SM_CYBORDER) - height);
GetSystemMetrics(SM_CXBORDER);
int x = CW_USEDEFAULT;
int y = CW_USEDEFAULT;
if (_wparams.get_win_x() != 0 && _wparams.get_win_y() != 0) {
@ -441,13 +455,6 @@ make_window() {
y = _wparams.get_win_y();
}
int width = 320;
int height = 240;
if (_wparams.get_win_width() != 0 && _wparams.get_win_height() != 0) {
width = _wparams.get_win_width();
height = _wparams.get_win_height();
}
if (_wparams.get_window_type() == P3D_WT_embedded) {
// Create an embedded window.
DWORD window_style =

View File

@ -22,7 +22,7 @@
P3DWindowParams::
P3DWindowParams() :
_window_type(P3D_WT_hidden),
_win_x(0), _win_y(0),
_win_x(-1), _win_y(-1),
_win_width(0), _win_height(0)
{
}

View File

@ -25,9 +25,6 @@
#include <signal.h>
#include <stdint.h>
// Clamps a value to two boundaries.
#define clamp(x, lb, hb) (x < lb ? lb : (x > hb ? hb : x))
////////////////////////////////////////////////////////////////////
// Function: P3DX11SplashWindow::Constructor
// Access: Public
@ -830,9 +827,6 @@ redraw() {
////////////////////////////////////////////////////////////////////
void P3DX11SplashWindow::
make_window() {
int x = _wparams.get_win_x();
int y = _wparams.get_win_y();
_win_width = 320;
_win_height = 240;
if (_wparams.get_win_width() != 0 && _wparams.get_win_height() != 0) {
@ -853,8 +847,16 @@ make_window() {
_display = XOpenDisplay(NULL);
_own_display = true;
//}
assert(_display != NULL);
_screen = DefaultScreen(_display);
int x = _wparams.get_win_x();
int y = _wparams.get_win_y();
if (x == -1) x = 0;
if (y == -1) y = 0;
if (x == -2) x = 0.5 * (DisplayWidth(_display, _screen) - _win_width);
if (y == -2) y = 0.5 * (DisplayHeight(_display, _screen) - _win_height);
if (_wparams.get_window_type() == P3D_WT_embedded) {
// Create an embedded window.
const P3D_window_handle &handle = _wparams.get_parent_window();
@ -865,7 +867,6 @@ make_window() {
parent = XRootWindow(_display, _screen);
}
assert(_display != NULL);
assert(parent != None);
int depth = DefaultDepth(_display, _screen);
@ -913,6 +914,23 @@ make_window() {
(_display, parent, x, y, _win_width, _win_height,
0, depth, InputOutput, dvisual, attrib_mask, &wa);
// Now hint the window manager about the window origin and size.
// This is necessary because window managers are free to ignore
// the window origin specified in the XCreateWindow call.
XSizeHints *size_hints_p = XAllocSizeHints();
if (_wparams.get_win_x() != -1 || _wparams.get_win_y() != -1) {
// If the user requested (-1, -1), the default position, we let
// the window manager choose a position by omitting the pos hint.
size_hints_p->x = x;
size_hints_p->y = y;
size_hints_p->flags |= USPosition;
}
size_hints_p->width = _win_width;
size_hints_p->height = _win_height;
size_hints_p->flags |= USSize;
XSetWMNormalHints(_display, _window, size_hints_p);
XFree(size_hints_p);
if (_visible) {
XMapWindow(_display, _window);
}

View File

@ -742,7 +742,9 @@ usage() {
<< " -o x,y\n"
<< " Specify the position (origin) of the graphic window on the\n"
<< " screen, or on the parent window.\n\n"
<< " screen, or on the parent window. If you specify -1,-1\n"
<< " the default position will be used, and a value of -2,-2\n"
<< " means that the window will be centered on the screen.\n\n"
<< " -l log_dirname\n"
<< " Specify the full path to the directory in which log files are\n"

View File

@ -50,8 +50,8 @@ Panda3DBase(bool console_environment) {
_window_type = P3D_WT_toplevel;
_win_x = 0;
_win_y = 0;
_win_x = -1;
_win_y = -1;
_win_width = 640;
_win_height = 480;
@ -73,6 +73,10 @@ Panda3DBase(bool console_environment) {
////////////////////////////////////////////////////////////////////
int Panda3DBase::
run_embedded(int read_offset, int argc, char *argv[]) {
// Make sure the splash window will be put in the center of the screen
_win_x = -2;
_win_y = -2;
// Read out some parameters from the binary
pifstream read;
Filename f = ExecutionEnvironment::get_binary_name();