1998-12-07 09:13:40 +00:00
|
|
|
/*
|
1998-12-26 12:00:43 +00:00
|
|
|
* X11 event driver
|
1998-12-07 09:13:40 +00:00
|
|
|
*
|
|
|
|
* Copyright 1993 Alexandre Julliard
|
1999-09-20 15:42:47 +00:00
|
|
|
* 1999 Noel Borthwick
|
2002-03-09 23:29:33 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1998-12-07 09:13:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-02-27 18:13:09 +00:00
|
|
|
#ifdef HAVE_POLL_H
|
|
|
|
#include <poll.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_POLL_H
|
|
|
|
#include <sys/poll.h>
|
|
|
|
#endif
|
1998-12-07 09:13:40 +00:00
|
|
|
#include <X11/Xatom.h>
|
|
|
|
#include <X11/keysym.h>
|
2003-11-21 21:48:36 +00:00
|
|
|
#include <X11/Xlib.h>
|
2002-09-24 18:36:51 +00:00
|
|
|
#include <X11/Xresource.h>
|
|
|
|
#include <X11/Xutil.h>
|
2011-04-27 14:00:02 +00:00
|
|
|
#ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
|
|
|
|
#include <X11/extensions/XInput2.h>
|
|
|
|
#endif
|
1999-12-12 19:42:47 +00:00
|
|
|
|
1998-12-07 09:13:40 +00:00
|
|
|
#include <assert.h>
|
2003-09-05 23:08:26 +00:00
|
|
|
#include <stdarg.h>
|
1998-12-07 09:13:40 +00:00
|
|
|
#include <string.h>
|
2005-03-09 18:46:13 +00:00
|
|
|
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
2003-09-05 23:08:26 +00:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "wingdi.h"
|
2000-09-16 20:58:06 +00:00
|
|
|
|
1998-12-07 09:13:40 +00:00
|
|
|
#include "x11drv.h"
|
2007-12-17 15:24:08 +00:00
|
|
|
|
|
|
|
/* avoid conflict with field names in included win32 headers */
|
|
|
|
#undef Status
|
|
|
|
#include "shlobj.h" /* DROPFILES */
|
2001-01-02 21:00:46 +00:00
|
|
|
#include "shellapi.h"
|
2007-12-17 15:24:08 +00:00
|
|
|
|
2008-04-17 14:07:06 +00:00
|
|
|
#include "wine/server.h"
|
2002-12-03 23:34:52 +00:00
|
|
|
#include "wine/debug.h"
|
1999-04-19 14:56:29 +00:00
|
|
|
|
2002-03-09 23:29:33 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(event);
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2004-01-21 02:22:26 +00:00
|
|
|
extern BOOL ximInComposeMode;
|
|
|
|
|
1998-12-07 09:13:40 +00:00
|
|
|
#define DndNotDnd -1 /* OffiX drag&drop */
|
|
|
|
#define DndUnknown 0
|
|
|
|
#define DndRawData 1
|
|
|
|
#define DndFile 2
|
|
|
|
#define DndFiles 3
|
|
|
|
#define DndText 4
|
|
|
|
#define DndDir 5
|
|
|
|
#define DndLink 6
|
|
|
|
#define DndExe 7
|
|
|
|
|
|
|
|
#define DndEND 8
|
|
|
|
|
|
|
|
#define DndURL 128 /* KDE drag&drop */
|
|
|
|
|
2010-11-01 18:45:12 +00:00
|
|
|
#define XEMBED_EMBEDDED_NOTIFY 0
|
|
|
|
#define XEMBED_WINDOW_ACTIVATE 1
|
|
|
|
#define XEMBED_WINDOW_DEACTIVATE 2
|
|
|
|
#define XEMBED_REQUEST_FOCUS 3
|
|
|
|
#define XEMBED_FOCUS_IN 4
|
|
|
|
#define XEMBED_FOCUS_OUT 5
|
|
|
|
#define XEMBED_FOCUS_NEXT 6
|
|
|
|
#define XEMBED_FOCUS_PREV 7
|
|
|
|
#define XEMBED_MODALITY_ON 10
|
|
|
|
#define XEMBED_MODALITY_OFF 11
|
|
|
|
#define XEMBED_REGISTER_ACCELERATOR 12
|
|
|
|
#define XEMBED_UNREGISTER_ACCELERATOR 13
|
|
|
|
#define XEMBED_ACTIVATE_ACCELERATOR 14
|
|
|
|
|
2011-04-12 19:16:15 +00:00
|
|
|
Bool (*pXGetEventData)( Display *display, XEvent /*XGenericEventCookie*/ *event ) = NULL;
|
|
|
|
void (*pXFreeEventData)( Display *display, XEvent /*XGenericEventCookie*/ *event ) = NULL;
|
|
|
|
|
2005-02-26 17:49:38 +00:00
|
|
|
/* Event handlers */
|
2008-04-17 14:07:06 +00:00
|
|
|
static void X11DRV_FocusIn( HWND hwnd, XEvent *event );
|
|
|
|
static void X11DRV_FocusOut( HWND hwnd, XEvent *event );
|
|
|
|
static void X11DRV_Expose( HWND hwnd, XEvent *event );
|
2008-04-17 14:13:12 +00:00
|
|
|
static void X11DRV_MapNotify( HWND hwnd, XEvent *event );
|
2011-04-04 13:20:14 +00:00
|
|
|
static void X11DRV_UnmapNotify( HWND hwnd, XEvent *event );
|
2010-11-01 18:45:12 +00:00
|
|
|
static void X11DRV_ReparentNotify( HWND hwnd, XEvent *event );
|
2008-04-22 14:56:31 +00:00
|
|
|
static void X11DRV_ConfigureNotify( HWND hwnd, XEvent *event );
|
2008-04-17 14:07:06 +00:00
|
|
|
static void X11DRV_PropertyNotify( HWND hwnd, XEvent *event );
|
|
|
|
static void X11DRV_ClientMessage( HWND hwnd, XEvent *event );
|
2010-11-08 14:22:09 +00:00
|
|
|
static void X11DRV_GravityNotify( HWND hwnd, XEvent *event );
|
2005-02-26 17:49:38 +00:00
|
|
|
|
2011-04-06 11:26:42 +00:00
|
|
|
#define MAX_EVENT_HANDLERS 128
|
2005-02-26 17:49:38 +00:00
|
|
|
|
2011-04-06 11:26:42 +00:00
|
|
|
static x11drv_event_handler handlers[MAX_EVENT_HANDLERS] =
|
2005-02-26 17:49:38 +00:00
|
|
|
{
|
2011-04-06 11:26:42 +00:00
|
|
|
NULL, /* 0 reserved */
|
|
|
|
NULL, /* 1 reserved */
|
|
|
|
X11DRV_KeyEvent, /* 2 KeyPress */
|
|
|
|
X11DRV_KeyEvent, /* 3 KeyRelease */
|
|
|
|
X11DRV_ButtonPress, /* 4 ButtonPress */
|
|
|
|
X11DRV_ButtonRelease, /* 5 ButtonRelease */
|
|
|
|
X11DRV_MotionNotify, /* 6 MotionNotify */
|
|
|
|
X11DRV_EnterNotify, /* 7 EnterNotify */
|
|
|
|
NULL, /* 8 LeaveNotify */
|
|
|
|
X11DRV_FocusIn, /* 9 FocusIn */
|
|
|
|
X11DRV_FocusOut, /* 10 FocusOut */
|
|
|
|
X11DRV_KeymapNotify, /* 11 KeymapNotify */
|
|
|
|
X11DRV_Expose, /* 12 Expose */
|
|
|
|
NULL, /* 13 GraphicsExpose */
|
|
|
|
NULL, /* 14 NoExpose */
|
|
|
|
NULL, /* 15 VisibilityNotify */
|
|
|
|
NULL, /* 16 CreateNotify */
|
|
|
|
X11DRV_DestroyNotify, /* 17 DestroyNotify */
|
|
|
|
X11DRV_UnmapNotify, /* 18 UnmapNotify */
|
|
|
|
X11DRV_MapNotify, /* 19 MapNotify */
|
|
|
|
NULL, /* 20 MapRequest */
|
|
|
|
X11DRV_ReparentNotify, /* 21 ReparentNotify */
|
|
|
|
X11DRV_ConfigureNotify, /* 22 ConfigureNotify */
|
|
|
|
NULL, /* 23 ConfigureRequest */
|
|
|
|
X11DRV_GravityNotify, /* 24 GravityNotify */
|
|
|
|
NULL, /* 25 ResizeRequest */
|
|
|
|
NULL, /* 26 CirculateNotify */
|
|
|
|
NULL, /* 27 CirculateRequest */
|
|
|
|
X11DRV_PropertyNotify, /* 28 PropertyNotify */
|
|
|
|
X11DRV_SelectionClear, /* 29 SelectionClear */
|
|
|
|
X11DRV_SelectionRequest, /* 30 SelectionRequest */
|
|
|
|
NULL, /* 31 SelectionNotify */
|
|
|
|
NULL, /* 32 ColormapNotify */
|
|
|
|
X11DRV_ClientMessage, /* 33 ClientMessage */
|
|
|
|
X11DRV_MappingNotify, /* 34 MappingNotify */
|
2011-04-13 16:56:37 +00:00
|
|
|
X11DRV_GenericEvent /* 35 GenericEvent */
|
2005-02-26 17:49:38 +00:00
|
|
|
};
|
1999-09-20 15:42:47 +00:00
|
|
|
|
2011-04-06 11:26:42 +00:00
|
|
|
static const char * event_names[MAX_EVENT_HANDLERS] =
|
|
|
|
{
|
|
|
|
NULL, NULL, "KeyPress", "KeyRelease", "ButtonPress", "ButtonRelease",
|
|
|
|
"MotionNotify", "EnterNotify", "LeaveNotify", "FocusIn", "FocusOut",
|
|
|
|
"KeymapNotify", "Expose", "GraphicsExpose", "NoExpose", "VisibilityNotify",
|
|
|
|
"CreateNotify", "DestroyNotify", "UnmapNotify", "MapNotify", "MapRequest",
|
|
|
|
"ReparentNotify", "ConfigureNotify", "ConfigureRequest", "GravityNotify", "ResizeRequest",
|
|
|
|
"CirculateNotify", "CirculateRequest", "PropertyNotify", "SelectionClear", "SelectionRequest",
|
|
|
|
"SelectionNotify", "ColormapNotify", "ClientMessage", "MappingNotify", "GenericEvent"
|
|
|
|
};
|
2011-04-12 19:16:15 +00:00
|
|
|
|
2011-04-27 14:00:02 +00:00
|
|
|
int xinput2_opcode = 0;
|
|
|
|
|
2005-02-26 17:49:38 +00:00
|
|
|
/* return the name of an X event */
|
|
|
|
static const char *dbgstr_event( int type )
|
|
|
|
{
|
2011-04-12 19:16:15 +00:00
|
|
|
if (type < MAX_EVENT_HANDLERS && event_names[type]) return event_names[type];
|
2011-04-06 11:26:42 +00:00
|
|
|
return wine_dbg_sprintf( "Unknown event %d", type );
|
2005-02-26 17:49:38 +00:00
|
|
|
}
|
|
|
|
|
2011-04-12 19:16:15 +00:00
|
|
|
static inline void get_event_data( XEvent *event )
|
|
|
|
{
|
|
|
|
#if defined(GenericEvent) && defined(HAVE_XEVENT_XCOOKIE)
|
|
|
|
if (event->xany.type != GenericEvent) return;
|
|
|
|
if (!pXGetEventData || !pXGetEventData( event->xany.display, event )) event->xcookie.data = NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void free_event_data( XEvent *event )
|
|
|
|
{
|
|
|
|
#if defined(GenericEvent) && defined(HAVE_XEVENT_XCOOKIE)
|
|
|
|
if (event->xany.type != GenericEvent) return;
|
|
|
|
if (event->xcookie.data) pXFreeEventData( event->xany.display, event );
|
|
|
|
#endif
|
|
|
|
}
|
2005-02-26 17:49:38 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_register_event_handler
|
|
|
|
*
|
|
|
|
* Register a handler for a given event type.
|
|
|
|
* If already registered, overwrite the previous handler.
|
|
|
|
*/
|
2011-04-06 11:26:42 +00:00
|
|
|
void X11DRV_register_event_handler( int type, x11drv_event_handler handler, const char *name )
|
2005-02-26 17:49:38 +00:00
|
|
|
{
|
2011-05-01 12:51:29 +00:00
|
|
|
assert( type < MAX_EVENT_HANDLERS );
|
2011-04-19 15:17:48 +00:00
|
|
|
assert( !handlers[type] || handlers[type] == handler );
|
2011-04-06 11:26:42 +00:00
|
|
|
handlers[type] = handler;
|
|
|
|
event_names[type] = name;
|
|
|
|
TRACE("registered handler %p for event %d %s\n", handler, type, debugstr_a(name) );
|
2005-02-26 17:49:38 +00:00
|
|
|
}
|
1998-12-07 09:13:40 +00:00
|
|
|
|
|
|
|
|
2005-03-08 19:20:14 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* filter_event
|
|
|
|
*/
|
|
|
|
static Bool filter_event( Display *display, XEvent *event, char *arg )
|
|
|
|
{
|
2005-09-12 15:14:06 +00:00
|
|
|
ULONG_PTR mask = (ULONG_PTR)arg;
|
2005-03-08 19:20:14 +00:00
|
|
|
|
|
|
|
if ((mask & QS_ALLINPUT) == QS_ALLINPUT) return 1;
|
|
|
|
|
|
|
|
switch(event->type)
|
|
|
|
{
|
|
|
|
case KeyPress:
|
|
|
|
case KeyRelease:
|
|
|
|
case KeymapNotify:
|
2006-03-30 14:23:12 +00:00
|
|
|
case MappingNotify:
|
2011-06-17 19:01:13 +00:00
|
|
|
return (mask & (QS_KEY|QS_HOTKEY)) != 0;
|
2005-03-08 19:20:14 +00:00
|
|
|
case ButtonPress:
|
|
|
|
case ButtonRelease:
|
|
|
|
return (mask & QS_MOUSEBUTTON) != 0;
|
|
|
|
case MotionNotify:
|
|
|
|
case EnterNotify:
|
|
|
|
case LeaveNotify:
|
|
|
|
return (mask & QS_MOUSEMOVE) != 0;
|
|
|
|
case Expose:
|
|
|
|
return (mask & QS_PAINT) != 0;
|
2006-03-30 14:23:12 +00:00
|
|
|
case FocusIn:
|
|
|
|
case FocusOut:
|
|
|
|
case MapNotify:
|
|
|
|
case UnmapNotify:
|
|
|
|
case ConfigureNotify:
|
|
|
|
case PropertyNotify:
|
2005-03-08 19:20:14 +00:00
|
|
|
case ClientMessage:
|
|
|
|
return (mask & QS_POSTMESSAGE) != 0;
|
|
|
|
default:
|
|
|
|
return (mask & QS_SENDMESSAGE) != 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-11 11:11:35 +00:00
|
|
|
enum event_merge_action
|
|
|
|
{
|
|
|
|
MERGE_DISCARD, /* discard the old event */
|
|
|
|
MERGE_HANDLE, /* handle the old event */
|
2011-04-27 14:00:02 +00:00
|
|
|
MERGE_KEEP, /* keep the old event for future merging */
|
|
|
|
MERGE_IGNORE /* ignore the new event, keep the old one */
|
2008-03-11 11:11:35 +00:00
|
|
|
};
|
|
|
|
|
2011-04-27 14:00:50 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* merge_raw_motion_events
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
|
|
|
|
static enum event_merge_action merge_raw_motion_events( XIRawEvent *prev, XIRawEvent *next )
|
|
|
|
{
|
|
|
|
int i, j, k;
|
|
|
|
unsigned char mask;
|
|
|
|
|
|
|
|
if (!prev->valuators.mask_len) return MERGE_HANDLE;
|
|
|
|
if (!next->valuators.mask_len) return MERGE_HANDLE;
|
|
|
|
|
|
|
|
mask = prev->valuators.mask[0] | next->valuators.mask[0];
|
|
|
|
if (mask == next->valuators.mask[0]) /* keep next */
|
|
|
|
{
|
|
|
|
for (i = j = k = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
if (XIMaskIsSet( prev->valuators.mask, i ))
|
|
|
|
next->valuators.values[j] += prev->valuators.values[k++];
|
|
|
|
if (XIMaskIsSet( next->valuators.mask, i )) j++;
|
|
|
|
}
|
|
|
|
TRACE( "merging duplicate GenericEvent\n" );
|
|
|
|
return MERGE_DISCARD;
|
|
|
|
}
|
|
|
|
if (mask == prev->valuators.mask[0]) /* keep prev */
|
|
|
|
{
|
|
|
|
for (i = j = k = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
if (XIMaskIsSet( next->valuators.mask, i ))
|
|
|
|
prev->valuators.values[j] += next->valuators.values[k++];
|
|
|
|
if (XIMaskIsSet( prev->valuators.mask, i )) j++;
|
|
|
|
}
|
|
|
|
TRACE( "merging duplicate GenericEvent\n" );
|
|
|
|
return MERGE_IGNORE;
|
|
|
|
}
|
|
|
|
/* can't merge events with disjoint masks */
|
|
|
|
return MERGE_HANDLE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-03-11 11:11:35 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* merge_events
|
|
|
|
*
|
|
|
|
* Try to merge 2 consecutive events.
|
|
|
|
*/
|
|
|
|
static enum event_merge_action merge_events( XEvent *prev, XEvent *next )
|
|
|
|
{
|
|
|
|
switch (prev->type)
|
|
|
|
{
|
|
|
|
case ConfigureNotify:
|
|
|
|
switch (next->type)
|
|
|
|
{
|
|
|
|
case ConfigureNotify:
|
2008-03-11 18:50:27 +00:00
|
|
|
if (prev->xany.window == next->xany.window)
|
|
|
|
{
|
|
|
|
TRACE( "discarding duplicate ConfigureNotify for window %lx\n", prev->xany.window );
|
|
|
|
return MERGE_DISCARD;
|
|
|
|
}
|
|
|
|
break;
|
2008-03-11 11:11:35 +00:00
|
|
|
case Expose:
|
|
|
|
case PropertyNotify:
|
|
|
|
return MERGE_KEEP;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MotionNotify:
|
2011-11-09 14:45:13 +00:00
|
|
|
switch (next->type)
|
2008-03-11 11:11:35 +00:00
|
|
|
{
|
2011-11-09 14:45:13 +00:00
|
|
|
case MotionNotify:
|
|
|
|
if (prev->xany.window == next->xany.window)
|
|
|
|
{
|
|
|
|
TRACE( "discarding duplicate MotionNotify for window %lx\n", prev->xany.window );
|
|
|
|
return MERGE_DISCARD;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
|
|
|
|
case GenericEvent:
|
|
|
|
if (next->xcookie.extension != xinput2_opcode) break;
|
|
|
|
if (next->xcookie.evtype != XI_RawMotion) break;
|
|
|
|
if (x11drv_thread_data()->warp_serial) break;
|
|
|
|
return MERGE_KEEP;
|
2008-03-11 11:11:35 +00:00
|
|
|
}
|
|
|
|
break;
|
2011-04-27 14:00:02 +00:00
|
|
|
case GenericEvent:
|
2011-11-09 14:45:13 +00:00
|
|
|
if (prev->xcookie.extension != xinput2_opcode) break;
|
|
|
|
if (prev->xcookie.evtype != XI_RawMotion) break;
|
|
|
|
switch (next->type)
|
2011-04-27 14:00:02 +00:00
|
|
|
{
|
2011-11-09 14:45:13 +00:00
|
|
|
case GenericEvent:
|
|
|
|
if (next->xcookie.extension != xinput2_opcode) break;
|
|
|
|
if (next->xcookie.evtype != XI_RawMotion) break;
|
|
|
|
if (x11drv_thread_data()->warp_serial) break;
|
|
|
|
return merge_raw_motion_events( prev->xcookie.data, next->xcookie.data );
|
|
|
|
#endif
|
2011-04-27 14:00:02 +00:00
|
|
|
}
|
|
|
|
break;
|
2008-03-11 11:11:35 +00:00
|
|
|
}
|
|
|
|
return MERGE_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* call_event_handler
|
|
|
|
*/
|
|
|
|
static inline void call_event_handler( Display *display, XEvent *event )
|
|
|
|
{
|
|
|
|
HWND hwnd;
|
2008-03-13 12:35:02 +00:00
|
|
|
XEvent *prev;
|
|
|
|
struct x11drv_thread_data *thread_data;
|
2008-03-11 11:11:35 +00:00
|
|
|
|
2011-04-06 11:26:42 +00:00
|
|
|
if (!handlers[event->type])
|
2008-03-11 11:11:35 +00:00
|
|
|
{
|
|
|
|
TRACE( "%s for win %lx, ignoring\n", dbgstr_event( event->type ), event->xany.window );
|
|
|
|
return; /* no handler, ignore it */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XFindContext( display, event->xany.window, winContext, (char **)&hwnd ) != 0)
|
|
|
|
hwnd = 0; /* not for a registered window */
|
|
|
|
if (!hwnd && event->xany.window == root_window) hwnd = GetDesktopWindow();
|
|
|
|
|
2010-01-04 16:56:32 +00:00
|
|
|
TRACE( "%lu %s for hwnd/window %p/%lx\n",
|
|
|
|
event->xany.serial, dbgstr_event( event->type ), hwnd, event->xany.window );
|
2008-03-13 12:35:02 +00:00
|
|
|
thread_data = x11drv_thread_data();
|
|
|
|
prev = thread_data->current_event;
|
|
|
|
thread_data->current_event = event;
|
2011-04-06 11:26:42 +00:00
|
|
|
handlers[event->type]( hwnd, event );
|
2008-03-13 12:35:02 +00:00
|
|
|
thread_data->current_event = prev;
|
2008-03-11 11:11:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-10 10:24:31 +00:00
|
|
|
/***********************************************************************
|
2001-05-16 19:52:29 +00:00
|
|
|
* process_events
|
1999-07-10 10:24:31 +00:00
|
|
|
*/
|
2009-10-02 12:56:37 +00:00
|
|
|
static int process_events( Display *display, Bool (*filter)(Display*, XEvent*,XPointer), ULONG_PTR arg )
|
1999-02-21 18:15:26 +00:00
|
|
|
{
|
2008-03-11 11:11:35 +00:00
|
|
|
XEvent event, prev_event;
|
2005-03-08 19:20:14 +00:00
|
|
|
int count = 0;
|
2008-03-11 11:11:35 +00:00
|
|
|
enum event_merge_action action = MERGE_DISCARD;
|
1999-02-21 18:15:26 +00:00
|
|
|
|
2008-03-11 11:11:35 +00:00
|
|
|
prev_event.type = 0;
|
2008-02-27 18:13:09 +00:00
|
|
|
while (XCheckIfEvent( display, &event, filter, (char *)arg ))
|
1999-05-22 18:57:17 +00:00
|
|
|
{
|
2005-03-08 19:20:14 +00:00
|
|
|
count++;
|
2008-07-10 02:29:20 +00:00
|
|
|
if (XFilterEvent( &event, None ))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* SCIM on linux filters key events strangely. It does not filter the
|
|
|
|
* KeyPress events for these keys however it does filter the
|
|
|
|
* KeyRelease events. This causes wine to become very confused as
|
|
|
|
* to the keyboard state.
|
|
|
|
*
|
|
|
|
* We need to let those KeyRelease events be processed so that the
|
|
|
|
* keyboard state is correct.
|
|
|
|
*/
|
|
|
|
if (event.type == KeyRelease)
|
|
|
|
{
|
|
|
|
KeySym keysym = 0;
|
|
|
|
XKeyEvent *keyevent = &event.xkey;
|
|
|
|
|
|
|
|
XLookupString(keyevent, NULL, 0, &keysym, NULL);
|
|
|
|
if (!(keysym == XK_Shift_L ||
|
|
|
|
keysym == XK_Shift_R ||
|
|
|
|
keysym == XK_Control_L ||
|
|
|
|
keysym == XK_Control_R ||
|
|
|
|
keysym == XK_Alt_R ||
|
|
|
|
keysym == XK_Alt_L ||
|
|
|
|
keysym == XK_Meta_R ||
|
|
|
|
keysym == XK_Meta_L))
|
|
|
|
continue; /* not a key we care about, ignore it */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
continue; /* filtered, ignore it */
|
|
|
|
}
|
2011-04-12 19:16:15 +00:00
|
|
|
get_event_data( &event );
|
2008-03-11 11:11:35 +00:00
|
|
|
if (prev_event.type) action = merge_events( &prev_event, &event );
|
|
|
|
switch( action )
|
2005-02-26 17:49:38 +00:00
|
|
|
{
|
2008-03-11 11:11:35 +00:00
|
|
|
case MERGE_HANDLE: /* handle prev, keep new */
|
|
|
|
call_event_handler( display, &prev_event );
|
2011-04-12 19:16:15 +00:00
|
|
|
/* fall through */
|
|
|
|
case MERGE_DISCARD: /* discard prev, keep new */
|
|
|
|
free_event_data( &prev_event );
|
2008-03-11 11:11:35 +00:00
|
|
|
prev_event = event;
|
|
|
|
break;
|
|
|
|
case MERGE_KEEP: /* handle new, keep prev for future merging */
|
|
|
|
call_event_handler( display, &event );
|
2011-04-27 14:00:02 +00:00
|
|
|
/* fall through */
|
|
|
|
case MERGE_IGNORE: /* ignore new, keep prev for future merging */
|
2011-04-12 19:16:15 +00:00
|
|
|
free_event_data( &event );
|
2008-03-11 11:11:35 +00:00
|
|
|
break;
|
2005-02-26 17:49:38 +00:00
|
|
|
}
|
1999-05-22 18:57:17 +00:00
|
|
|
}
|
2008-03-11 11:11:35 +00:00
|
|
|
if (prev_event.type) call_event_handler( display, &prev_event );
|
2011-04-12 19:16:15 +00:00
|
|
|
free_event_data( &prev_event );
|
2010-04-22 14:33:35 +00:00
|
|
|
XFlush( gdi_display );
|
2005-02-26 17:49:38 +00:00
|
|
|
if (count) TRACE( "processed %d events\n", count );
|
2001-06-04 21:55:17 +00:00
|
|
|
return count;
|
1998-12-07 09:13:40 +00:00
|
|
|
}
|
|
|
|
|
2001-05-16 19:52:29 +00:00
|
|
|
|
1998-12-07 09:13:40 +00:00
|
|
|
/***********************************************************************
|
2001-05-18 22:51:56 +00:00
|
|
|
* MsgWaitForMultipleObjectsEx (X11DRV.@)
|
1998-12-07 09:13:40 +00:00
|
|
|
*/
|
2008-12-16 14:32:08 +00:00
|
|
|
DWORD CDECL X11DRV_MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
|
|
|
|
DWORD timeout, DWORD mask, DWORD flags )
|
1998-12-07 09:13:40 +00:00
|
|
|
{
|
2007-04-04 16:02:53 +00:00
|
|
|
DWORD ret;
|
2005-06-01 11:08:39 +00:00
|
|
|
struct x11drv_thread_data *data = TlsGetValue( thread_data_tls_index );
|
2001-05-16 19:52:29 +00:00
|
|
|
|
2007-04-04 16:02:53 +00:00
|
|
|
if (!data)
|
2005-08-03 15:47:30 +00:00
|
|
|
{
|
|
|
|
if (!count && !timeout) return WAIT_TIMEOUT;
|
2001-05-18 22:51:56 +00:00
|
|
|
return WaitForMultipleObjectsEx( count, handles, flags & MWMO_WAITALL,
|
|
|
|
timeout, flags & MWMO_ALERTABLE );
|
2005-08-03 15:47:30 +00:00
|
|
|
}
|
2001-05-16 19:52:29 +00:00
|
|
|
|
2008-03-13 12:35:02 +00:00
|
|
|
if (data->current_event) mask = 0; /* don't process nested events */
|
2005-08-03 15:47:30 +00:00
|
|
|
|
2008-02-27 18:13:09 +00:00
|
|
|
if (process_events( data->display, filter_event, mask )) ret = count - 1;
|
2005-08-03 15:47:30 +00:00
|
|
|
else if (count || timeout)
|
2001-06-04 21:55:17 +00:00
|
|
|
{
|
2007-04-04 16:02:53 +00:00
|
|
|
ret = WaitForMultipleObjectsEx( count, handles, flags & MWMO_WAITALL,
|
2001-06-04 21:55:17 +00:00
|
|
|
timeout, flags & MWMO_ALERTABLE );
|
2008-02-27 18:13:09 +00:00
|
|
|
if (ret == count - 1) process_events( data->display, filter_event, mask );
|
2001-06-04 21:55:17 +00:00
|
|
|
}
|
2005-08-03 15:47:30 +00:00
|
|
|
else ret = WAIT_TIMEOUT;
|
|
|
|
|
2001-05-16 19:52:29 +00:00
|
|
|
return ret;
|
1998-12-07 09:13:40 +00:00
|
|
|
}
|
|
|
|
|
2005-01-14 17:06:40 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* EVENT_x11_time_to_win32_time
|
|
|
|
*
|
|
|
|
* Make our timer and the X timer line up as best we can
|
|
|
|
* Pass 0 to retrieve the current adjustment value (times -1)
|
|
|
|
*/
|
|
|
|
DWORD EVENT_x11_time_to_win32_time(Time time)
|
|
|
|
{
|
|
|
|
static DWORD adjust = 0;
|
|
|
|
DWORD now = GetTickCount();
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
if (! adjust && time != 0)
|
|
|
|
{
|
|
|
|
ret = now;
|
|
|
|
adjust = time - now;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If we got an event in the 'future', then our clock is clearly wrong.
|
|
|
|
If we got it more than 10000 ms in the future, then it's most likely
|
|
|
|
that the clock has wrapped. */
|
|
|
|
|
|
|
|
ret = time - adjust;
|
|
|
|
if (ret > now && ((ret - now) < 10000) && time != 0)
|
|
|
|
{
|
|
|
|
adjust += ret - now;
|
|
|
|
ret -= ret - now;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
2001-05-16 19:52:29 +00:00
|
|
|
|
2002-10-11 23:41:06 +00:00
|
|
|
/*******************************************************************
|
|
|
|
* can_activate_window
|
|
|
|
*
|
|
|
|
* Check if we can activate the specified window.
|
|
|
|
*/
|
2007-03-17 10:47:28 +00:00
|
|
|
static inline BOOL can_activate_window( HWND hwnd )
|
2002-10-11 23:41:06 +00:00
|
|
|
{
|
|
|
|
LONG style = GetWindowLongW( hwnd, GWL_STYLE );
|
2012-09-18 09:24:55 +00:00
|
|
|
RECT rect;
|
2012-02-01 14:33:51 +00:00
|
|
|
|
2002-10-11 23:41:06 +00:00
|
|
|
if (!(style & WS_VISIBLE)) return FALSE;
|
|
|
|
if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
|
2009-04-23 10:41:57 +00:00
|
|
|
if (style & WS_MINIMIZE) return FALSE;
|
2009-10-23 10:25:22 +00:00
|
|
|
if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOACTIVATE) return FALSE;
|
2007-08-16 21:43:58 +00:00
|
|
|
if (hwnd == GetDesktopWindow()) return FALSE;
|
2012-09-18 09:24:55 +00:00
|
|
|
if (GetWindowRect( hwnd, &rect ) && IsRectEmpty( &rect )) return FALSE;
|
2002-10-11 23:41:06 +00:00
|
|
|
return !(style & WS_DISABLED);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-18 09:20:07 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* set_input_focus
|
|
|
|
*
|
|
|
|
* Try to force focus for non-managed windows.
|
|
|
|
*/
|
|
|
|
static void set_input_focus( Display *display, Window window )
|
|
|
|
{
|
|
|
|
XWindowChanges changes;
|
|
|
|
DWORD timestamp;
|
|
|
|
|
|
|
|
if (!window) return;
|
|
|
|
|
|
|
|
if (EVENT_x11_time_to_win32_time(0))
|
|
|
|
/* ICCCM says don't use CurrentTime, so try to use last message time if possible */
|
|
|
|
/* FIXME: this is not entirely correct */
|
|
|
|
timestamp = GetMessageTime() - EVENT_x11_time_to_win32_time(0);
|
|
|
|
else
|
|
|
|
timestamp = CurrentTime;
|
|
|
|
|
|
|
|
/* Set X focus and install colormap */
|
|
|
|
changes.stack_mode = Above;
|
|
|
|
XConfigureWindow( display, window, CWStackMode, &changes );
|
|
|
|
XSetInputFocus( display, window, RevertToParent, timestamp );
|
|
|
|
}
|
|
|
|
|
2002-09-18 23:09:50 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* set_focus
|
|
|
|
*/
|
2008-06-26 14:20:02 +00:00
|
|
|
static void set_focus( Display *display, HWND hwnd, Time time )
|
2002-09-18 23:09:50 +00:00
|
|
|
{
|
2002-10-11 23:41:06 +00:00
|
|
|
HWND focus;
|
2002-09-18 23:09:50 +00:00
|
|
|
Window win;
|
2009-11-11 20:37:51 +00:00
|
|
|
GUITHREADINFO threadinfo;
|
2001-06-04 21:55:17 +00:00
|
|
|
|
2002-10-31 02:38:20 +00:00
|
|
|
TRACE( "setting foreground window to %p\n", hwnd );
|
2002-10-11 23:41:06 +00:00
|
|
|
SetForegroundWindow( hwnd );
|
2001-06-04 21:55:17 +00:00
|
|
|
|
2010-11-16 19:57:27 +00:00
|
|
|
threadinfo.cbSize = sizeof(threadinfo);
|
2009-11-11 20:37:51 +00:00
|
|
|
GetGUIThreadInfo(0, &threadinfo);
|
|
|
|
focus = threadinfo.hwndFocus;
|
2010-06-24 20:06:29 +00:00
|
|
|
if (!focus) focus = threadinfo.hwndActive;
|
2003-01-21 20:16:20 +00:00
|
|
|
if (focus) focus = GetAncestor( focus, GA_ROOT );
|
2002-09-18 23:09:50 +00:00
|
|
|
win = X11DRV_get_whole_window(focus);
|
|
|
|
|
|
|
|
if (win)
|
|
|
|
{
|
2002-10-31 02:38:20 +00:00
|
|
|
TRACE( "setting focus to %p (%lx) time=%ld\n", focus, win, time );
|
2008-06-26 14:20:02 +00:00
|
|
|
XSetInputFocus( display, win, RevertToParent, time );
|
2002-09-18 23:09:50 +00:00
|
|
|
}
|
1998-12-07 09:13:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-01 18:57:12 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* handle_manager_message
|
|
|
|
*/
|
|
|
|
static void handle_manager_message( HWND hwnd, XClientMessageEvent *event )
|
|
|
|
{
|
|
|
|
if (hwnd != GetDesktopWindow()) return;
|
|
|
|
if (systray_atom && event->data.l[1] == systray_atom)
|
|
|
|
change_systray_owner( event->display, event->data.l[2] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-12-07 09:13:40 +00:00
|
|
|
/**********************************************************************
|
2005-03-01 11:52:02 +00:00
|
|
|
* handle_wm_protocols
|
1998-12-07 09:13:40 +00:00
|
|
|
*/
|
2005-03-01 11:52:02 +00:00
|
|
|
static void handle_wm_protocols( HWND hwnd, XClientMessageEvent *event )
|
1998-12-07 09:13:40 +00:00
|
|
|
{
|
2002-09-18 23:09:50 +00:00
|
|
|
Atom protocol = (Atom)event->data.l[0];
|
2010-06-29 09:08:51 +00:00
|
|
|
Time event_time = (Time)event->data.l[1];
|
2002-09-18 23:09:50 +00:00
|
|
|
|
|
|
|
if (!protocol) return;
|
1999-10-13 13:49:01 +00:00
|
|
|
|
2003-11-20 04:24:18 +00:00
|
|
|
if (protocol == x11drv_atom(WM_DELETE_WINDOW))
|
2002-09-18 23:09:50 +00:00
|
|
|
{
|
2010-06-29 09:08:51 +00:00
|
|
|
update_user_time( event_time );
|
|
|
|
|
2009-12-11 17:47:59 +00:00
|
|
|
if (hwnd == GetDesktopWindow())
|
|
|
|
{
|
|
|
|
/* The desktop window does not have a close button that we can
|
|
|
|
* pretend to click. Therefore, we simply send it a close command. */
|
|
|
|
SendMessageW(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-09-18 23:09:50 +00:00
|
|
|
/* Ignore the delete window request if the window has been disabled
|
|
|
|
* and we are in managed mode. This is to disallow applications from
|
|
|
|
* being closed by the window manager while in a modal state.
|
|
|
|
*/
|
2005-07-25 11:08:43 +00:00
|
|
|
if (IsWindowEnabled(hwnd))
|
|
|
|
{
|
|
|
|
HMENU hSysMenu;
|
|
|
|
|
|
|
|
if (GetClassLongW(hwnd, GCL_STYLE) & CS_NOCLOSE) return;
|
|
|
|
hSysMenu = GetSystemMenu(hwnd, FALSE);
|
|
|
|
if (hSysMenu)
|
|
|
|
{
|
|
|
|
UINT state = GetMenuState(hSysMenu, SC_CLOSE, MF_BYCOMMAND);
|
|
|
|
if (state == 0xFFFFFFFF || (state & (MF_DISABLED | MF_GRAYED)))
|
|
|
|
return;
|
|
|
|
}
|
2007-06-18 21:00:04 +00:00
|
|
|
if (GetActiveWindow() != hwnd)
|
|
|
|
{
|
|
|
|
LRESULT ma = SendMessageW( hwnd, WM_MOUSEACTIVATE,
|
|
|
|
(WPARAM)GetAncestor( hwnd, GA_ROOT ),
|
2009-09-09 08:21:52 +00:00
|
|
|
MAKELPARAM( HTCLOSE, WM_NCLBUTTONDOWN ) );
|
2007-06-18 21:00:04 +00:00
|
|
|
switch(ma)
|
|
|
|
{
|
|
|
|
case MA_NOACTIVATEANDEAT:
|
|
|
|
case MA_ACTIVATEANDEAT:
|
|
|
|
return;
|
|
|
|
case MA_NOACTIVATE:
|
|
|
|
break;
|
|
|
|
case MA_ACTIVATE:
|
|
|
|
case 0:
|
|
|
|
SetActiveWindow(hwnd);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN( "unknown WM_MOUSEACTIVATE code %d\n", (int) ma );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-05-28 06:06:14 +00:00
|
|
|
|
2010-06-16 08:06:15 +00:00
|
|
|
PostMessageW( hwnd, WM_SYSCOMMAND, SC_CLOSE, 0 );
|
2005-07-25 11:08:43 +00:00
|
|
|
}
|
2002-09-18 23:09:50 +00:00
|
|
|
}
|
2003-11-20 04:24:18 +00:00
|
|
|
else if (protocol == x11drv_atom(WM_TAKE_FOCUS))
|
2001-06-04 21:55:17 +00:00
|
|
|
{
|
2002-09-18 23:09:50 +00:00
|
|
|
HWND last_focus = x11drv_thread_data()->last_focus;
|
|
|
|
|
2006-10-07 23:34:01 +00:00
|
|
|
TRACE( "got take focus msg for %p, enabled=%d, visible=%d (style %08x), focus=%p, active=%p, fg=%p, last=%p\n",
|
2006-07-05 07:57:44 +00:00
|
|
|
hwnd, IsWindowEnabled(hwnd), IsWindowVisible(hwnd), GetWindowLongW(hwnd, GWL_STYLE),
|
|
|
|
GetFocus(), GetActiveWindow(), GetForegroundWindow(), last_focus );
|
2002-09-18 23:09:50 +00:00
|
|
|
|
2002-10-11 23:41:06 +00:00
|
|
|
if (can_activate_window(hwnd))
|
2001-06-04 21:55:17 +00:00
|
|
|
{
|
2002-09-18 23:09:50 +00:00
|
|
|
/* simulate a mouse click on the caption to find out
|
|
|
|
* whether the window wants to be activated */
|
|
|
|
LRESULT ma = SendMessageW( hwnd, WM_MOUSEACTIVATE,
|
2002-10-31 02:38:20 +00:00
|
|
|
(WPARAM)GetAncestor( hwnd, GA_ROOT ),
|
2002-09-18 23:09:50 +00:00
|
|
|
MAKELONG(HTCAPTION,WM_LBUTTONDOWN) );
|
2007-06-21 22:38:00 +00:00
|
|
|
if (ma != MA_NOACTIVATEANDEAT && ma != MA_NOACTIVATE)
|
|
|
|
{
|
2008-06-26 14:20:02 +00:00
|
|
|
set_focus( event->display, hwnd, event_time );
|
2007-06-21 22:38:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-09-18 23:09:50 +00:00
|
|
|
}
|
2009-08-17 14:32:45 +00:00
|
|
|
else if (hwnd == GetDesktopWindow())
|
|
|
|
{
|
|
|
|
hwnd = GetForegroundWindow();
|
|
|
|
if (!hwnd) hwnd = last_focus;
|
|
|
|
if (!hwnd) hwnd = GetDesktopWindow();
|
|
|
|
set_focus( event->display, hwnd, event_time );
|
|
|
|
return;
|
|
|
|
}
|
2007-06-21 22:38:00 +00:00
|
|
|
/* try to find some other window to give the focus to */
|
|
|
|
hwnd = GetFocus();
|
|
|
|
if (hwnd) hwnd = GetAncestor( hwnd, GA_ROOT );
|
|
|
|
if (!hwnd) hwnd = GetActiveWindow();
|
|
|
|
if (!hwnd) hwnd = last_focus;
|
2008-06-26 14:20:02 +00:00
|
|
|
if (hwnd && can_activate_window(hwnd)) set_focus( event->display, hwnd, event_time );
|
2003-11-20 04:24:18 +00:00
|
|
|
}
|
|
|
|
else if (protocol == x11drv_atom(_NET_WM_PING))
|
|
|
|
{
|
2003-05-04 02:27:20 +00:00
|
|
|
XClientMessageEvent xev;
|
|
|
|
xev = *event;
|
|
|
|
|
|
|
|
TRACE("NET_WM Ping\n");
|
|
|
|
xev.window = DefaultRootWindow(xev.display);
|
|
|
|
XSendEvent(xev.display, xev.window, False, SubstructureRedirectMask | SubstructureNotifyMask, (XEvent*)&xev);
|
2002-09-18 23:09:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const char * const focus_details[] =
|
|
|
|
{
|
|
|
|
"NotifyAncestor",
|
|
|
|
"NotifyVirtual",
|
|
|
|
"NotifyInferior",
|
|
|
|
"NotifyNonlinear",
|
|
|
|
"NotifyNonlinearVirtual",
|
|
|
|
"NotifyPointer",
|
|
|
|
"NotifyPointerRoot",
|
|
|
|
"NotifyDetailNone"
|
|
|
|
};
|
|
|
|
|
|
|
|
/**********************************************************************
|
2008-04-17 14:07:06 +00:00
|
|
|
* X11DRV_FocusIn
|
2002-09-18 23:09:50 +00:00
|
|
|
*/
|
2008-04-17 14:07:06 +00:00
|
|
|
static void X11DRV_FocusIn( HWND hwnd, XEvent *xev )
|
2002-09-18 23:09:50 +00:00
|
|
|
{
|
2005-02-26 17:49:38 +00:00
|
|
|
XFocusChangeEvent *event = &xev->xfocus;
|
2003-01-23 01:29:58 +00:00
|
|
|
XIC xic;
|
|
|
|
|
2002-09-18 23:09:50 +00:00
|
|
|
if (!hwnd) return;
|
|
|
|
|
2002-10-31 02:38:20 +00:00
|
|
|
TRACE( "win %p xwin %lx detail=%s\n", hwnd, event->window, focus_details[event->detail] );
|
2002-09-18 23:09:50 +00:00
|
|
|
|
|
|
|
if (event->detail == NotifyPointer) return;
|
2011-05-11 10:07:37 +00:00
|
|
|
if (hwnd == GetDesktopWindow()) return;
|
2002-09-18 23:09:50 +00:00
|
|
|
|
2012-08-14 11:38:03 +00:00
|
|
|
if ((xic = X11DRV_get_ic( hwnd ))) XSetICFocus( xic );
|
2011-05-11 10:30:03 +00:00
|
|
|
if (use_take_focus)
|
|
|
|
{
|
2011-05-12 14:24:58 +00:00
|
|
|
if (hwnd == GetForegroundWindow()) clip_fullscreen_window( hwnd, FALSE );
|
2011-05-11 10:30:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-01-23 01:29:58 +00:00
|
|
|
|
2002-10-11 23:41:06 +00:00
|
|
|
if (!can_activate_window(hwnd))
|
2002-09-18 23:09:50 +00:00
|
|
|
{
|
|
|
|
HWND hwnd = GetFocus();
|
2003-01-21 20:16:20 +00:00
|
|
|
if (hwnd) hwnd = GetAncestor( hwnd, GA_ROOT );
|
2002-09-18 23:09:50 +00:00
|
|
|
if (!hwnd) hwnd = GetActiveWindow();
|
|
|
|
if (!hwnd) hwnd = x11drv_thread_data()->last_focus;
|
2008-06-26 14:20:02 +00:00
|
|
|
if (hwnd && can_activate_window(hwnd)) set_focus( event->display, hwnd, CurrentTime );
|
2001-06-04 21:55:17 +00:00
|
|
|
}
|
2002-10-11 23:41:06 +00:00
|
|
|
else SetForegroundWindow( hwnd );
|
1998-12-07 09:13:40 +00:00
|
|
|
}
|
|
|
|
|
2002-09-18 23:09:50 +00:00
|
|
|
|
1998-12-07 09:13:40 +00:00
|
|
|
/**********************************************************************
|
2008-04-17 14:07:06 +00:00
|
|
|
* X11DRV_FocusOut
|
2002-09-18 23:09:50 +00:00
|
|
|
*
|
|
|
|
* Note: only top-level windows get FocusOut events.
|
1998-12-07 09:13:40 +00:00
|
|
|
*/
|
2008-04-17 14:07:06 +00:00
|
|
|
static void X11DRV_FocusOut( HWND hwnd, XEvent *xev )
|
1998-12-07 09:13:40 +00:00
|
|
|
{
|
2005-02-26 17:49:38 +00:00
|
|
|
XFocusChangeEvent *event = &xev->xfocus;
|
2002-09-18 23:09:50 +00:00
|
|
|
HWND hwnd_tmp;
|
|
|
|
Window focus_win;
|
|
|
|
int revert;
|
2003-01-23 01:29:58 +00:00
|
|
|
XIC xic;
|
2002-09-18 23:09:50 +00:00
|
|
|
|
2011-05-11 10:07:37 +00:00
|
|
|
TRACE( "win %p xwin %lx detail=%s\n", hwnd, event->window, focus_details[event->detail] );
|
|
|
|
|
|
|
|
if (event->detail == NotifyPointer)
|
2011-04-25 08:49:49 +00:00
|
|
|
{
|
2011-05-11 10:07:37 +00:00
|
|
|
if (!hwnd && event->window == x11drv_thread_data()->clip_window) reset_clipping_window();
|
2011-04-25 08:49:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-03-09 10:37:15 +00:00
|
|
|
if (!hwnd) return;
|
2004-01-21 02:22:26 +00:00
|
|
|
if (ximInComposeMode) return;
|
|
|
|
|
2002-10-11 23:41:06 +00:00
|
|
|
x11drv_thread_data()->last_focus = hwnd;
|
2012-08-14 11:38:03 +00:00
|
|
|
if ((xic = X11DRV_get_ic( hwnd ))) XUnsetICFocus( xic );
|
|
|
|
|
2011-05-11 10:07:37 +00:00
|
|
|
if (root_window != DefaultRootWindow(event->display))
|
|
|
|
{
|
|
|
|
if (hwnd == GetDesktopWindow()) reset_clipping_window();
|
|
|
|
return;
|
|
|
|
}
|
2002-09-18 23:09:50 +00:00
|
|
|
if (hwnd != GetForegroundWindow()) return;
|
2006-05-10 19:32:56 +00:00
|
|
|
SendMessageW( hwnd, WM_CANCELMODE, 0, 0 );
|
2002-09-18 23:09:50 +00:00
|
|
|
|
|
|
|
/* don't reset the foreground window, if the window which is
|
|
|
|
getting the focus is a Wine window */
|
|
|
|
|
2008-06-26 14:20:02 +00:00
|
|
|
XGetInputFocus( event->display, &focus_win, &revert );
|
2002-09-24 18:36:51 +00:00
|
|
|
if (focus_win)
|
|
|
|
{
|
2008-06-26 14:20:02 +00:00
|
|
|
if (XFindContext( event->display, focus_win, winContext, (char **)&hwnd_tmp ) != 0)
|
2002-09-24 18:36:51 +00:00
|
|
|
focus_win = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!focus_win)
|
2002-09-18 23:09:50 +00:00
|
|
|
{
|
|
|
|
/* Abey : 6-Oct-99. Check again if the focus out window is the
|
|
|
|
Foreground window, because in most cases the messages sent
|
|
|
|
above must have already changed the foreground window, in which
|
|
|
|
case we don't have to change the foreground window to 0 */
|
|
|
|
if (hwnd == GetForegroundWindow())
|
|
|
|
{
|
2007-07-20 13:15:42 +00:00
|
|
|
TRACE( "lost focus, setting fg to desktop\n" );
|
|
|
|
SetForegroundWindow( GetDesktopWindow() );
|
2002-09-18 23:09:50 +00:00
|
|
|
}
|
|
|
|
}
|
1998-12-07 09:13:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-17 14:07:06 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_Expose
|
|
|
|
*/
|
|
|
|
static void X11DRV_Expose( HWND hwnd, XEvent *xev )
|
|
|
|
{
|
|
|
|
XExposeEvent *event = &xev->xexpose;
|
|
|
|
RECT rect;
|
|
|
|
struct x11drv_win_data *data;
|
2012-04-30 13:09:03 +00:00
|
|
|
int flags = RDW_INVALIDATE | RDW_ERASE | RDW_FRAME;
|
2008-04-17 14:07:06 +00:00
|
|
|
|
|
|
|
TRACE( "win %p (%lx) %d,%d %dx%d\n",
|
|
|
|
hwnd, event->window, event->x, event->y, event->width, event->height );
|
|
|
|
|
2012-09-19 11:12:42 +00:00
|
|
|
if (!(data = get_win_data( hwnd ))) return;
|
2008-04-17 14:07:06 +00:00
|
|
|
|
2010-09-27 19:12:49 +00:00
|
|
|
rect.left = event->x;
|
|
|
|
rect.top = event->y;
|
|
|
|
rect.right = event->x + event->width;
|
|
|
|
rect.bottom = event->y + event->height;
|
2012-04-30 13:09:03 +00:00
|
|
|
|
|
|
|
if (data->surface)
|
2008-04-17 14:07:06 +00:00
|
|
|
{
|
2012-04-30 13:09:03 +00:00
|
|
|
data->surface->funcs->lock( data->surface );
|
|
|
|
add_bounds_rect( data->surface->funcs->get_bounds( data->surface ), &rect );
|
|
|
|
data->surface->funcs->unlock( data->surface );
|
2008-04-17 14:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (event->window != root_window)
|
|
|
|
{
|
2012-04-30 13:09:03 +00:00
|
|
|
OffsetRect( &rect, data->whole_rect.left - data->client_rect.left,
|
|
|
|
data->whole_rect.top - data->client_rect.top );
|
|
|
|
|
2010-10-07 12:26:21 +00:00
|
|
|
if (GetWindowLongW( data->hwnd, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL)
|
|
|
|
mirror_rect( &data->client_rect, &rect );
|
|
|
|
|
2008-04-17 14:07:06 +00:00
|
|
|
SERVER_START_REQ( update_window_zorder )
|
|
|
|
{
|
2008-12-08 15:58:20 +00:00
|
|
|
req->window = wine_server_user_handle( hwnd );
|
2008-04-17 14:07:06 +00:00
|
|
|
req->rect.left = rect.left;
|
|
|
|
req->rect.top = rect.top;
|
|
|
|
req->rect.right = rect.right;
|
|
|
|
req->rect.bottom = rect.bottom;
|
|
|
|
wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
flags |= RDW_ALLCHILDREN;
|
|
|
|
}
|
2010-12-13 11:42:47 +00:00
|
|
|
else OffsetRect( &rect, virtual_screen_rect.left, virtual_screen_rect.top );
|
2008-04-17 14:07:06 +00:00
|
|
|
|
2012-09-19 11:12:42 +00:00
|
|
|
if (data->surface) flags = 0;
|
|
|
|
release_win_data( data );
|
|
|
|
|
|
|
|
if (flags) RedrawWindow( hwnd, &rect, 0, flags );
|
2008-04-17 14:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-17 14:13:12 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* X11DRV_MapNotify
|
|
|
|
*/
|
|
|
|
static void X11DRV_MapNotify( HWND hwnd, XEvent *event )
|
|
|
|
{
|
|
|
|
struct x11drv_win_data *data;
|
|
|
|
|
2011-04-14 10:04:45 +00:00
|
|
|
if (event->xany.window == x11drv_thread_data()->clip_window)
|
2011-04-04 13:20:14 +00:00
|
|
|
{
|
|
|
|
clipping_cursor = 1;
|
|
|
|
return;
|
|
|
|
}
|
2012-09-18 09:24:55 +00:00
|
|
|
if (!(data = get_win_data( hwnd ))) return;
|
2008-04-17 14:13:12 +00:00
|
|
|
|
2012-09-18 09:24:55 +00:00
|
|
|
if (!data->managed && !data->embedded && data->mapped)
|
2008-04-17 14:13:12 +00:00
|
|
|
{
|
|
|
|
HWND hwndFocus = GetFocus();
|
2012-09-18 09:20:07 +00:00
|
|
|
if (hwndFocus && IsChild( hwnd, hwndFocus ))
|
|
|
|
set_input_focus( thread_display(), data->whole_window );
|
2008-04-17 14:13:12 +00:00
|
|
|
}
|
2012-09-18 09:24:55 +00:00
|
|
|
release_win_data( data );
|
2008-04-17 14:13:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-04 13:20:14 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* X11DRV_UnmapNotify
|
|
|
|
*/
|
|
|
|
static void X11DRV_UnmapNotify( HWND hwnd, XEvent *event )
|
|
|
|
{
|
2011-04-22 14:22:09 +00:00
|
|
|
if (event->xany.window == x11drv_thread_data()->clip_window) clipping_cursor = 0;
|
2011-04-04 13:20:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-31 15:11:28 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* is_net_wm_state_maximized
|
|
|
|
*/
|
|
|
|
static BOOL is_net_wm_state_maximized( Display *display, struct x11drv_win_data *data )
|
|
|
|
{
|
|
|
|
Atom type, *state;
|
|
|
|
int format, ret = 0;
|
|
|
|
unsigned long i, count, remaining;
|
|
|
|
|
2010-11-08 14:20:51 +00:00
|
|
|
if (!data->whole_window) return FALSE;
|
|
|
|
|
2008-07-31 15:11:28 +00:00
|
|
|
if (!XGetWindowProperty( display, data->whole_window, x11drv_atom(_NET_WM_STATE), 0,
|
|
|
|
65536/sizeof(CARD32), False, XA_ATOM, &type, &format, &count,
|
|
|
|
&remaining, (unsigned char **)&state ))
|
|
|
|
{
|
|
|
|
if (type == XA_ATOM && format == 32)
|
|
|
|
{
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (state[i] == x11drv_atom(_NET_WM_STATE_MAXIMIZED_VERT) ||
|
|
|
|
state[i] == x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ))
|
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XFree( state );
|
|
|
|
}
|
|
|
|
return (ret == 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-01 18:45:12 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_ReparentNotify
|
|
|
|
*/
|
|
|
|
static void X11DRV_ReparentNotify( HWND hwnd, XEvent *xev )
|
|
|
|
{
|
|
|
|
XReparentEvent *event = &xev->xreparent;
|
|
|
|
struct x11drv_win_data *data;
|
2010-11-08 14:28:09 +00:00
|
|
|
HWND parent, old_parent;
|
|
|
|
DWORD style;
|
2010-11-01 18:45:12 +00:00
|
|
|
|
2012-09-19 11:13:40 +00:00
|
|
|
if (!(data = get_win_data( hwnd ))) return;
|
|
|
|
|
|
|
|
if (!data->embedded)
|
|
|
|
{
|
|
|
|
release_win_data( data );
|
|
|
|
return;
|
|
|
|
}
|
2010-11-08 14:28:09 +00:00
|
|
|
|
|
|
|
if (data->whole_window)
|
|
|
|
{
|
|
|
|
if (event->parent == root_window)
|
|
|
|
{
|
|
|
|
TRACE( "%p/%lx reparented to root\n", hwnd, data->whole_window );
|
|
|
|
data->embedder = 0;
|
2012-09-19 11:13:40 +00:00
|
|
|
release_win_data( data );
|
2010-11-08 14:28:09 +00:00
|
|
|
SendMessageW( hwnd, WM_CLOSE, 0, 0 );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
data->embedder = event->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE( "%p/%lx reparented to %lx\n", hwnd, data->whole_window, event->parent );
|
2012-09-19 11:13:40 +00:00
|
|
|
release_win_data( data );
|
2010-11-08 14:28:09 +00:00
|
|
|
|
|
|
|
style = GetWindowLongW( hwnd, GWL_STYLE );
|
2010-11-01 18:45:12 +00:00
|
|
|
if (event->parent == root_window)
|
|
|
|
{
|
2010-11-08 14:28:09 +00:00
|
|
|
parent = GetDesktopWindow();
|
|
|
|
style = (style & ~WS_CHILD) | WS_POPUP;
|
2010-11-01 18:45:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-08 14:28:09 +00:00
|
|
|
if (!(parent = create_foreign_window( event->display, event->parent ))) return;
|
|
|
|
style = (style & ~WS_POPUP) | WS_CHILD;
|
2010-11-01 18:45:12 +00:00
|
|
|
}
|
2010-11-08 14:28:09 +00:00
|
|
|
|
|
|
|
ShowWindow( hwnd, SW_HIDE );
|
|
|
|
old_parent = SetParent( hwnd, parent );
|
|
|
|
SetWindowLongW( hwnd, GWL_STYLE, style );
|
|
|
|
SetWindowPos( hwnd, HWND_TOP, event->x, event->y, 0, 0,
|
|
|
|
SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOCOPYBITS |
|
|
|
|
((style & WS_VISIBLE) ? SWP_SHOWWINDOW : 0) );
|
|
|
|
|
|
|
|
/* make old parent destroy itself if it no longer has children */
|
|
|
|
if (old_parent != GetDesktopWindow()) PostMessageW( old_parent, WM_CLOSE, 0, 0 );
|
2010-11-01 18:45:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-22 14:56:31 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_ConfigureNotify
|
|
|
|
*/
|
|
|
|
void X11DRV_ConfigureNotify( HWND hwnd, XEvent *xev )
|
|
|
|
{
|
|
|
|
XConfigureEvent *event = &xev->xconfigure;
|
|
|
|
struct x11drv_win_data *data;
|
|
|
|
RECT rect;
|
|
|
|
UINT flags;
|
2010-11-08 14:20:51 +00:00
|
|
|
HWND parent;
|
|
|
|
BOOL root_coords;
|
2008-04-22 14:56:31 +00:00
|
|
|
int cx, cy, x = event->x, y = event->y;
|
|
|
|
|
|
|
|
if (!hwnd) return;
|
2012-09-19 11:13:23 +00:00
|
|
|
if (!(data = get_win_data( hwnd ))) return;
|
|
|
|
if (!data->mapped || data->iconic) goto done;
|
|
|
|
if (data->whole_window && !data->managed) goto done;
|
2010-11-08 14:28:09 +00:00
|
|
|
/* ignore synthetic events on foreign windows */
|
2012-09-19 11:13:23 +00:00
|
|
|
if (event->send_event && !data->whole_window) goto done;
|
2010-01-04 16:56:32 +00:00
|
|
|
if (data->configure_serial && (long)(data->configure_serial - event->serial) > 0)
|
|
|
|
{
|
|
|
|
TRACE( "win %p/%lx event %d,%d,%dx%d ignoring old serial %lu/%lu\n",
|
|
|
|
hwnd, data->whole_window, event->x, event->y, event->width, event->height,
|
|
|
|
event->serial, data->configure_serial );
|
2012-09-19 11:13:23 +00:00
|
|
|
goto done;
|
2010-01-04 16:56:32 +00:00
|
|
|
}
|
2008-04-22 14:56:31 +00:00
|
|
|
|
|
|
|
/* Get geometry */
|
|
|
|
|
2010-11-08 14:20:51 +00:00
|
|
|
parent = GetAncestor( hwnd, GA_PARENT );
|
|
|
|
root_coords = event->send_event; /* synthetic events are always in root coords */
|
|
|
|
|
|
|
|
if (!root_coords && parent == GetDesktopWindow()) /* normal event, map coordinates to the root */
|
2008-04-22 14:56:31 +00:00
|
|
|
{
|
|
|
|
Window child;
|
2010-11-08 14:20:51 +00:00
|
|
|
XTranslateCoordinates( event->display, event->window, root_window,
|
2008-04-22 14:56:31 +00:00
|
|
|
0, 0, &x, &y, &child );
|
2010-11-08 14:20:51 +00:00
|
|
|
root_coords = TRUE;
|
2008-04-22 14:56:31 +00:00
|
|
|
}
|
|
|
|
rect.left = x;
|
|
|
|
rect.top = y;
|
|
|
|
rect.right = x + event->width;
|
|
|
|
rect.bottom = y + event->height;
|
2010-11-08 14:20:51 +00:00
|
|
|
if (root_coords) OffsetRect( &rect, virtual_screen_rect.left, virtual_screen_rect.top );
|
2008-07-31 15:11:28 +00:00
|
|
|
TRACE( "win %p/%lx new X rect %d,%d,%dx%d (event %d,%d,%dx%d)\n",
|
|
|
|
hwnd, data->whole_window, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
|
2008-04-22 14:56:31 +00:00
|
|
|
event->x, event->y, event->width, event->height );
|
|
|
|
|
2010-11-08 14:20:51 +00:00
|
|
|
X11DRV_X_to_window_rect( data, &rect );
|
|
|
|
if (root_coords) MapWindowPoints( 0, parent, (POINT *)&rect, 2 );
|
|
|
|
|
2008-04-22 14:56:31 +00:00
|
|
|
/* Compare what has changed */
|
|
|
|
|
2008-09-17 19:14:05 +00:00
|
|
|
x = rect.left;
|
|
|
|
y = rect.top;
|
|
|
|
cx = rect.right - rect.left;
|
|
|
|
cy = rect.bottom - rect.top;
|
|
|
|
flags = SWP_NOACTIVATE | SWP_NOZORDER;
|
|
|
|
|
2010-11-08 14:28:09 +00:00
|
|
|
if (!data->whole_window) flags |= SWP_NOCOPYBITS; /* we can't copy bits of foreign windows */
|
|
|
|
|
2008-09-17 19:14:05 +00:00
|
|
|
if (data->window_rect.left == x && data->window_rect.top == y) flags |= SWP_NOMOVE;
|
2008-04-22 14:56:31 +00:00
|
|
|
else
|
|
|
|
TRACE( "%p moving from (%d,%d) to (%d,%d)\n",
|
2008-09-17 19:14:05 +00:00
|
|
|
hwnd, data->window_rect.left, data->window_rect.top, x, y );
|
2008-04-22 14:56:31 +00:00
|
|
|
|
2008-09-17 19:14:05 +00:00
|
|
|
if ((data->window_rect.right - data->window_rect.left == cx &&
|
|
|
|
data->window_rect.bottom - data->window_rect.top == cy) ||
|
|
|
|
(IsRectEmpty( &data->window_rect ) && event->width == 1 && event->height == 1))
|
2008-04-22 14:56:31 +00:00
|
|
|
flags |= SWP_NOSIZE;
|
|
|
|
else
|
|
|
|
TRACE( "%p resizing from (%dx%d) to (%dx%d)\n",
|
2008-09-17 19:14:05 +00:00
|
|
|
hwnd, data->window_rect.right - data->window_rect.left,
|
|
|
|
data->window_rect.bottom - data->window_rect.top, cx, cy );
|
2008-04-22 14:56:31 +00:00
|
|
|
|
2011-04-05 09:31:27 +00:00
|
|
|
if (is_net_wm_state_maximized( event->display, data ))
|
|
|
|
{
|
|
|
|
if (!IsZoomed( data->hwnd ))
|
|
|
|
{
|
|
|
|
TRACE( "win %p/%lx is maximized\n", data->hwnd, data->whole_window );
|
2012-09-19 11:13:23 +00:00
|
|
|
release_win_data( data );
|
2011-04-05 09:31:27 +00:00
|
|
|
SendMessageW( data->hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0 );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (IsZoomed( data->hwnd ))
|
|
|
|
{
|
|
|
|
TRACE( "window %p/%lx is no longer maximized\n", data->hwnd, data->whole_window );
|
2012-09-19 11:13:23 +00:00
|
|
|
release_win_data( data );
|
2011-04-05 09:31:27 +00:00
|
|
|
SendMessageW( data->hwnd, WM_SYSCOMMAND, SC_RESTORE, 0 );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-06 12:09:06 +00:00
|
|
|
if ((flags & (SWP_NOSIZE | SWP_NOMOVE)) != (SWP_NOSIZE | SWP_NOMOVE))
|
2012-09-19 11:13:23 +00:00
|
|
|
{
|
|
|
|
release_win_data( data );
|
2012-09-06 12:09:06 +00:00
|
|
|
SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
|
2012-09-19 11:13:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
release_win_data( data );
|
2008-04-22 14:56:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-08 14:22:09 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* X11DRV_GravityNotify
|
|
|
|
*/
|
|
|
|
static void X11DRV_GravityNotify( HWND hwnd, XEvent *xev )
|
|
|
|
{
|
|
|
|
XGravityEvent *event = &xev->xgravity;
|
2012-09-19 11:13:51 +00:00
|
|
|
struct x11drv_win_data *data = get_win_data( hwnd );
|
|
|
|
RECT rect, window_rect;
|
2010-11-08 14:22:09 +00:00
|
|
|
|
2012-09-19 11:13:51 +00:00
|
|
|
if (!data) return;
|
|
|
|
|
|
|
|
if (data->whole_window) /* only handle this for foreign windows */
|
|
|
|
{
|
|
|
|
release_win_data( data );
|
|
|
|
return;
|
|
|
|
}
|
2010-11-08 14:22:09 +00:00
|
|
|
|
|
|
|
rect.left = event->x;
|
|
|
|
rect.top = event->y;
|
|
|
|
rect.right = rect.left + data->whole_rect.right - data->whole_rect.left;
|
|
|
|
rect.bottom = rect.top + data->whole_rect.bottom - data->whole_rect.top;
|
|
|
|
|
|
|
|
TRACE( "win %p/%lx new X rect %d,%d,%dx%d (event %d,%d)\n",
|
|
|
|
hwnd, data->whole_window, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
|
|
|
|
event->x, event->y );
|
|
|
|
|
|
|
|
X11DRV_X_to_window_rect( data, &rect );
|
2012-09-19 11:13:51 +00:00
|
|
|
window_rect = data->window_rect;
|
|
|
|
release_win_data( data );
|
2010-11-08 14:22:09 +00:00
|
|
|
|
2012-09-19 11:13:51 +00:00
|
|
|
if (window_rect.left != rect.left || window_rect.top != rect.top)
|
2010-11-08 14:22:09 +00:00
|
|
|
SetWindowPos( hwnd, 0, rect.left, rect.top, 0, 0,
|
|
|
|
SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOCOPYBITS );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 18:11:43 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* get_window_wm_state
|
|
|
|
*/
|
2012-09-13 18:08:01 +00:00
|
|
|
static int get_window_wm_state( Display *display, Window window )
|
2008-02-27 18:11:43 +00:00
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
CARD32 state;
|
|
|
|
XID icon;
|
|
|
|
} *state;
|
|
|
|
Atom type;
|
|
|
|
int format, ret = -1;
|
|
|
|
unsigned long count, remaining;
|
|
|
|
|
2012-09-13 18:08:01 +00:00
|
|
|
if (!XGetWindowProperty( display, window, x11drv_atom(WM_STATE), 0,
|
2008-02-27 18:11:43 +00:00
|
|
|
sizeof(*state)/sizeof(CARD32), False, x11drv_atom(WM_STATE),
|
|
|
|
&type, &format, &count, &remaining, (unsigned char **)&state ))
|
|
|
|
{
|
2008-04-07 09:41:54 +00:00
|
|
|
if (type == x11drv_atom(WM_STATE) && get_property_size( format, count ) >= sizeof(*state))
|
2008-02-27 18:11:43 +00:00
|
|
|
ret = state->state;
|
|
|
|
XFree( state );
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-20 15:42:47 +00:00
|
|
|
/***********************************************************************
|
2008-04-02 13:55:25 +00:00
|
|
|
* handle_wm_state_notify
|
|
|
|
*
|
|
|
|
* Handle a PropertyNotify for WM_STATE.
|
1999-09-20 15:42:47 +00:00
|
|
|
*/
|
2012-09-13 18:08:01 +00:00
|
|
|
static void handle_wm_state_notify( HWND hwnd, XPropertyEvent *event, BOOL update_window )
|
1999-09-20 15:42:47 +00:00
|
|
|
{
|
2012-09-13 18:08:01 +00:00
|
|
|
struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
|
2010-05-24 14:54:59 +00:00
|
|
|
DWORD style;
|
|
|
|
|
2012-09-13 18:08:01 +00:00
|
|
|
if (!data) return;
|
|
|
|
|
2008-02-27 18:11:43 +00:00
|
|
|
switch(event->state)
|
1999-09-20 15:42:47 +00:00
|
|
|
{
|
2008-02-27 18:11:43 +00:00
|
|
|
case PropertyDelete:
|
2008-09-17 19:13:38 +00:00
|
|
|
TRACE( "%p/%lx: WM_STATE deleted from %d\n", data->hwnd, data->whole_window, data->wm_state );
|
2008-04-02 13:55:25 +00:00
|
|
|
data->wm_state = WithdrawnState;
|
2008-02-27 18:11:43 +00:00
|
|
|
break;
|
1999-09-20 15:42:47 +00:00
|
|
|
case PropertyNewValue:
|
2008-02-27 18:11:43 +00:00
|
|
|
{
|
2008-09-17 19:13:38 +00:00
|
|
|
int old_state = data->wm_state;
|
2012-09-13 18:08:01 +00:00
|
|
|
int new_state = get_window_wm_state( event->display, data->whole_window );
|
2008-02-27 18:11:43 +00:00
|
|
|
if (new_state != -1 && new_state != data->wm_state)
|
|
|
|
{
|
2008-09-17 19:13:38 +00:00
|
|
|
TRACE( "%p/%lx: new WM_STATE %d from %d\n",
|
|
|
|
data->hwnd, data->whole_window, new_state, old_state );
|
2008-02-27 18:11:43 +00:00
|
|
|
data->wm_state = new_state;
|
2008-09-17 19:13:38 +00:00
|
|
|
/* ignore the initial state transition out of withdrawn state */
|
|
|
|
/* metacity does Withdrawn->NormalState->IconicState when mapping an iconic window */
|
|
|
|
if (!old_state) return;
|
2008-02-27 18:11:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
1999-09-20 15:42:47 +00:00
|
|
|
}
|
2008-04-02 13:58:59 +00:00
|
|
|
|
|
|
|
if (!update_window || !data->managed || !data->mapped) return;
|
|
|
|
|
2010-05-24 14:54:59 +00:00
|
|
|
style = GetWindowLongW( data->hwnd, GWL_STYLE );
|
|
|
|
|
2008-04-02 13:58:59 +00:00
|
|
|
if (data->iconic && data->wm_state == NormalState) /* restore window */
|
|
|
|
{
|
|
|
|
data->iconic = FALSE;
|
2008-07-31 15:12:16 +00:00
|
|
|
if (is_net_wm_state_maximized( event->display, data ))
|
|
|
|
{
|
2010-05-24 14:54:59 +00:00
|
|
|
if ((style & WS_MAXIMIZEBOX) && !(style & WS_DISABLED))
|
|
|
|
{
|
|
|
|
TRACE( "restoring to max %p/%lx\n", data->hwnd, data->whole_window );
|
|
|
|
SendMessageW( data->hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0 );
|
|
|
|
}
|
|
|
|
else TRACE( "not restoring to max win %p/%lx style %08x\n",
|
|
|
|
data->hwnd, data->whole_window, style );
|
2008-07-31 15:12:16 +00:00
|
|
|
}
|
2010-05-24 14:54:59 +00:00
|
|
|
else if (style & (WS_MINIMIZE | WS_MAXIMIZE))
|
2008-07-31 15:12:16 +00:00
|
|
|
{
|
|
|
|
TRACE( "restoring win %p/%lx\n", data->hwnd, data->whole_window );
|
|
|
|
SendMessageW( data->hwnd, WM_SYSCOMMAND, SC_RESTORE, 0 );
|
|
|
|
}
|
2010-05-24 14:54:59 +00:00
|
|
|
else TRACE( "not restoring win %p/%lx style %08x\n", data->hwnd, data->whole_window, style );
|
2008-04-02 13:58:59 +00:00
|
|
|
}
|
|
|
|
else if (!data->iconic && data->wm_state == IconicState)
|
|
|
|
{
|
|
|
|
data->iconic = TRUE;
|
2010-05-24 14:54:59 +00:00
|
|
|
if ((style & WS_MINIMIZEBOX) && !(style & WS_DISABLED))
|
|
|
|
{
|
|
|
|
TRACE( "minimizing win %p/%lx\n", data->hwnd, data->whole_window );
|
|
|
|
SendMessageW( data->hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0 );
|
|
|
|
}
|
|
|
|
else TRACE( "not minimizing win %p/%lx style %08x\n", data->hwnd, data->whole_window, style );
|
2008-04-02 13:58:59 +00:00
|
|
|
}
|
1999-09-20 15:42:47 +00:00
|
|
|
}
|
1998-12-07 09:13:40 +00:00
|
|
|
|
2008-02-27 18:13:09 +00:00
|
|
|
|
2008-04-02 13:55:25 +00:00
|
|
|
/***********************************************************************
|
2008-04-17 14:07:06 +00:00
|
|
|
* X11DRV_PropertyNotify
|
2008-04-02 13:55:25 +00:00
|
|
|
*/
|
2008-04-17 14:07:06 +00:00
|
|
|
static void X11DRV_PropertyNotify( HWND hwnd, XEvent *xev )
|
2008-04-02 13:55:25 +00:00
|
|
|
{
|
|
|
|
XPropertyEvent *event = &xev->xproperty;
|
|
|
|
|
|
|
|
if (!hwnd) return;
|
2012-09-13 18:08:01 +00:00
|
|
|
if (event->atom == x11drv_atom(WM_STATE)) handle_wm_state_notify( hwnd, event, TRUE );
|
2008-04-02 13:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 18:13:09 +00:00
|
|
|
/* event filter to wait for a WM_STATE change notification on a window */
|
|
|
|
static Bool is_wm_state_notify( Display *display, XEvent *event, XPointer arg )
|
|
|
|
{
|
2008-03-05 15:52:22 +00:00
|
|
|
if (event->xany.window != (Window)arg) return 0;
|
|
|
|
return (event->type == DestroyNotify ||
|
|
|
|
(event->type == PropertyNotify && event->xproperty.atom == x11drv_atom(WM_STATE)));
|
2008-02-27 18:13:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* wait_for_withdrawn_state
|
|
|
|
*/
|
2012-09-13 18:08:01 +00:00
|
|
|
void wait_for_withdrawn_state( HWND hwnd, BOOL set )
|
2008-02-27 18:13:09 +00:00
|
|
|
{
|
2012-09-13 18:08:01 +00:00
|
|
|
Display *display = thread_display();
|
|
|
|
struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
|
2008-02-27 18:13:09 +00:00
|
|
|
DWORD end = GetTickCount() + 2000;
|
|
|
|
|
2012-09-13 18:08:01 +00:00
|
|
|
if (!data || !data->managed) return;
|
2008-02-27 18:13:09 +00:00
|
|
|
|
2008-03-05 15:52:22 +00:00
|
|
|
TRACE( "waiting for window %p/%lx to become %swithdrawn\n",
|
|
|
|
data->hwnd, data->whole_window, set ? "" : "not " );
|
2008-02-27 18:13:09 +00:00
|
|
|
|
2008-03-05 15:52:22 +00:00
|
|
|
while (data->whole_window && ((data->wm_state == WithdrawnState) == !set))
|
|
|
|
{
|
2008-04-02 13:55:25 +00:00
|
|
|
XEvent event;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
while (XCheckIfEvent( display, &event, is_wm_state_notify, (char *)data->whole_window ))
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
if (XFilterEvent( &event, None )) continue; /* filtered, ignore it */
|
|
|
|
if (event.type == DestroyNotify) call_event_handler( display, &event );
|
2012-09-13 18:08:01 +00:00
|
|
|
else handle_wm_state_notify( hwnd, &event.xproperty, FALSE );
|
2008-04-02 13:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!count)
|
2008-02-27 18:13:09 +00:00
|
|
|
{
|
2008-03-05 15:52:22 +00:00
|
|
|
struct pollfd pfd;
|
|
|
|
int timeout = end - GetTickCount();
|
|
|
|
|
|
|
|
pfd.fd = ConnectionNumber(display);
|
|
|
|
pfd.events = POLLIN;
|
|
|
|
if (timeout <= 0 || poll( &pfd, 1, timeout ) != 1)
|
|
|
|
{
|
|
|
|
FIXME( "window %p/%lx wait timed out\n", data->hwnd, data->whole_window );
|
|
|
|
break;
|
|
|
|
}
|
2008-02-27 18:13:09 +00:00
|
|
|
}
|
|
|
|
}
|
2008-03-05 15:52:22 +00:00
|
|
|
TRACE( "window %p/%lx state now %d\n", data->hwnd, data->whole_window, data->wm_state );
|
2008-02-27 18:13:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-18 09:20:07 +00:00
|
|
|
/*****************************************************************
|
|
|
|
* SetFocus (X11DRV.@)
|
|
|
|
*
|
|
|
|
* Set the X focus.
|
|
|
|
*/
|
|
|
|
void CDECL X11DRV_SetFocus( HWND hwnd )
|
|
|
|
{
|
|
|
|
Display *display = thread_display();
|
|
|
|
struct x11drv_win_data *data;
|
|
|
|
|
|
|
|
if (!(hwnd = GetAncestor( hwnd, GA_ROOT ))) return;
|
2012-09-18 09:24:55 +00:00
|
|
|
if (!(data = get_win_data( hwnd ))) return;
|
2012-09-18 09:20:07 +00:00
|
|
|
if (!data->managed) set_input_focus( display, data->whole_window );
|
2012-09-18 09:24:55 +00:00
|
|
|
release_win_data( data );
|
2012-09-18 09:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-23 20:56:37 +00:00
|
|
|
static HWND find_drop_window( HWND hQueryWnd, LPPOINT lpPt )
|
|
|
|
{
|
|
|
|
RECT tempRect;
|
|
|
|
|
|
|
|
if (!IsWindowEnabled(hQueryWnd)) return 0;
|
|
|
|
|
|
|
|
GetWindowRect(hQueryWnd, &tempRect);
|
|
|
|
|
|
|
|
if(!PtInRect(&tempRect, *lpPt)) return 0;
|
|
|
|
|
|
|
|
if (!IsIconic( hQueryWnd ))
|
|
|
|
{
|
2005-03-24 20:41:27 +00:00
|
|
|
POINT pt = *lpPt;
|
|
|
|
ScreenToClient( hQueryWnd, &pt );
|
2002-09-23 20:56:37 +00:00
|
|
|
GetClientRect( hQueryWnd, &tempRect );
|
|
|
|
|
2005-03-24 20:41:27 +00:00
|
|
|
if (PtInRect( &tempRect, pt))
|
2002-09-23 20:56:37 +00:00
|
|
|
{
|
2005-03-24 20:41:27 +00:00
|
|
|
HWND ret = ChildWindowFromPointEx( hQueryWnd, pt, CWP_SKIPINVISIBLE|CWP_SKIPDISABLED );
|
|
|
|
if (ret && ret != hQueryWnd)
|
2002-09-23 20:56:37 +00:00
|
|
|
{
|
2005-03-24 20:41:27 +00:00
|
|
|
ret = find_drop_window( ret, lpPt );
|
|
|
|
if (ret) return ret;
|
2002-09-23 20:56:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!(GetWindowLongA( hQueryWnd, GWL_EXSTYLE ) & WS_EX_ACCEPTFILES)) return 0;
|
|
|
|
|
|
|
|
ScreenToClient(hQueryWnd, lpPt);
|
|
|
|
|
|
|
|
return hQueryWnd;
|
|
|
|
}
|
|
|
|
|
1998-12-07 09:13:40 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* EVENT_DropFromOffix
|
|
|
|
*
|
2008-01-04 19:37:14 +00:00
|
|
|
* don't know if it still works (last Changelog is from 96/11/04)
|
1998-12-07 09:13:40 +00:00
|
|
|
*/
|
1999-04-15 15:22:23 +00:00
|
|
|
static void EVENT_DropFromOffiX( HWND hWnd, XClientMessageEvent *event )
|
1998-12-07 09:13:40 +00:00
|
|
|
{
|
2008-02-28 19:02:31 +00:00
|
|
|
struct x11drv_win_data *data;
|
2002-09-23 20:56:37 +00:00
|
|
|
unsigned long data_length;
|
|
|
|
unsigned long aux_long;
|
|
|
|
unsigned char* p_data = NULL;
|
2005-11-23 13:30:41 +00:00
|
|
|
Atom atom_aux;
|
2012-09-18 09:37:33 +00:00
|
|
|
int x, y, cx, cy, dummy;
|
2002-09-23 20:56:37 +00:00
|
|
|
BOOL bAccept;
|
2005-01-17 19:17:47 +00:00
|
|
|
Window win, w_aux_root, w_aux_child;
|
2002-09-23 20:56:37 +00:00
|
|
|
|
2012-09-18 09:37:33 +00:00
|
|
|
if (!(data = get_win_data( hWnd ))) return;
|
|
|
|
cx = data->whole_rect.right - data->whole_rect.left;
|
|
|
|
cy = data->whole_rect.bottom - data->whole_rect.top;
|
|
|
|
win = data->whole_window;
|
|
|
|
release_win_data( data );
|
|
|
|
|
2005-01-17 19:17:47 +00:00
|
|
|
XQueryPointer( event->display, win, &w_aux_root, &w_aux_child,
|
2005-11-23 13:30:41 +00:00
|
|
|
&x, &y, &dummy, &dummy, (unsigned int*)&aux_long);
|
2006-10-24 10:38:21 +00:00
|
|
|
x += virtual_screen_rect.left;
|
|
|
|
y += virtual_screen_rect.top;
|
2002-09-23 20:56:37 +00:00
|
|
|
|
|
|
|
/* find out drop point and drop window */
|
2012-09-18 09:37:33 +00:00
|
|
|
if (x < 0 || y < 0 || x > cx || y > cy)
|
|
|
|
{
|
2008-02-28 19:02:31 +00:00
|
|
|
bAccept = GetWindowLongW( hWnd, GWL_EXSTYLE ) & WS_EX_ACCEPTFILES;
|
2002-09-23 20:56:37 +00:00
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
else
|
1998-12-07 09:13:40 +00:00
|
|
|
{
|
2002-09-23 20:56:37 +00:00
|
|
|
POINT pt = { x, y };
|
|
|
|
HWND hwndDrop = find_drop_window( hWnd, &pt );
|
|
|
|
if (hwndDrop)
|
|
|
|
{
|
|
|
|
x = pt.x;
|
|
|
|
y = pt.y;
|
|
|
|
bAccept = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bAccept = FALSE;
|
|
|
|
}
|
1998-12-07 09:13:40 +00:00
|
|
|
}
|
2001-10-16 21:58:58 +00:00
|
|
|
|
|
|
|
if (!bAccept) return;
|
|
|
|
|
2003-11-21 21:48:36 +00:00
|
|
|
XGetWindowProperty( event->display, DefaultRootWindow(event->display),
|
|
|
|
x11drv_atom(DndSelection), 0, 65535, FALSE,
|
2005-11-23 13:30:41 +00:00
|
|
|
AnyPropertyType, &atom_aux, &dummy,
|
2003-11-21 21:48:36 +00:00
|
|
|
&data_length, &aux_long, &p_data);
|
2001-10-16 21:58:58 +00:00
|
|
|
|
|
|
|
if( !aux_long && p_data) /* don't bother if > 64K */
|
1998-12-07 09:13:40 +00:00
|
|
|
{
|
2005-11-23 13:30:41 +00:00
|
|
|
char *p = (char *)p_data;
|
2001-10-16 21:58:58 +00:00
|
|
|
char *p_drop;
|
1999-03-14 17:25:32 +00:00
|
|
|
|
2001-10-16 21:58:58 +00:00
|
|
|
aux_long = 0;
|
|
|
|
while( *p ) /* calculate buffer size */
|
|
|
|
{
|
2005-11-23 13:30:41 +00:00
|
|
|
INT len = GetShortPathNameA( p, NULL, 0 );
|
|
|
|
if (len) aux_long += len + 1;
|
2001-10-16 21:58:58 +00:00
|
|
|
p += strlen(p) + 1;
|
|
|
|
}
|
|
|
|
if( aux_long && aux_long < 65535 )
|
|
|
|
{
|
|
|
|
HDROP hDrop;
|
|
|
|
DROPFILES *lpDrop;
|
|
|
|
|
|
|
|
aux_long += sizeof(DROPFILES) + 1;
|
|
|
|
hDrop = GlobalAlloc( GMEM_SHARE, aux_long );
|
2008-12-01 01:09:52 +00:00
|
|
|
lpDrop = GlobalLock( hDrop );
|
2001-10-16 21:58:58 +00:00
|
|
|
|
|
|
|
if( lpDrop )
|
|
|
|
{
|
|
|
|
lpDrop->pFiles = sizeof(DROPFILES);
|
|
|
|
lpDrop->pt.x = x;
|
|
|
|
lpDrop->pt.y = y;
|
2008-02-28 19:02:31 +00:00
|
|
|
lpDrop->fNC = FALSE;
|
2001-10-16 21:58:58 +00:00
|
|
|
lpDrop->fWide = FALSE;
|
|
|
|
p_drop = (char *)(lpDrop + 1);
|
2005-11-23 13:30:41 +00:00
|
|
|
p = (char *)p_data;
|
2001-10-16 21:58:58 +00:00
|
|
|
while(*p)
|
|
|
|
{
|
2005-11-23 13:30:41 +00:00
|
|
|
if (GetShortPathNameA( p, p_drop, aux_long - (p_drop - (char *)lpDrop) ))
|
2001-10-16 21:58:58 +00:00
|
|
|
p_drop += strlen( p_drop ) + 1;
|
|
|
|
p += strlen(p) + 1;
|
|
|
|
}
|
|
|
|
*p_drop = '\0';
|
|
|
|
PostMessageA( hWnd, WM_DROPFILES, (WPARAM)hDrop, 0L );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-11-21 21:48:36 +00:00
|
|
|
if( p_data ) XFree(p_data);
|
1998-12-07 09:13:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* EVENT_DropURLs
|
|
|
|
*
|
2002-05-31 23:06:46 +00:00
|
|
|
* drop items are separated by \n
|
1998-12-07 09:13:40 +00:00
|
|
|
* each item is prefixed by its mime type
|
|
|
|
*
|
|
|
|
* event->data.l[3], event->data.l[4] contains drop x,y position
|
|
|
|
*/
|
1999-04-15 15:22:23 +00:00
|
|
|
static void EVENT_DropURLs( HWND hWnd, XClientMessageEvent *event )
|
1998-12-07 09:13:40 +00:00
|
|
|
{
|
2008-02-28 19:02:31 +00:00
|
|
|
struct x11drv_win_data *win_data;
|
1998-12-07 09:13:40 +00:00
|
|
|
unsigned long data_length;
|
|
|
|
unsigned long aux_long, drop_len = 0;
|
|
|
|
unsigned char *p_data = NULL; /* property data */
|
|
|
|
char *p_drop = NULL;
|
|
|
|
char *p, *next;
|
2000-09-25 23:56:41 +00:00
|
|
|
int x, y;
|
|
|
|
DROPFILES *lpDrop;
|
|
|
|
HDROP hDrop;
|
1998-12-07 09:13:40 +00:00
|
|
|
union {
|
|
|
|
Atom atom_aux;
|
|
|
|
int i;
|
|
|
|
Window w_aux;
|
2005-08-16 16:02:45 +00:00
|
|
|
unsigned int u;
|
1998-12-07 09:13:40 +00:00
|
|
|
} u; /* unused */
|
|
|
|
|
2001-10-16 21:58:58 +00:00
|
|
|
if (!(GetWindowLongW( hWnd, GWL_EXSTYLE ) & WS_EX_ACCEPTFILES)) return;
|
1998-12-07 09:13:40 +00:00
|
|
|
|
2003-11-21 21:48:36 +00:00
|
|
|
XGetWindowProperty( event->display, DefaultRootWindow(event->display),
|
|
|
|
x11drv_atom(DndSelection), 0, 65535, FALSE,
|
|
|
|
AnyPropertyType, &u.atom_aux, &u.i,
|
|
|
|
&data_length, &aux_long, &p_data);
|
1998-12-07 09:13:40 +00:00
|
|
|
if (aux_long)
|
1999-12-08 03:56:23 +00:00
|
|
|
WARN("property too large, truncated!\n");
|
|
|
|
TRACE("urls=%s\n", p_data);
|
1998-12-07 09:13:40 +00:00
|
|
|
|
|
|
|
if( !aux_long && p_data) { /* don't bother if > 64K */
|
|
|
|
/* calculate length */
|
2005-08-16 16:02:45 +00:00
|
|
|
p = (char*) p_data;
|
1998-12-07 09:13:40 +00:00
|
|
|
next = strchr(p, '\n');
|
|
|
|
while (p) {
|
|
|
|
if (next) *next=0;
|
|
|
|
if (strncmp(p,"file:",5) == 0 ) {
|
1999-02-26 11:11:13 +00:00
|
|
|
INT len = GetShortPathNameA( p+5, NULL, 0 );
|
1998-12-07 09:13:40 +00:00
|
|
|
if (len) drop_len += len + 1;
|
|
|
|
}
|
2002-05-31 23:06:46 +00:00
|
|
|
if (next) {
|
|
|
|
*next = '\n';
|
1998-12-07 09:13:40 +00:00
|
|
|
p = next + 1;
|
|
|
|
next = strchr(p, '\n');
|
|
|
|
} else {
|
|
|
|
p = NULL;
|
|
|
|
}
|
|
|
|
}
|
2002-05-31 23:06:46 +00:00
|
|
|
|
1998-12-07 09:13:40 +00:00
|
|
|
if( drop_len && drop_len < 65535 ) {
|
2003-11-21 21:48:36 +00:00
|
|
|
XQueryPointer( event->display, root_window, &u.w_aux, &u.w_aux,
|
2005-08-16 16:02:45 +00:00
|
|
|
&x, &y, &u.i, &u.i, &u.u);
|
2006-10-24 10:38:21 +00:00
|
|
|
x += virtual_screen_rect.left;
|
|
|
|
y += virtual_screen_rect.top;
|
1999-04-15 15:22:23 +00:00
|
|
|
|
2000-09-25 23:56:41 +00:00
|
|
|
drop_len += sizeof(DROPFILES) + 1;
|
2001-01-02 21:00:46 +00:00
|
|
|
hDrop = GlobalAlloc( GMEM_SHARE, drop_len );
|
2008-12-01 01:09:52 +00:00
|
|
|
lpDrop = GlobalLock( hDrop );
|
2000-09-25 23:56:41 +00:00
|
|
|
|
2012-09-18 09:37:33 +00:00
|
|
|
if( lpDrop && (win_data = get_win_data( hWnd )))
|
2008-02-28 19:02:31 +00:00
|
|
|
{
|
2000-09-25 23:56:41 +00:00
|
|
|
lpDrop->pFiles = sizeof(DROPFILES);
|
2008-02-02 17:27:19 +00:00
|
|
|
lpDrop->pt.x = x;
|
|
|
|
lpDrop->pt.y = y;
|
2000-09-25 23:56:41 +00:00
|
|
|
lpDrop->fNC =
|
2008-02-28 19:02:31 +00:00
|
|
|
( x < (win_data->client_rect.left - win_data->whole_rect.left) ||
|
|
|
|
y < (win_data->client_rect.top - win_data->whole_rect.top) ||
|
|
|
|
x > (win_data->client_rect.right - win_data->whole_rect.left) ||
|
|
|
|
y > (win_data->client_rect.bottom - win_data->whole_rect.top) );
|
2000-09-25 23:56:41 +00:00
|
|
|
lpDrop->fWide = FALSE;
|
|
|
|
p_drop = (char*)(lpDrop + 1);
|
2012-09-18 09:37:33 +00:00
|
|
|
release_win_data( win_data );
|
1998-12-07 09:13:40 +00:00
|
|
|
}
|
2000-09-25 23:56:41 +00:00
|
|
|
|
1998-12-07 09:13:40 +00:00
|
|
|
/* create message content */
|
|
|
|
if (p_drop) {
|
2005-08-16 16:02:45 +00:00
|
|
|
p = (char*) p_data;
|
1998-12-07 09:13:40 +00:00
|
|
|
next = strchr(p, '\n');
|
|
|
|
while (p) {
|
|
|
|
if (next) *next=0;
|
|
|
|
if (strncmp(p,"file:",5) == 0 ) {
|
1999-02-26 11:11:13 +00:00
|
|
|
INT len = GetShortPathNameA( p+5, p_drop, 65535 );
|
1998-12-07 09:13:40 +00:00
|
|
|
if (len) {
|
1999-12-08 03:56:23 +00:00
|
|
|
TRACE("drop file %s as %s\n", p+5, p_drop);
|
1998-12-07 09:13:40 +00:00
|
|
|
p_drop += len+1;
|
|
|
|
} else {
|
2005-11-10 12:14:56 +00:00
|
|
|
WARN("can't convert file %s to dos name\n", p+5);
|
1998-12-07 09:13:40 +00:00
|
|
|
}
|
|
|
|
} else {
|
1999-12-08 03:56:23 +00:00
|
|
|
WARN("unknown mime type %s\n", p);
|
1998-12-07 09:13:40 +00:00
|
|
|
}
|
2002-05-31 23:06:46 +00:00
|
|
|
if (next) {
|
|
|
|
*next = '\n';
|
1998-12-07 09:13:40 +00:00
|
|
|
p = next + 1;
|
|
|
|
next = strchr(p, '\n');
|
|
|
|
} else {
|
|
|
|
p = NULL;
|
|
|
|
}
|
|
|
|
*p_drop = '\0';
|
|
|
|
}
|
|
|
|
|
2000-09-25 23:56:41 +00:00
|
|
|
GlobalUnlock(hDrop);
|
2001-01-02 21:00:46 +00:00
|
|
|
PostMessageA( hWnd, WM_DROPFILES, (WPARAM)hDrop, 0L );
|
1998-12-07 09:13:40 +00:00
|
|
|
}
|
|
|
|
}
|
2003-11-21 21:48:36 +00:00
|
|
|
if( p_data ) XFree(p_data);
|
1998-12-07 09:13:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-01 18:45:12 +00:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* handle_xembed_protocol
|
|
|
|
*/
|
|
|
|
static void handle_xembed_protocol( HWND hwnd, XClientMessageEvent *event )
|
|
|
|
{
|
2012-09-19 11:14:00 +00:00
|
|
|
struct x11drv_win_data *data = get_win_data( hwnd );
|
2010-11-01 18:45:12 +00:00
|
|
|
|
|
|
|
if (!data) return;
|
|
|
|
|
|
|
|
switch (event->data.l[1])
|
|
|
|
{
|
|
|
|
case XEMBED_EMBEDDED_NOTIFY:
|
|
|
|
TRACE( "win %p/%lx XEMBED_EMBEDDED_NOTIFY owner %lx\n", hwnd, event->window, event->data.l[3] );
|
|
|
|
data->embedder = event->data.l[3];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
TRACE( "win %p/%lx XEMBED message %lu(%lu)\n",
|
|
|
|
hwnd, event->window, event->data.l[1], event->data.l[2] );
|
|
|
|
break;
|
|
|
|
}
|
2012-09-19 11:14:00 +00:00
|
|
|
release_win_data( data );
|
2010-11-01 18:45:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-01 11:52:02 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* handle_dnd_protocol
|
|
|
|
*/
|
|
|
|
static void handle_dnd_protocol( HWND hwnd, XClientMessageEvent *event )
|
|
|
|
{
|
|
|
|
Window root, child;
|
|
|
|
int root_x, root_y, child_x, child_y;
|
|
|
|
unsigned int u;
|
|
|
|
|
|
|
|
/* query window (drag&drop event contains only drag window) */
|
|
|
|
XQueryPointer( event->display, root_window, &root, &child,
|
|
|
|
&root_x, &root_y, &child_x, &child_y, &u);
|
|
|
|
if (XFindContext( event->display, child, winContext, (char **)&hwnd ) != 0) hwnd = 0;
|
|
|
|
if (!hwnd) return;
|
|
|
|
if (event->data.l[0] == DndFile || event->data.l[0] == DndFiles)
|
|
|
|
EVENT_DropFromOffiX(hwnd, event);
|
|
|
|
else if (event->data.l[0] == DndURL)
|
|
|
|
EVENT_DropURLs(hwnd, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct client_message_handler
|
|
|
|
{
|
|
|
|
int atom; /* protocol atom */
|
|
|
|
void (*handler)(HWND, XClientMessageEvent *); /* corresponding handler function */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct client_message_handler client_messages[] =
|
|
|
|
{
|
2010-11-01 18:57:12 +00:00
|
|
|
{ XATOM_MANAGER, handle_manager_message },
|
2005-03-01 11:52:02 +00:00
|
|
|
{ XATOM_WM_PROTOCOLS, handle_wm_protocols },
|
2010-11-01 18:45:12 +00:00
|
|
|
{ XATOM__XEMBED, handle_xembed_protocol },
|
2005-03-01 11:52:02 +00:00
|
|
|
{ XATOM_DndProtocol, handle_dnd_protocol },
|
|
|
|
{ XATOM_XdndEnter, X11DRV_XDND_EnterEvent },
|
|
|
|
{ XATOM_XdndPosition, X11DRV_XDND_PositionEvent },
|
|
|
|
{ XATOM_XdndDrop, X11DRV_XDND_DropEvent },
|
|
|
|
{ XATOM_XdndLeave, X11DRV_XDND_LeaveEvent }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
1998-12-07 09:13:40 +00:00
|
|
|
/**********************************************************************
|
2008-04-17 14:07:06 +00:00
|
|
|
* X11DRV_ClientMessage
|
1998-12-07 09:13:40 +00:00
|
|
|
*/
|
2008-04-17 14:07:06 +00:00
|
|
|
static void X11DRV_ClientMessage( HWND hwnd, XEvent *xev )
|
1998-12-07 09:13:40 +00:00
|
|
|
{
|
2005-02-26 17:49:38 +00:00
|
|
|
XClientMessageEvent *event = &xev->xclient;
|
2005-03-01 11:52:02 +00:00
|
|
|
unsigned int i;
|
2005-02-26 17:49:38 +00:00
|
|
|
|
2005-03-01 11:52:02 +00:00
|
|
|
if (!hwnd) return;
|
2005-02-26 17:49:38 +00:00
|
|
|
|
2005-03-01 11:52:02 +00:00
|
|
|
if (event->format != 32)
|
2001-06-04 21:55:17 +00:00
|
|
|
{
|
2005-03-01 11:52:02 +00:00
|
|
|
WARN( "Don't know how to handle format %d\n", event->format );
|
|
|
|
return;
|
1999-04-18 09:21:01 +00:00
|
|
|
}
|
2005-03-01 11:52:02 +00:00
|
|
|
|
|
|
|
for (i = 0; i < sizeof(client_messages)/sizeof(client_messages[0]); i++)
|
2003-11-20 22:09:51 +00:00
|
|
|
{
|
2005-03-01 11:52:02 +00:00
|
|
|
if (event->message_type == X11DRV_Atoms[client_messages[i].atom - FIRST_XATOM])
|
|
|
|
{
|
|
|
|
client_messages[i].handler( hwnd, event );
|
|
|
|
return;
|
|
|
|
}
|
1998-12-07 09:13:40 +00:00
|
|
|
}
|
2005-03-01 11:52:02 +00:00
|
|
|
TRACE( "no handler found for %ld\n", event->message_type );
|
1998-12-07 09:13:40 +00:00
|
|
|
}
|