support cursor_hidden

This commit is contained in:
David Rose 2004-03-03 20:15:09 +00:00
parent d561b66713
commit 58c7debfa5
4 changed files with 84 additions and 7 deletions

View File

@ -49,6 +49,18 @@ get_root() const {
return _root; return _root;
} }
////////////////////////////////////////////////////////////////////
// Function: glxGraphicsPipe::get_im
// Access: Public
// Description: Returns the input method opened for the pipe, or NULL
// if the input method could not be opened for some
// reason.
////////////////////////////////////////////////////////////////////
INLINE XIM glxGraphicsPipe::
get_im() const {
return _im;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: glxGraphicsPipe::get_wm_delete_window // Function: glxGraphicsPipe::get_wm_delete_window
// Access: Public // Access: Public
@ -61,13 +73,15 @@ get_wm_delete_window() const {
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: glxGraphicsPipe::get_im // Function: glxGraphicsPipe::get_hidden_cursor
// Access: Public // Access: Public
// Description: Returns the input method opened for the pipe, or NULL // Description: Returns an invisible Cursor suitable for assigning to
// if the input method could not be opened for some // windows that have the cursor_hidden property set.
// reason.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE XIM glxGraphicsPipe:: INLINE Cursor glxGraphicsPipe::
get_im() const { get_hidden_cursor() {
return _im; if (_hidden_cursor == None) {
make_hidden_cursor();
}
return _hidden_cursor;
} }

View File

@ -56,6 +56,7 @@ glxGraphicsPipe(const string &display) {
_screen = 0; _screen = 0;
_root = (Window)NULL; _root = (Window)NULL;
_im = (XIM)NULL; _im = (XIM)NULL;
_hidden_cursor = None;
install_error_handlers(); install_error_handlers();
@ -118,6 +119,7 @@ glxGraphicsPipe(const string &display) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
glxGraphicsPipe:: glxGraphicsPipe::
~glxGraphicsPipe() { ~glxGraphicsPipe() {
release_hidden_cursor();
if (_im) { if (_im) {
XCloseIM(_im); XCloseIM(_im);
} }
@ -574,6 +576,44 @@ try_for_fbconfig(int framebuffer_mode,
return fbconfig; return fbconfig;
} }
////////////////////////////////////////////////////////////////////
// Function: glxGraphicsPipe::make_hidden_cursor
// Access: Private
// Description: Called once to make an invisible Cursor for return
// from get_hidden_cursor().
////////////////////////////////////////////////////////////////////
void glxGraphicsPipe::
make_hidden_cursor() {
nassertv(_hidden_cursor == None);
unsigned int x_size, y_size;
XQueryBestCursor(_display, _root, 1, 1, &x_size, &y_size);
cerr << "best size is " << x_size << " x " << y_size << "\n";
Pixmap empty = XCreatePixmap(_display, _root, x_size, y_size, 1);
XColor black;
memset(&black, 0, sizeof(black));
_hidden_cursor = XCreatePixmapCursor(_display, empty, empty,
&black, &black, x_size, y_size);
XFreePixmap(_display, empty);
}
////////////////////////////////////////////////////////////////////
// Function: glxGraphicsPipe::release_hidden_cursor
// Access: Private
// Description: Called once to release the invisible cursor created
// by make_hidden_cursor().
////////////////////////////////////////////////////////////////////
void glxGraphicsPipe::
release_hidden_cursor() {
if (_hidden_cursor != None) {
XFreeCursor(_display, _hidden_cursor);
_hidden_cursor = None;
}
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: glxGraphicsPipe::install_error_handlers // Function: glxGraphicsPipe::install_error_handlers
// Access: Private, Static // Access: Private, Static

View File

@ -34,6 +34,7 @@ typedef int XVisualInfo;
typedef int GLXFBConfig; typedef int GLXFBConfig;
typedef int GLXPbuffer; typedef int GLXPbuffer;
typedef int Atom; typedef int Atom;
typedef int Cursor;
typedef int XIM; typedef int XIM;
typedef int XIC; typedef int XIC;
#else #else
@ -77,6 +78,8 @@ public:
INLINE Atom get_wm_delete_window() const; INLINE Atom get_wm_delete_window() const;
INLINE Cursor get_hidden_cursor();
protected: protected:
virtual PT(GraphicsStateGuardian) make_gsg(const FrameBufferProperties &properties, virtual PT(GraphicsStateGuardian) make_gsg(const FrameBufferProperties &properties,
GraphicsStateGuardian *share_with); GraphicsStateGuardian *share_with);
@ -90,6 +93,8 @@ private:
GLXFBConfig choose_fbconfig(FrameBufferProperties &properties) const; GLXFBConfig choose_fbconfig(FrameBufferProperties &properties) const;
GLXFBConfig try_for_fbconfig(int framebuffer_mode, GLXFBConfig try_for_fbconfig(int framebuffer_mode,
int want_depth_bits, int want_color_bits) const; int want_depth_bits, int want_color_bits) const;
void make_hidden_cursor();
void release_hidden_cursor();
static void install_error_handlers(); static void install_error_handlers();
static int error_handler(Display *display, XErrorEvent *error); static int error_handler(Display *display, XErrorEvent *error);
@ -102,6 +107,7 @@ private:
Atom _wm_protocols; Atom _wm_protocols;
Atom _wm_delete_window; Atom _wm_delete_window;
Cursor _hidden_cursor;
typedef int ErrorHandlerFunc(Display *, XErrorEvent *); typedef int ErrorHandlerFunc(Display *, XErrorEvent *);
typedef int IOErrorHandlerFunc(Display *); typedef int IOErrorHandlerFunc(Display *);

View File

@ -407,6 +407,9 @@ set_properties_now(WindowProperties &properties) {
// The window is already open; we are limited to what we can change // The window is already open; we are limited to what we can change
// on the fly. // on the fly.
glxGraphicsPipe *glx_pipe;
DCAST_INTO_V(glx_pipe, _pipe);
// The window title may be changed by issuing another hint request. // The window title may be changed by issuing another hint request.
// Assume this will be honored. // Assume this will be honored.
if (properties.has_title()) { if (properties.has_title()) {
@ -443,6 +446,16 @@ set_properties_now(WindowProperties &properties) {
// Don't draw anything until this is done reconfiguring. // Don't draw anything until this is done reconfiguring.
_awaiting_configure = true; _awaiting_configure = true;
} }
// We hide the cursor by setting it to an invisible pixmap.
if (properties.has_cursor_hidden()) {
if (properties.get_cursor_hidden()) {
XDefineCursor(_display, _xwindow, glx_pipe->get_hidden_cursor());
} else {
XDefineCursor(_display, _xwindow, None);
}
properties.clear_cursor_hidden();
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -557,6 +570,10 @@ open_window() {
<< "Couldn't create input context.\n"; << "Couldn't create input context.\n";
} }
if (_properties.get_cursor_hidden()) {
XDefineCursor(_display, _xwindow, glx_pipe->get_hidden_cursor());
}
XMapWindow(_display, _xwindow); XMapWindow(_display, _xwindow);
return true; return true;