2011-08-09 06:24:12 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Client
|
|
|
|
* X11 Windows
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2011-10-28 20:27:09 +04:00
|
|
|
#include <X11/Xlib.h>
|
2011-08-09 06:24:12 +04:00
|
|
|
#include <X11/Xutil.h>
|
2011-08-23 23:52:17 +04:00
|
|
|
#include <X11/Xatom.h>
|
2011-08-24 06:58:36 +04:00
|
|
|
|
2011-09-02 02:08:53 +04:00
|
|
|
#include <freerdp/rail.h>
|
|
|
|
#include <freerdp/utils/rail.h>
|
|
|
|
|
|
|
|
|
2011-08-24 06:58:36 +04:00
|
|
|
#ifdef WITH_XEXT
|
2011-08-23 00:06:12 +04:00
|
|
|
#include <X11/extensions/shape.h>
|
2011-08-24 06:58:36 +04:00
|
|
|
#endif
|
2011-08-09 06:24:12 +04:00
|
|
|
|
2011-10-22 20:55:03 +04:00
|
|
|
#include "FreeRDP_Icon_256px.h"
|
|
|
|
#define xf_icon_prop FreeRDP_Icon_256px_prop
|
|
|
|
|
2011-08-09 06:24:12 +04:00
|
|
|
#include "xf_window.h"
|
|
|
|
|
2011-08-17 22:13:44 +04:00
|
|
|
/* Extended Window Manager Hints: http://standards.freedesktop.org/wm-spec/wm-spec-1.3.html */
|
|
|
|
|
2011-08-09 06:24:12 +04:00
|
|
|
#define MWM_HINTS_DECORATIONS (1L << 1)
|
|
|
|
#define PROP_MOTIF_WM_HINTS_ELEMENTS 5
|
|
|
|
|
|
|
|
struct _PropMotifWmHints
|
|
|
|
{
|
2011-08-18 00:57:21 +04:00
|
|
|
unsigned long flags;
|
|
|
|
unsigned long functions;
|
|
|
|
unsigned long decorations;
|
|
|
|
long inputMode;
|
|
|
|
unsigned long status;
|
2011-08-09 06:24:12 +04:00
|
|
|
};
|
|
|
|
typedef struct _PropMotifWmHints PropMotifWmHints;
|
|
|
|
|
2011-08-24 08:46:34 +04:00
|
|
|
void xf_SendClientMessage(xfInfo* xfi, xfWindow* window, Atom atom, long msg, long d1, long d2, long d3)
|
|
|
|
{
|
|
|
|
XEvent xevent;
|
|
|
|
|
|
|
|
xevent.xclient.type = ClientMessage;
|
|
|
|
xevent.xclient.message_type = atom;
|
|
|
|
xevent.xclient.window = window->handle;
|
|
|
|
xevent.xclient.format = 32;
|
|
|
|
xevent.xclient.data.l[0] = CurrentTime;
|
|
|
|
xevent.xclient.data.l[1] = msg;
|
|
|
|
xevent.xclient.data.l[2] = d1;
|
|
|
|
xevent.xclient.data.l[3] = d2;
|
|
|
|
xevent.xclient.data.l[4] = d3;
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
XSendEvent(xfi->display, window->handle, false, NoEventMask, &xevent);
|
|
|
|
XSync(xfi->display, false);
|
2011-08-24 08:46:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void xf_SetWindowFullscreen(xfInfo* xfi, xfWindow* window, boolean fullscreen)
|
2011-08-09 06:24:12 +04:00
|
|
|
{
|
|
|
|
if (fullscreen)
|
|
|
|
{
|
2011-11-19 21:19:16 +04:00
|
|
|
xf_SetWindowDecorations(xfi, window, false);
|
2011-08-09 06:24:12 +04:00
|
|
|
|
2011-08-24 08:46:34 +04:00
|
|
|
XMoveResizeWindow(xfi->display, window->handle, 0, 0, window->width, window->height);
|
|
|
|
XMapRaised(xfi->display, window->handle);
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
window->fullscreen = true;
|
2011-08-09 06:24:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-17 22:13:44 +04:00
|
|
|
/* http://tronche.com/gui/x/xlib/window-information/XGetWindowProperty.html */
|
|
|
|
|
2011-08-24 08:46:34 +04:00
|
|
|
boolean xf_GetWindowProperty(xfInfo* xfi, Window window, Atom property, int length,
|
2011-08-17 22:13:44 +04:00
|
|
|
unsigned long* nitems, unsigned long* bytes, uint8** prop)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
Atom actual_type;
|
|
|
|
int actual_format;
|
|
|
|
|
|
|
|
if (property == None)
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-17 22:13:44 +04:00
|
|
|
|
|
|
|
status = XGetWindowProperty(xfi->display, window,
|
2011-11-19 21:19:16 +04:00
|
|
|
property, 0, length, false, AnyPropertyType,
|
2011-08-17 22:13:44 +04:00
|
|
|
&actual_type, &actual_format, nitems, bytes, prop);
|
|
|
|
|
|
|
|
if (status != Success)
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-17 22:13:44 +04:00
|
|
|
|
2011-10-17 17:39:06 +04:00
|
|
|
if (actual_type == None)
|
|
|
|
{
|
|
|
|
DEBUG_WARN("Property %lu does not exist", property);
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-10-17 17:39:06 +04:00
|
|
|
}
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-17 22:13:44 +04:00
|
|
|
}
|
|
|
|
|
2011-08-24 08:46:34 +04:00
|
|
|
boolean xf_GetCurrentDesktop(xfInfo* xfi)
|
2011-08-17 22:13:44 +04:00
|
|
|
{
|
|
|
|
boolean status;
|
|
|
|
unsigned long nitems;
|
|
|
|
unsigned long bytes;
|
|
|
|
unsigned char* prop;
|
|
|
|
|
2011-08-24 08:46:34 +04:00
|
|
|
status = xf_GetWindowProperty(xfi, DefaultRootWindow(xfi->display),
|
|
|
|
xfi->_NET_CURRENT_DESKTOP, 1, &nitems, &bytes, &prop);
|
2011-08-17 22:13:44 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
if (status != true) {
|
|
|
|
return false;
|
2011-11-01 23:31:57 +04:00
|
|
|
}
|
2011-08-17 22:13:44 +04:00
|
|
|
|
|
|
|
xfi->current_desktop = (int) *prop;
|
|
|
|
xfree(prop);
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-17 22:13:44 +04:00
|
|
|
}
|
|
|
|
|
2011-08-24 08:46:34 +04:00
|
|
|
boolean xf_GetWorkArea(xfInfo* xfi)
|
2011-08-17 22:13:44 +04:00
|
|
|
{
|
|
|
|
long* plong;
|
|
|
|
boolean status;
|
|
|
|
unsigned long nitems;
|
|
|
|
unsigned long bytes;
|
|
|
|
unsigned char* prop;
|
|
|
|
|
2011-11-01 23:31:57 +04:00
|
|
|
status = xf_GetCurrentDesktop(xfi);
|
2011-08-17 22:13:44 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
if (status != true)
|
|
|
|
return false;
|
2011-08-17 22:13:44 +04:00
|
|
|
|
2011-11-01 23:31:57 +04:00
|
|
|
status = xf_GetWindowProperty(xfi, DefaultRootWindow(xfi->display),
|
|
|
|
xfi->_NET_WORKAREA, 32 * 4, &nitems, &bytes, &prop);
|
2011-09-27 07:06:45 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
if (status != true)
|
|
|
|
return false;
|
2011-08-17 22:13:44 +04:00
|
|
|
|
2011-11-01 23:31:57 +04:00
|
|
|
if ((xfi->current_desktop * 4 + 3) >= nitems) {
|
|
|
|
xfree(prop);
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-11-01 23:31:57 +04:00
|
|
|
}
|
|
|
|
|
2011-08-17 22:13:44 +04:00
|
|
|
plong = (long*) prop;
|
|
|
|
|
|
|
|
xfi->workArea.x = plong[xfi->current_desktop * 4 + 0];
|
|
|
|
xfi->workArea.y = plong[xfi->current_desktop * 4 + 1];
|
|
|
|
xfi->workArea.width = plong[xfi->current_desktop * 4 + 2];
|
|
|
|
xfi->workArea.height = plong[xfi->current_desktop * 4 + 3];
|
|
|
|
xfree(prop);
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-17 22:13:44 +04:00
|
|
|
}
|
|
|
|
|
2011-08-24 08:46:34 +04:00
|
|
|
void xf_SetWindowDecorations(xfInfo* xfi, xfWindow* window, boolean show)
|
2011-08-09 06:24:12 +04:00
|
|
|
{
|
|
|
|
PropMotifWmHints hints;
|
|
|
|
|
2011-08-24 08:46:34 +04:00
|
|
|
hints.decorations = show;
|
2011-08-09 06:24:12 +04:00
|
|
|
hints.flags = MWM_HINTS_DECORATIONS;
|
|
|
|
|
2011-08-24 08:46:34 +04:00
|
|
|
XChangeProperty(xfi->display, window->handle, xfi->_MOTIF_WM_HINTS, xfi->_MOTIF_WM_HINTS, 32,
|
|
|
|
PropModeReplace, (uint8*) &hints, PROP_MOTIF_WM_HINTS_ELEMENTS);
|
2011-08-09 06:24:12 +04:00
|
|
|
}
|
|
|
|
|
2011-08-30 22:21:16 +04:00
|
|
|
void xf_SetWindowUnlisted(xfInfo* xfi, xfWindow* window)
|
|
|
|
{
|
|
|
|
Atom window_state[2];
|
|
|
|
|
|
|
|
window_state[0] = xfi->_NET_WM_STATE_SKIP_PAGER;
|
|
|
|
window_state[1] = xfi->_NET_WM_STATE_SKIP_TASKBAR;
|
|
|
|
|
|
|
|
XChangeProperty(xfi->display, window->handle, xfi->_NET_WM_STATE,
|
|
|
|
XA_ATOM, 32, PropModeReplace, (uint8*) &window_state, 2);
|
|
|
|
}
|
|
|
|
|
2011-08-25 01:16:57 +04:00
|
|
|
void xf_SetWindowStyle(xfInfo* xfi, xfWindow* window, uint32 style, uint32 ex_style)
|
|
|
|
{
|
|
|
|
Atom window_type;
|
|
|
|
|
|
|
|
window_type = xfi->_NET_WM_WINDOW_TYPE_NORMAL;
|
|
|
|
|
2011-08-30 22:21:16 +04:00
|
|
|
if ((style & WS_POPUP) || (style & WS_DLGFRAME) || (ex_style & WS_EX_DLGMODALFRAME))
|
2011-08-25 01:16:57 +04:00
|
|
|
{
|
|
|
|
window_type = xfi->_NET_WM_WINDOW_TYPE_DIALOG;
|
|
|
|
}
|
2011-08-30 22:21:16 +04:00
|
|
|
|
|
|
|
if (ex_style & WS_EX_TOOLWINDOW)
|
2011-08-25 01:16:57 +04:00
|
|
|
{
|
2011-08-30 22:21:16 +04:00
|
|
|
xf_SetWindowUnlisted(xfi, window);
|
2011-08-25 01:16:57 +04:00
|
|
|
window_type = xfi->_NET_WM_WINDOW_TYPE_UTILITY;
|
|
|
|
}
|
|
|
|
|
|
|
|
XChangeProperty(xfi->display, window->handle, xfi->_NET_WM_WINDOW_TYPE,
|
2011-08-30 22:21:16 +04:00
|
|
|
XA_ATOM, 32, PropModeReplace, (uint8*) &window_type, 1);
|
2011-08-25 01:16:57 +04:00
|
|
|
}
|
|
|
|
|
2011-10-07 23:50:07 +04:00
|
|
|
xfWindow* xf_CreateDesktopWindow(xfInfo* xfi, char* name, int width, int height, boolean decorations)
|
2011-08-09 06:24:12 +04:00
|
|
|
{
|
|
|
|
xfWindow* window;
|
|
|
|
|
|
|
|
window = (xfWindow*) xzalloc(sizeof(xfWindow));
|
|
|
|
|
|
|
|
if (window != NULL)
|
|
|
|
{
|
|
|
|
int input_mask;
|
|
|
|
XClassHint* class_hints;
|
|
|
|
|
2011-08-24 08:46:34 +04:00
|
|
|
window->width = width;
|
|
|
|
window->height = height;
|
2011-11-19 21:19:16 +04:00
|
|
|
window->fullscreen = false;
|
2011-10-07 23:50:07 +04:00
|
|
|
window->decorations = decorations;
|
2011-08-09 06:24:12 +04:00
|
|
|
|
|
|
|
window->handle = XCreateWindow(xfi->display, RootWindowOfScreen(xfi->screen),
|
2011-08-17 22:51:17 +04:00
|
|
|
xfi->workArea.x, xfi->workArea.y, xfi->width, xfi->height, 0, xfi->depth, InputOutput, xfi->visual,
|
2011-08-09 06:24:12 +04:00
|
|
|
CWBackPixel | CWBackingStore | CWOverrideRedirect | CWColormap |
|
|
|
|
CWBorderPixel, &xfi->attribs);
|
|
|
|
|
|
|
|
class_hints = XAllocClassHint();
|
|
|
|
|
|
|
|
if (class_hints != NULL)
|
|
|
|
{
|
2011-09-14 06:20:04 +04:00
|
|
|
class_hints->res_name = "xfreerdp";
|
|
|
|
class_hints->res_class = "xfreerdp";
|
2011-08-09 06:24:12 +04:00
|
|
|
XSetClassHint(xfi->display, window->handle, class_hints);
|
|
|
|
XFree(class_hints);
|
|
|
|
}
|
|
|
|
|
2011-09-06 12:22:53 +04:00
|
|
|
xf_ResizeDesktopWindow(xfi, window, width, height);
|
2011-10-07 23:50:07 +04:00
|
|
|
xf_SetWindowDecorations(xfi, window, decorations);
|
2011-08-09 06:24:12 +04:00
|
|
|
|
|
|
|
input_mask =
|
|
|
|
KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
|
|
|
|
VisibilityChangeMask | FocusChangeMask | StructureNotifyMask |
|
2011-10-05 02:46:49 +04:00
|
|
|
PointerMotionMask | ExposureMask | PropertyChangeMask;
|
|
|
|
|
|
|
|
if (xfi->grab_keyboard)
|
|
|
|
input_mask |= EnterWindowMask | LeaveWindowMask;
|
2011-08-09 06:24:12 +04:00
|
|
|
|
2011-10-22 20:55:03 +04:00
|
|
|
XChangeProperty(xfi->display, window->handle, xfi->_NET_WM_ICON, XA_CARDINAL, 32,
|
|
|
|
PropModeReplace, (uint8*) xf_icon_prop, sizeof(xf_icon_prop) / sizeof(long));
|
|
|
|
|
2011-08-09 06:24:12 +04:00
|
|
|
XSelectInput(xfi->display, window->handle, input_mask);
|
|
|
|
XMapWindow(xfi->display, window->handle);
|
|
|
|
}
|
|
|
|
|
2011-09-14 06:20:04 +04:00
|
|
|
XStoreName(xfi->display, window->handle, name);
|
|
|
|
|
2011-08-09 06:24:12 +04:00
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2011-09-06 12:22:53 +04:00
|
|
|
void xf_ResizeDesktopWindow(xfInfo* xfi, xfWindow* window, int width, int height)
|
|
|
|
{
|
|
|
|
XSizeHints* size_hints;
|
|
|
|
|
|
|
|
size_hints = XAllocSizeHints();
|
|
|
|
|
|
|
|
if (size_hints)
|
|
|
|
{
|
|
|
|
size_hints->flags = PMinSize | PMaxSize;
|
|
|
|
size_hints->min_width = size_hints->max_width = xfi->width;
|
|
|
|
size_hints->min_height = size_hints->max_height = xfi->height;
|
|
|
|
XSetWMNormalHints(xfi->display, window->handle, size_hints);
|
|
|
|
XFree(size_hints);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-02 21:29:17 +04:00
|
|
|
void xf_FixWindowCoordinates(xfInfo* xfi, int* x, int* y, int* width, int* height)
|
2011-08-23 05:22:05 +04:00
|
|
|
{
|
2011-09-02 21:29:17 +04:00
|
|
|
int vscreen_width;
|
|
|
|
int vscreen_height;
|
|
|
|
|
|
|
|
vscreen_width = xfi->vscreen.area.right - xfi->vscreen.area.left + 1;
|
|
|
|
vscreen_height = xfi->vscreen.area.bottom - xfi->vscreen.area.top + 1;
|
|
|
|
|
2011-10-31 21:55:05 +04:00
|
|
|
if (*width < 1)
|
|
|
|
{
|
|
|
|
*width = 1;
|
|
|
|
}
|
|
|
|
if (*height < 1)
|
|
|
|
{
|
|
|
|
*height = 1;
|
|
|
|
}
|
2011-09-02 21:29:17 +04:00
|
|
|
if (*x < xfi->vscreen.area.left)
|
2011-08-23 05:22:05 +04:00
|
|
|
{
|
|
|
|
*width += *x;
|
2011-09-02 21:29:17 +04:00
|
|
|
*x = xfi->vscreen.area.left;
|
2011-08-23 05:22:05 +04:00
|
|
|
}
|
2011-09-02 21:29:17 +04:00
|
|
|
if (*y < xfi->vscreen.area.top)
|
2011-08-23 05:22:05 +04:00
|
|
|
{
|
|
|
|
*height += *y;
|
2011-09-02 21:29:17 +04:00
|
|
|
*y = xfi->vscreen.area.top;
|
|
|
|
}
|
|
|
|
if (*width > vscreen_width)
|
|
|
|
{
|
|
|
|
*width = vscreen_width;
|
|
|
|
}
|
|
|
|
if (*height > vscreen_height)
|
|
|
|
{
|
|
|
|
*height = vscreen_height;
|
2011-08-23 05:22:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-22 07:54:02 +04:00
|
|
|
char rail_window_class[] = "RAIL:00000000";
|
|
|
|
|
2011-09-23 05:23:01 +04:00
|
|
|
xfWindow* xf_CreateWindow(xfInfo* xfi, rdpWindow* wnd, int x, int y, int width, int height, uint32 id)
|
2011-08-17 10:14:02 +04:00
|
|
|
{
|
|
|
|
xfWindow* window;
|
|
|
|
|
|
|
|
window = (xfWindow*) xzalloc(sizeof(xfWindow));
|
|
|
|
|
2011-09-02 21:29:17 +04:00
|
|
|
xf_FixWindowCoordinates(xfi, &x, &y, &width, &height);
|
2011-08-23 05:22:05 +04:00
|
|
|
|
|
|
|
window->left = x;
|
|
|
|
window->top = y;
|
|
|
|
window->right = x + width - 1;
|
|
|
|
window->bottom = y + height - 1;
|
2011-08-17 10:14:02 +04:00
|
|
|
window->width = width;
|
|
|
|
window->height = height;
|
|
|
|
|
2011-10-31 21:55:05 +04:00
|
|
|
XGCValues gcv;
|
|
|
|
int input_mask;
|
|
|
|
XClassHint* class_hints;
|
2011-08-17 10:14:02 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
window->decorations = false;
|
|
|
|
window->fullscreen = false;
|
2011-10-31 21:55:05 +04:00
|
|
|
window->window = wnd;
|
2011-11-19 21:19:16 +04:00
|
|
|
window->localMoveSize = false;
|
2011-08-25 01:16:57 +04:00
|
|
|
|
2011-10-31 21:55:05 +04:00
|
|
|
window->handle = XCreateWindow(xfi->display, RootWindowOfScreen(xfi->screen),
|
|
|
|
x, y, window->width, window->height, 0, xfi->depth, InputOutput, xfi->visual,
|
|
|
|
CWBackPixel | CWBackingStore | CWOverrideRedirect | CWColormap |
|
|
|
|
CWBorderPixel, &xfi->attribs);
|
2011-08-17 10:14:02 +04:00
|
|
|
|
2011-10-31 21:55:05 +04:00
|
|
|
xf_SetWindowDecorations(xfi, window, window->decorations);
|
2011-08-17 10:14:02 +04:00
|
|
|
|
2011-10-31 21:55:05 +04:00
|
|
|
class_hints = XAllocClassHint();
|
2011-08-17 10:14:02 +04:00
|
|
|
|
2011-10-31 21:55:05 +04:00
|
|
|
if (class_hints != NULL)
|
|
|
|
{
|
|
|
|
char* class;
|
|
|
|
class = xmalloc(sizeof(rail_window_class));
|
|
|
|
snprintf(class, sizeof(rail_window_class), "RAIL:%08X", id);
|
|
|
|
class_hints->res_name = "RAIL";
|
|
|
|
class_hints->res_class = class;
|
|
|
|
XSetClassHint(xfi->display, window->handle, class_hints);
|
|
|
|
XFree(class_hints);
|
|
|
|
xfree(class);
|
|
|
|
}
|
2011-08-17 10:14:02 +04:00
|
|
|
|
2011-10-31 21:55:05 +04:00
|
|
|
XSetWMProtocols(xfi->display, window->handle, &(xfi->WM_DELETE_WINDOW), 1);
|
2011-09-21 16:36:49 +04:00
|
|
|
|
2011-10-31 21:55:05 +04:00
|
|
|
input_mask =
|
|
|
|
KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
|
|
|
|
VisibilityChangeMask | FocusChangeMask | StructureNotifyMask |
|
2011-11-15 02:36:25 +04:00
|
|
|
PointerMotionMask | ExposureMask | EnterWindowMask;
|
2011-08-17 10:14:02 +04:00
|
|
|
|
2011-10-31 21:55:05 +04:00
|
|
|
XSelectInput(xfi->display, window->handle, input_mask);
|
|
|
|
XMapWindow(xfi->display, window->handle);
|
2011-08-17 10:14:02 +04:00
|
|
|
|
2011-10-31 21:55:05 +04:00
|
|
|
memset(&gcv, 0, sizeof(gcv));
|
|
|
|
window->gc = XCreateGC(xfi->display, window->handle, GCGraphicsExposures, &gcv);
|
2011-08-17 22:51:17 +04:00
|
|
|
|
2011-10-31 21:55:05 +04:00
|
|
|
xf_MoveWindow(xfi, window, x, y, width, height);
|
2011-08-17 10:14:02 +04:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2011-09-01 02:02:22 +04:00
|
|
|
void xf_SetWindowMinMaxInfo(xfInfo* xfi, xfWindow* window,
|
2011-09-02 21:29:17 +04:00
|
|
|
int maxWidth, int maxHeight, int maxPosX, int maxPosY,
|
|
|
|
int minTrackWidth, int minTrackHeight, int maxTrackWidth, int maxTrackHeight)
|
2011-09-01 02:02:22 +04:00
|
|
|
{
|
2011-09-02 02:08:53 +04:00
|
|
|
XSizeHints* size_hints;
|
|
|
|
|
|
|
|
size_hints = XAllocSizeHints();
|
|
|
|
|
|
|
|
if (size_hints)
|
|
|
|
{
|
|
|
|
size_hints->flags = PMinSize | PMaxSize | PResizeInc;
|
|
|
|
|
|
|
|
size_hints->min_width = minTrackWidth;
|
|
|
|
size_hints->min_height = minTrackHeight;
|
|
|
|
|
|
|
|
size_hints->max_width = maxTrackWidth;
|
|
|
|
size_hints->max_height = maxTrackHeight;
|
|
|
|
|
2011-09-02 20:39:56 +04:00
|
|
|
/* to speedup window drawing we need to select optimal value for sizing step. */
|
2011-09-04 00:38:01 +04:00
|
|
|
size_hints->width_inc = size_hints->height_inc = 1;
|
2011-09-02 02:08:53 +04:00
|
|
|
|
|
|
|
XSetWMNormalHints(xfi->display, window->handle, size_hints);
|
|
|
|
XFree(size_hints);
|
|
|
|
}
|
2011-09-01 02:02:22 +04:00
|
|
|
}
|
|
|
|
|
2011-09-01 02:22:21 +04:00
|
|
|
|
2011-09-02 20:39:56 +04:00
|
|
|
void xf_SendMoveResizeEvent(xfInfo* xfi, xfWindow* window, int direction, int x_root, int y_root)
|
2011-09-01 02:22:21 +04:00
|
|
|
{
|
|
|
|
// TODO:
|
|
|
|
// - how to receive movesize canceling event?
|
|
|
|
// - how to produce correct RAIL movesize finish?
|
|
|
|
// - how to receive move/size window coordinates in process of local move/size?
|
|
|
|
|
|
|
|
XEvent event;
|
|
|
|
|
|
|
|
event.xclient.type = ClientMessage;
|
|
|
|
event.xclient.window = window->handle;
|
|
|
|
event.xclient.message_type = xfi->_NET_WM_MOVERESIZE;
|
|
|
|
event.xclient.serial = 0;
|
|
|
|
event.xclient.display = xfi->display;
|
2011-11-19 21:19:16 +04:00
|
|
|
event.xclient.send_event = true;
|
2011-09-01 02:22:21 +04:00
|
|
|
event.xclient.format = 32;
|
|
|
|
event.xclient.data.l[0] = x_root;
|
|
|
|
event.xclient.data.l[1] = y_root;
|
|
|
|
event.xclient.data.l[2] = direction;
|
2011-09-02 20:39:56 +04:00
|
|
|
event.xclient.data.l[3] = 1; /* button 1 */
|
2011-09-01 02:22:21 +04:00
|
|
|
event.xclient.data.l[4] = 0;
|
|
|
|
|
|
|
|
XUngrabPointer(xfi->display, CurrentTime);
|
2011-11-19 21:19:16 +04:00
|
|
|
XSendEvent(xfi->display, RootWindowOfScreen(xfi->screen), false, SubstructureNotifyMask, &event);
|
2011-09-01 02:22:21 +04:00
|
|
|
}
|
|
|
|
|
2011-09-01 02:02:22 +04:00
|
|
|
void xf_StartLocalMoveSize(xfInfo* xfi, xfWindow* window, uint16 moveSizeType, int posX, int posY)
|
|
|
|
{
|
2011-11-19 21:19:16 +04:00
|
|
|
window->localMoveSize = true;
|
2011-09-01 02:02:22 +04:00
|
|
|
}
|
|
|
|
|
2011-09-23 05:23:01 +04:00
|
|
|
void xf_StopLocalMoveSize(xfInfo* xfi, xfWindow* window, uint16 moveSizeType, int posX, int posY)
|
2011-09-01 02:02:22 +04:00
|
|
|
{
|
2011-11-19 21:19:16 +04:00
|
|
|
window->localMoveSize = false;
|
2011-09-01 02:02:22 +04:00
|
|
|
}
|
|
|
|
|
2011-08-18 06:50:49 +04:00
|
|
|
void xf_MoveWindow(xfInfo* xfi, xfWindow* window, int x, int y, int width, int height)
|
|
|
|
{
|
2011-11-19 21:19:16 +04:00
|
|
|
boolean resize = false;
|
2011-08-18 09:16:49 +04:00
|
|
|
|
2011-08-20 06:21:09 +04:00
|
|
|
if ((width * height) < 1)
|
|
|
|
return;
|
|
|
|
|
2011-09-23 05:23:01 +04:00
|
|
|
if ((window->width != width) || (window->height != height))
|
2011-11-19 21:19:16 +04:00
|
|
|
resize = true;
|
2011-09-02 02:08:53 +04:00
|
|
|
|
2011-09-23 05:23:01 +04:00
|
|
|
if (resize)
|
2011-09-06 01:25:46 +04:00
|
|
|
XMoveResizeWindow(xfi->display, window->handle, x, y, width, height);
|
2011-09-23 05:23:01 +04:00
|
|
|
else
|
|
|
|
XMoveWindow(xfi->display, window->handle, x, y);
|
2011-08-19 19:12:30 +04:00
|
|
|
|
2011-08-23 05:22:05 +04:00
|
|
|
window->left = x;
|
|
|
|
window->top = y;
|
|
|
|
window->right = x + width - 1;
|
|
|
|
window->bottom = y + height - 1;
|
2011-08-19 19:12:30 +04:00
|
|
|
window->width = width;
|
|
|
|
window->height = height;
|
2011-09-04 00:38:01 +04:00
|
|
|
|
|
|
|
DEBUG_X11_LMS("xf_MoveWindow: window=0x%X rc={l=%d t=%d r=%d b=%d} w=%d h=%d",
|
2011-09-23 05:23:01 +04:00
|
|
|
(uint32) window->handle, window->left, window->top, window->right, window->bottom,
|
2011-09-04 00:38:01 +04:00
|
|
|
window->width, window->height);
|
2011-09-23 05:23:01 +04:00
|
|
|
|
|
|
|
if (resize)
|
|
|
|
{
|
|
|
|
xf_UpdateWindowArea(xfi, window, 0, 0, width, height);
|
|
|
|
}
|
2011-08-18 06:50:49 +04:00
|
|
|
}
|
|
|
|
|
2011-08-22 07:15:19 +04:00
|
|
|
void xf_ShowWindow(xfInfo* xfi, xfWindow* window, uint8 state)
|
|
|
|
{
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case WINDOW_HIDE:
|
2011-08-23 23:52:17 +04:00
|
|
|
XWithdrawWindow(xfi->display, window->handle, xfi->screen_number);
|
2011-08-22 07:15:19 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WINDOW_SHOW_MINIMIZED:
|
|
|
|
XIconifyWindow(xfi->display, window->handle, xfi->screen_number);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINDOW_SHOW_MAXIMIZED:
|
|
|
|
XRaiseWindow(xfi->display, window->handle);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINDOW_SHOW:
|
2011-08-23 23:52:17 +04:00
|
|
|
XMapWindow(xfi->display, window->handle);
|
2011-08-22 07:15:19 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
XFlush(xfi->display);
|
|
|
|
}
|
|
|
|
|
2011-08-22 01:32:18 +04:00
|
|
|
void xf_SetWindowIcon(xfInfo* xfi, xfWindow* window, rdpIcon* icon)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
int pixels;
|
|
|
|
int propsize;
|
|
|
|
long* propdata;
|
|
|
|
long* dstp;
|
|
|
|
uint32* srcp;
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
if (icon->big != true)
|
2011-08-22 01:32:18 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
pixels = icon->entry->width * icon->entry->height;
|
|
|
|
propsize = 2 + pixels;
|
|
|
|
propdata = xmalloc(propsize * sizeof(long));
|
|
|
|
|
|
|
|
propdata[0] = icon->entry->width;
|
|
|
|
propdata[1] = icon->entry->height;
|
|
|
|
dstp = &(propdata[2]);
|
2011-08-22 06:30:49 +04:00
|
|
|
srcp = (uint32*) icon->extra;
|
2011-08-22 01:32:18 +04:00
|
|
|
|
|
|
|
for (y = 0; y < icon->entry->height; y++)
|
|
|
|
{
|
|
|
|
for (x = 0; x < icon->entry->width; x++)
|
|
|
|
{
|
|
|
|
*dstp++ = *srcp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-24 08:46:34 +04:00
|
|
|
XChangeProperty(xfi->display, window->handle, xfi->_NET_WM_ICON, XA_CARDINAL, 32,
|
|
|
|
PropModeReplace, (uint8*) propdata, propsize);
|
2011-08-22 01:32:18 +04:00
|
|
|
|
2011-08-24 08:46:34 +04:00
|
|
|
XFlush(xfi->display);
|
2011-08-22 01:32:18 +04:00
|
|
|
}
|
|
|
|
|
2011-08-25 22:11:45 +04:00
|
|
|
void xf_SetWindowRects(xfInfo* xfi, xfWindow* window, RECTANGLE_16* rects, int nrects)
|
2011-08-23 00:06:12 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
XRectangle* xrects;
|
|
|
|
|
|
|
|
xrects = xmalloc(sizeof(XRectangle) * nrects);
|
|
|
|
|
|
|
|
for (i = 0; i < nrects; i++)
|
|
|
|
{
|
|
|
|
xrects[i].x = rects[i].left;
|
|
|
|
xrects[i].y = rects[i].top;
|
2011-08-23 00:10:08 +04:00
|
|
|
xrects[i].width = rects[i].right - rects[i].left;
|
|
|
|
xrects[i].height = rects[i].bottom - rects[i].top;
|
2011-08-23 00:06:12 +04:00
|
|
|
}
|
|
|
|
|
2011-08-24 06:58:36 +04:00
|
|
|
#ifdef WITH_XEXT
|
2011-08-23 00:06:12 +04:00
|
|
|
XShapeCombineRectangles(xfi->display, window->handle, ShapeBounding, 0, 0, xrects, nrects, ShapeSet, 0);
|
2011-08-24 06:58:36 +04:00
|
|
|
#endif
|
|
|
|
|
2011-08-23 00:06:12 +04:00
|
|
|
xfree(xrects);
|
|
|
|
}
|
|
|
|
|
2011-08-30 22:21:16 +04:00
|
|
|
void xf_SetWindowVisibilityRects(xfInfo* xfi, xfWindow* window, RECTANGLE_16* rects, int nrects)
|
2011-08-09 06:24:12 +04:00
|
|
|
{
|
2011-08-30 22:21:16 +04:00
|
|
|
int i;
|
|
|
|
XRectangle* xrects;
|
2011-08-25 01:16:57 +04:00
|
|
|
|
2011-08-30 22:21:16 +04:00
|
|
|
xrects = xmalloc(sizeof(XRectangle) * nrects);
|
2011-08-25 01:16:57 +04:00
|
|
|
|
2011-08-30 22:21:16 +04:00
|
|
|
for (i = 0; i < nrects; i++)
|
2011-08-22 13:21:39 +04:00
|
|
|
{
|
2011-08-30 22:21:16 +04:00
|
|
|
xrects[i].x = rects[i].left;
|
|
|
|
xrects[i].y = rects[i].top;
|
|
|
|
xrects[i].width = rects[i].right - rects[i].left;
|
|
|
|
xrects[i].height = rects[i].bottom - rects[i].top;
|
2011-08-22 13:21:39 +04:00
|
|
|
}
|
2011-08-30 22:21:16 +04:00
|
|
|
|
|
|
|
#ifdef WITH_XEXT
|
2011-09-01 02:02:22 +04:00
|
|
|
//XShapeCombineRectangles(xfi->display, window->handle, ShapeBounding, 0, 0, xrects, nrects, ShapeSet, 0);
|
2011-08-30 22:21:16 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
xfree(xrects);
|
2011-08-25 01:16:57 +04:00
|
|
|
}
|
|
|
|
|
2011-09-23 05:23:01 +04:00
|
|
|
void xf_UpdateWindowArea(xfInfo* xfi, xfWindow* window, int x, int y, int width, int height)
|
|
|
|
{
|
|
|
|
int ax, ay;
|
|
|
|
rdpWindow* wnd;
|
|
|
|
|
|
|
|
wnd = window->window;
|
|
|
|
ax = x + wnd->windowOffsetX;
|
|
|
|
ay = y + wnd->windowOffsetY;
|
|
|
|
|
|
|
|
if (ax + width > wnd->windowOffsetX + wnd->windowWidth)
|
|
|
|
width = (wnd->windowOffsetX + wnd->windowWidth - 1) - ax;
|
|
|
|
|
|
|
|
if (ay + height > wnd->windowOffsetY + wnd->windowHeight)
|
|
|
|
height = (wnd->windowOffsetY + wnd->windowHeight - 1) - ay;
|
|
|
|
|
2011-09-23 08:06:39 +04:00
|
|
|
if (xfi->sw_gdi)
|
|
|
|
{
|
|
|
|
XPutImage(xfi->display, xfi->primary, window->gc, xfi->image,
|
2011-09-23 05:23:01 +04:00
|
|
|
ax, ay, ax, ay, width, height);
|
2011-09-23 08:06:39 +04:00
|
|
|
}
|
2011-09-23 05:23:01 +04:00
|
|
|
|
|
|
|
XCopyArea(xfi->display, xfi->primary, window->handle, window->gc,
|
|
|
|
ax, ay, width, height, x, y);
|
|
|
|
|
|
|
|
XFlush(xfi->display);
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean xf_IsWindowBorder(xfInfo* xfi, xfWindow* xfw, int x, int y)
|
|
|
|
{
|
|
|
|
rdpWindow* wnd;
|
2011-11-19 21:19:16 +04:00
|
|
|
boolean clientArea = false;
|
|
|
|
boolean windowArea = false;
|
2011-09-23 05:23:01 +04:00
|
|
|
|
|
|
|
wnd = xfw->window;
|
|
|
|
|
|
|
|
if (((x > wnd->clientOffsetX) && (x < wnd->clientOffsetX + wnd->clientAreaWidth)) &&
|
|
|
|
((y > wnd->clientOffsetY) && (y < wnd->clientOffsetY + wnd->clientAreaHeight)))
|
2011-11-19 21:19:16 +04:00
|
|
|
clientArea = true;
|
2011-09-23 05:23:01 +04:00
|
|
|
|
|
|
|
if (((x > wnd->windowOffsetX) && (x < wnd->windowOffsetX + wnd->windowWidth)) &&
|
|
|
|
((y > wnd->windowOffsetY) && (y < wnd->windowOffsetY + wnd->windowHeight)))
|
2011-11-19 21:19:16 +04:00
|
|
|
windowArea = true;
|
2011-09-23 05:23:01 +04:00
|
|
|
|
|
|
|
return (windowArea && !(clientArea));
|
|
|
|
}
|
|
|
|
|
2011-08-25 01:16:57 +04:00
|
|
|
void xf_DestroyWindow(xfInfo* xfi, xfWindow* window)
|
|
|
|
{
|
2011-09-06 00:42:18 +04:00
|
|
|
if (window == NULL)
|
|
|
|
return;
|
|
|
|
|
2011-11-18 02:00:13 +04:00
|
|
|
if (xfi->window == window)
|
|
|
|
xfi->window = NULL;
|
|
|
|
|
2011-08-30 22:21:16 +04:00
|
|
|
if (window->gc)
|
|
|
|
XFreeGC(xfi->display, window->gc);
|
2011-08-25 01:16:57 +04:00
|
|
|
|
2011-08-30 22:21:16 +04:00
|
|
|
if (window->handle)
|
|
|
|
{
|
|
|
|
XUnmapWindow(xfi->display, window->handle);
|
|
|
|
XDestroyWindow(xfi->display, window->handle);
|
|
|
|
}
|
2011-08-25 01:16:57 +04:00
|
|
|
|
2011-08-30 22:21:16 +04:00
|
|
|
xfree(window);
|
2011-08-09 06:24:12 +04:00
|
|
|
}
|