2004-08-31 18:33:05 +02:00
|
|
|
/*
|
|
|
|
* Xephyr - A kdrive X server thats runs in a host X window.
|
|
|
|
* Authored by Matthew Allum <mallum@o-hand.com>
|
|
|
|
*
|
2011-06-17 16:26:17 +02:00
|
|
|
* Copyright © 2004 Nokia
|
2004-08-31 18:33:05 +02:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
* documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
* the above copyright notice appear in all copies and that both that
|
|
|
|
* copyright notice and this permission notice appear in supporting
|
|
|
|
* documentation, and that the name of Nokia not be used in
|
|
|
|
* advertising or publicity pertaining to distribution of the software without
|
|
|
|
* specific, written prior permission. Nokia makes no
|
|
|
|
* representations about the suitability of this software for any purpose. It
|
|
|
|
* is provided "as is" without express or implied warranty.
|
|
|
|
*
|
|
|
|
* NOKIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
|
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
|
|
* EVENT SHALL NOKIA BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
|
|
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
|
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2007-09-19 15:35:51 +02:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <kdrive-config.h>
|
|
|
|
#endif
|
|
|
|
|
2008-07-23 01:00:26 +02:00
|
|
|
/*
|
|
|
|
* including some server headers (like kdrive-config.h)
|
|
|
|
* might define the macro _XSERVER64
|
|
|
|
* on 64 bits machines. That macro must _NOT_ be defined for Xlib
|
|
|
|
* client code, otherwise bad things happen.
|
|
|
|
* So let's undef that macro if necessary.
|
|
|
|
*/
|
|
|
|
#ifdef _XSERVER64
|
|
|
|
#undef _XSERVER64
|
|
|
|
#endif
|
|
|
|
|
2004-08-31 18:33:05 +02:00
|
|
|
#include "hostx.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
2012-03-21 20:55:09 +01:00
|
|
|
#include <string.h> /* for memset */
|
2011-10-10 21:16:31 +02:00
|
|
|
#include <errno.h>
|
2005-06-23 18:50:07 +02:00
|
|
|
#include <time.h>
|
2004-08-31 18:33:05 +02:00
|
|
|
|
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/shm.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
2004-11-09 12:36:49 +01:00
|
|
|
#include <X11/keysym.h>
|
2010-06-20 01:05:40 +02:00
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include <xcb/xproto.h>
|
|
|
|
#include <X11/Xlib-xcb.h>
|
|
|
|
#include <xcb/xcb_icccm.h>
|
|
|
|
#include <xcb/xcb_aux.h>
|
|
|
|
#include <xcb/shm.h>
|
|
|
|
#include <xcb/xcb_image.h>
|
|
|
|
#include <xcb/shape.h>
|
2010-06-25 00:26:48 +02:00
|
|
|
#include <xcb/xcb_keysyms.h>
|
2008-04-23 16:46:30 +02:00
|
|
|
#ifdef XF86DRI
|
2010-06-20 01:05:40 +02:00
|
|
|
#include <xcb/xf86dri.h>
|
|
|
|
#include <xcb/glx.h>
|
|
|
|
#endif /* XF86DRI */
|
2007-08-28 15:58:55 +02:00
|
|
|
#include "ephyrlog.h"
|
2004-08-31 18:33:05 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* All xlib calls go here, which gets built as its own .a .
|
|
|
|
* Mixing kdrive and xlib headers causes all sorts of types
|
|
|
|
* to get clobbered.
|
|
|
|
*/
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
struct EphyrHostScreen {
|
|
|
|
Window win;
|
|
|
|
Window win_pre_existing; /* Set via -parent option like xnest */
|
|
|
|
Window peer_win; /* Used for GL; should be at most one */
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_image_t *ximg;
|
2012-03-21 20:55:09 +01:00
|
|
|
int win_width, win_height;
|
|
|
|
int server_depth;
|
|
|
|
unsigned char *fb_data; /* only used when host bpp != server bpp */
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_shm_segment_info_t shminfo;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
void *info; /* Pointer to the screen this is associated with */
|
|
|
|
int mynum; /* Screen number */
|
2007-10-02 13:25:51 +02:00
|
|
|
};
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
struct EphyrHostXVars {
|
|
|
|
char *server_dpy_name;
|
|
|
|
Display *dpy;
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_connection_t *conn;
|
2012-03-21 20:55:09 +01:00
|
|
|
int screen;
|
|
|
|
Visual *visual;
|
|
|
|
Window winroot;
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_gcontext_t gc;
|
2012-03-21 20:55:09 +01:00
|
|
|
int depth;
|
|
|
|
Bool use_host_cursor;
|
|
|
|
Bool use_fullscreen;
|
|
|
|
Bool have_shm;
|
|
|
|
|
|
|
|
int n_screens;
|
|
|
|
struct EphyrHostScreen *screens;
|
|
|
|
|
|
|
|
long damage_debug_msec;
|
|
|
|
|
|
|
|
unsigned long cmap[256];
|
2004-08-31 18:33:05 +02:00
|
|
|
};
|
|
|
|
|
2004-11-09 12:36:49 +01:00
|
|
|
/* memset ( missing> ) instead of below */
|
2007-10-02 13:25:51 +02:00
|
|
|
/*static EphyrHostXVars HostX = { "?", 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};*/
|
|
|
|
static EphyrHostXVars HostX;
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
static int HostXWantDamageDebug = 0;
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
extern EphyrKeySyms ephyrKeySyms;
|
2006-07-19 22:51:04 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
extern int monitorResolution;
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2012-12-11 17:23:55 +01:00
|
|
|
extern Bool EphyrWantResize;
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
char *ephyrResName = NULL;
|
|
|
|
int ephyrResNameFromCmd = 0;
|
|
|
|
char *ephyrTitle = NULL;
|
2008-02-29 01:45:21 +01:00
|
|
|
|
2005-06-09 18:22:27 +02:00
|
|
|
static void
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_set_fullscreen_hint(void);
|
2005-06-09 18:22:27 +02:00
|
|
|
|
2007-10-02 13:25:51 +02:00
|
|
|
#define host_depth_matches_server(_vars) (HostX.depth == (_vars)->server_depth)
|
2004-11-08 23:39:47 +01:00
|
|
|
|
2007-10-02 13:25:51 +02:00
|
|
|
static struct EphyrHostScreen *
|
2012-03-21 20:55:09 +01:00
|
|
|
host_screen_from_screen_info(EphyrScreenInfo * screen)
|
2007-10-02 13:25:51 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
int i;
|
2007-10-02 13:25:51 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
for (i = 0; i < HostX.n_screens; i++) {
|
|
|
|
if (HostX.screens[i].info == screen) {
|
|
|
|
return &HostX.screens[i];
|
2007-10-02 13:25:51 +02:00
|
|
|
}
|
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
return NULL;
|
2007-10-02 13:25:51 +02:00
|
|
|
}
|
2004-11-08 23:39:47 +01:00
|
|
|
|
2004-08-31 18:33:05 +02:00
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_want_screen_size(EphyrScreenInfo screen, int *width, int *height)
|
2004-08-31 18:33:05 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
|
|
|
|
|
|
|
|
if (host_screen &&
|
|
|
|
(host_screen->win_pre_existing != None ||
|
|
|
|
HostX.use_fullscreen == True)) {
|
|
|
|
*width = host_screen->win_width;
|
|
|
|
*height = host_screen->win_height;
|
|
|
|
return 1;
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
return 0;
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
|
|
|
|
2004-11-09 12:36:49 +01:00
|
|
|
void
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_add_screen(EphyrScreenInfo screen, unsigned long win_id, int screen_num)
|
2007-10-02 13:25:51 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
int index = HostX.n_screens;
|
2007-10-02 13:25:51 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
HostX.n_screens += 1;
|
|
|
|
HostX.screens = realloc(HostX.screens,
|
|
|
|
HostX.n_screens * sizeof(struct EphyrHostScreen));
|
|
|
|
memset(&HostX.screens[index], 0, sizeof(struct EphyrHostScreen));
|
2007-10-02 13:25:51 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
HostX.screens[index].info = screen;
|
|
|
|
HostX.screens[index].win_pre_existing = win_id;
|
2007-10-02 13:25:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_set_display_name(char *name)
|
2004-11-09 12:36:49 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
HostX.server_dpy_name = strdup(name);
|
2004-11-09 12:36:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-10-02 13:25:51 +02:00
|
|
|
hostx_set_screen_number(EphyrScreenInfo screen, int number)
|
2004-11-09 12:36:49 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
|
|
|
|
|
|
|
|
if (host_screen) {
|
|
|
|
host_screen->mynum = number;
|
|
|
|
hostx_set_win_title(host_screen->info, "");
|
|
|
|
}
|
|
|
|
}
|
2007-10-02 13:25:51 +02:00
|
|
|
|
|
|
|
void
|
2013-08-17 13:01:32 +02:00
|
|
|
hostx_set_win_title(EphyrScreenInfo screen, const char *extra_text)
|
2007-10-02 13:25:51 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
|
2007-10-02 13:25:51 +02:00
|
|
|
|
2009-06-10 18:05:09 +02:00
|
|
|
if (!host_screen)
|
2012-03-21 20:55:09 +01:00
|
|
|
return;
|
2004-11-09 12:36:49 +01:00
|
|
|
|
2009-06-10 18:05:09 +02:00
|
|
|
if (ephyrTitle) {
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_icccm_set_wm_name(HostX.conn,
|
|
|
|
host_screen->win,
|
|
|
|
XCB_ATOM_STRING,
|
|
|
|
8,
|
|
|
|
strlen(ephyrTitle),
|
|
|
|
ephyrTitle);
|
|
|
|
} else {
|
2009-06-10 18:05:09 +02:00
|
|
|
#define BUF_LEN 256
|
2012-03-21 20:55:09 +01:00
|
|
|
char buf[BUF_LEN + 1];
|
2004-11-09 12:36:49 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
memset(buf, 0, BUF_LEN + 1);
|
|
|
|
snprintf(buf, BUF_LEN, "Xephyr on %s.%d %s",
|
|
|
|
HostX.server_dpy_name,
|
|
|
|
host_screen->mynum, (extra_text != NULL) ? extra_text : "");
|
2009-06-10 18:05:09 +02:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_icccm_set_wm_name(HostX.conn,
|
|
|
|
host_screen->win,
|
|
|
|
XCB_ATOM_STRING,
|
|
|
|
8,
|
|
|
|
strlen(buf),
|
|
|
|
buf);
|
2009-06-10 18:05:09 +02:00
|
|
|
}
|
2004-11-09 12:36:49 +01:00
|
|
|
}
|
|
|
|
|
2004-08-31 18:33:05 +02:00
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_want_host_cursor(void)
|
2004-08-31 18:33:05 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
return HostX.use_host_cursor;
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_use_host_cursor(void)
|
2004-08-31 18:33:05 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
HostX.use_host_cursor = True;
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_want_preexisting_window(EphyrScreenInfo screen)
|
2004-08-31 18:33:05 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
|
2007-10-02 13:25:51 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
if (host_screen && host_screen->win_pre_existing) {
|
|
|
|
return 1;
|
2007-10-02 13:25:51 +02:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
else {
|
|
|
|
return 0;
|
2007-10-02 13:25:51 +02:00
|
|
|
}
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
|
|
|
|
2005-06-09 18:22:27 +02:00
|
|
|
void
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_use_fullscreen(void)
|
2005-06-09 18:22:27 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
HostX.use_fullscreen = True;
|
2005-06-09 18:22:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_want_fullscreen(void)
|
2005-06-09 18:22:27 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
return HostX.use_fullscreen;
|
2005-06-09 18:22:27 +02:00
|
|
|
}
|
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
static xcb_intern_atom_cookie_t cookie_WINDOW_STATE,
|
|
|
|
cookie_WINDOW_STATE_FULLSCREEN;
|
|
|
|
|
2005-06-09 18:22:27 +02:00
|
|
|
static void
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_set_fullscreen_hint(void)
|
2005-06-09 18:22:27 +02:00
|
|
|
{
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_atom_t atom_WINDOW_STATE, atom_WINDOW_STATE_FULLSCREEN;
|
2012-03-21 20:55:09 +01:00
|
|
|
int index;
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_intern_atom_reply_t *reply;
|
|
|
|
|
|
|
|
reply = xcb_intern_atom_reply(HostX.conn, cookie_WINDOW_STATE, NULL);
|
|
|
|
atom_WINDOW_STATE = reply->atom;
|
|
|
|
free(reply);
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
reply = xcb_intern_atom_reply(HostX.conn, cookie_WINDOW_STATE_FULLSCREEN,
|
|
|
|
NULL);
|
|
|
|
atom_WINDOW_STATE_FULLSCREEN = reply->atom;
|
|
|
|
free(reply);
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
for (index = 0; index < HostX.n_screens; index++) {
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_change_property(HostX.conn,
|
|
|
|
PropModeReplace,
|
|
|
|
HostX.screens[index].win,
|
|
|
|
atom_WINDOW_STATE,
|
|
|
|
XCB_ATOM_ATOM,
|
|
|
|
32,
|
|
|
|
1,
|
|
|
|
&atom_WINDOW_STATE_FULLSCREEN);
|
2007-10-02 13:25:51 +02:00
|
|
|
}
|
2005-06-09 18:22:27 +02:00
|
|
|
}
|
|
|
|
|
2004-08-31 18:33:05 +02:00
|
|
|
static void
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_toggle_damage_debug(void)
|
2004-08-31 18:33:05 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
HostXWantDamageDebug ^= 1;
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
|
|
|
|
2007-10-02 13:25:51 +02:00
|
|
|
void
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_handle_signal(int signum)
|
2004-08-31 18:33:05 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_toggle_damage_debug();
|
|
|
|
EPHYR_DBG("Signal caught. Damage Debug:%i\n", HostXWantDamageDebug);
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
|
|
|
|
2008-02-29 01:45:21 +01:00
|
|
|
void
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_use_resname(char *name, int fromcmd)
|
2008-02-29 01:45:21 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
ephyrResName = name;
|
|
|
|
ephyrResNameFromCmd = fromcmd;
|
2008-02-29 01:45:21 +01:00
|
|
|
}
|
|
|
|
|
2009-06-10 18:05:09 +02:00
|
|
|
void
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_set_title(char *title)
|
2009-06-10 18:05:09 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
ephyrTitle = title;
|
2009-06-10 18:05:09 +02:00
|
|
|
}
|
|
|
|
|
2011-12-02 09:09:07 +01:00
|
|
|
#ifdef __SUNPRO_C
|
|
|
|
/* prevent "Function has no return statement" error for x_io_error_handler */
|
|
|
|
#pragma does_not_return(exit)
|
|
|
|
#endif
|
|
|
|
|
2011-10-10 21:16:31 +02:00
|
|
|
static int _X_NORETURN
|
2012-03-21 20:55:09 +01:00
|
|
|
x_io_error_handler(Display * dpy)
|
|
|
|
{
|
2011-10-10 21:16:31 +02:00
|
|
|
ErrorF("Lost connection to X server: %s\n", strerror(errno));
|
|
|
|
CloseWellKnownConnections();
|
|
|
|
OsCleanup(1);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2004-08-31 18:33:05 +02:00
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_init(void)
|
2004-08-31 18:33:05 +02:00
|
|
|
{
|
2010-06-20 01:05:40 +02:00
|
|
|
uint32_t attr;
|
|
|
|
xcb_cursor_t empty_cursor;
|
|
|
|
xcb_pixmap_t cursor_pxm;
|
|
|
|
uint16_t red, green, blue;
|
|
|
|
uint32_t pixel;
|
2012-03-21 20:55:09 +01:00
|
|
|
int index;
|
|
|
|
char *tmpstr;
|
2010-06-20 01:05:40 +02:00
|
|
|
char *class_hint;
|
|
|
|
size_t class_len;
|
|
|
|
const xcb_query_extension_reply_t *shm_rep;
|
|
|
|
xcb_screen_t *screen;
|
|
|
|
|
|
|
|
attr =
|
|
|
|
XCB_EVENT_MASK_BUTTON_PRESS
|
|
|
|
| XCB_EVENT_MASK_BUTTON_RELEASE
|
|
|
|
| XCB_EVENT_MASK_POINTER_MOTION
|
|
|
|
| XCB_EVENT_MASK_KEY_PRESS
|
|
|
|
| XCB_EVENT_MASK_KEY_RELEASE
|
|
|
|
| XCB_EVENT_MASK_EXPOSURE
|
|
|
|
| XCB_EVENT_MASK_STRUCTURE_NOTIFY;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
EPHYR_DBG("mark");
|
|
|
|
|
|
|
|
if ((HostX.dpy = XOpenDisplay(getenv("DISPLAY"))) == NULL) {
|
|
|
|
fprintf(stderr, "\nXephyr cannot open host display. Is DISPLAY set?\n");
|
|
|
|
exit(1);
|
2007-10-02 13:25:51 +02:00
|
|
|
}
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
XSetIOErrorHandler(x_io_error_handler);
|
2011-10-10 21:16:31 +02:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
HostX.conn = XGetXCBConnection(HostX.dpy);
|
2012-03-21 20:55:09 +01:00
|
|
|
HostX.screen = DefaultScreen(HostX.dpy);
|
2010-06-20 01:05:40 +02:00
|
|
|
screen = xcb_aux_get_screen(HostX.conn, HostX.screen);
|
2012-03-21 20:55:09 +01:00
|
|
|
HostX.winroot = RootWindow(HostX.dpy, HostX.screen);
|
2010-06-20 01:05:40 +02:00
|
|
|
HostX.gc = xcb_generate_id(HostX.conn);
|
2012-03-21 20:55:09 +01:00
|
|
|
HostX.depth = DefaultDepth(HostX.dpy, HostX.screen);
|
|
|
|
HostX.visual = DefaultVisual(HostX.dpy, HostX.screen);
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_create_gc(HostX.conn, HostX.gc, HostX.winroot, 0, NULL);
|
|
|
|
cookie_WINDOW_STATE = xcb_intern_atom(HostX.conn, False,
|
|
|
|
strlen("_NET_WM_STATE"),
|
|
|
|
"_NET_WM_STATE");
|
|
|
|
cookie_WINDOW_STATE_FULLSCREEN =
|
|
|
|
xcb_intern_atom(HostX.conn, False,
|
|
|
|
strlen("_NET_WM_STATE_FULLSCREEN"),
|
|
|
|
"_NET_WM_STATE_FULLSCREEN");
|
2008-02-29 01:45:21 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
for (index = 0; index < HostX.n_screens; index++) {
|
|
|
|
struct EphyrHostScreen *host_screen = &HostX.screens[index];
|
2007-10-02 13:25:51 +02:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
host_screen->win = xcb_generate_id(HostX.conn);
|
2012-03-21 20:55:09 +01:00
|
|
|
host_screen->server_depth = HostX.depth;
|
2007-10-02 13:25:51 +02:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
if (host_screen->win_pre_existing != XCB_WINDOW_NONE) {
|
|
|
|
xcb_get_geometry_reply_t *prewin_geom;
|
|
|
|
xcb_get_geometry_cookie_t cookie;
|
|
|
|
xcb_generic_error_t *e = NULL;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
/* Get screen size from existing window */
|
|
|
|
cookie = xcb_get_geometry(HostX.conn,
|
|
|
|
host_screen->win_pre_existing);
|
|
|
|
prewin_geom = xcb_get_geometry_reply(HostX.conn, cookie, &e);
|
|
|
|
|
|
|
|
if (e) {
|
|
|
|
free(e);
|
|
|
|
free(prewin_geom);
|
|
|
|
fprintf (stderr, "\nXephyr -parent window' does not exist!\n");
|
|
|
|
exit (1);
|
2007-10-02 13:25:51 +02:00
|
|
|
}
|
2008-02-29 01:45:21 +01:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
host_screen->win_width = prewin_geom->width;
|
|
|
|
host_screen->win_height = prewin_geom->height;
|
|
|
|
|
|
|
|
free(prewin_geom);
|
|
|
|
|
|
|
|
xcb_create_window(HostX.conn,
|
|
|
|
XCB_COPY_FROM_PARENT,
|
|
|
|
host_screen->win,
|
|
|
|
host_screen->win_pre_existing,
|
|
|
|
0,0,
|
|
|
|
host_screen->win_width,
|
|
|
|
host_screen->win_height,
|
|
|
|
0,
|
|
|
|
XCB_WINDOW_CLASS_COPY_FROM_PARENT,
|
|
|
|
XCB_COPY_FROM_PARENT,
|
|
|
|
XCB_CW_EVENT_MASK,
|
|
|
|
&attr);
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
|
|
|
else {
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_create_window(HostX.conn,
|
|
|
|
XCB_COPY_FROM_PARENT,
|
|
|
|
host_screen->win,
|
|
|
|
HostX.winroot,
|
|
|
|
0,0,100,100, /* will resize */
|
|
|
|
0,
|
|
|
|
XCB_WINDOW_CLASS_COPY_FROM_PARENT,
|
|
|
|
XCB_COPY_FROM_PARENT,
|
|
|
|
XCB_CW_EVENT_MASK,
|
|
|
|
&attr);
|
|
|
|
|
|
|
|
hostx_set_win_title (host_screen->info,
|
|
|
|
"(ctrl+shift grabs mouse and keyboard)");
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
if (HostX.use_fullscreen) {
|
2010-06-20 01:05:40 +02:00
|
|
|
host_screen->win_width = DisplayWidth(HostX.dpy, HostX.screen);
|
|
|
|
host_screen->win_height = DisplayHeight(HostX.dpy, HostX.screen);
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
hostx_set_fullscreen_hint();
|
|
|
|
}
|
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
tmpstr = getenv("RESOURCE_NAME");
|
|
|
|
if (tmpstr && (!ephyrResNameFromCmd))
|
|
|
|
ephyrResName = tmpstr;
|
|
|
|
class_len = strlen(ephyrResName) + 1 + strlen("Xephyr") + 1;
|
|
|
|
class_hint = malloc(class_len);
|
2012-03-21 20:55:09 +01:00
|
|
|
if (class_hint) {
|
2010-06-20 01:05:40 +02:00
|
|
|
strcpy(class_hint, ephyrResName);
|
|
|
|
strcpy(class_hint + strlen(ephyrResName) + 1, "Xephyr");
|
|
|
|
xcb_change_property(HostX.conn,
|
|
|
|
XCB_PROP_MODE_REPLACE,
|
|
|
|
host_screen->win,
|
|
|
|
XCB_ATOM_WM_CLASS,
|
|
|
|
XCB_ATOM_STRING,
|
|
|
|
8,
|
|
|
|
class_len,
|
|
|
|
class_hint);
|
|
|
|
free(class_hint);
|
2008-02-29 01:45:21 +01:00
|
|
|
}
|
2007-10-02 13:25:51 +02:00
|
|
|
}
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
if (!xcb_aux_parse_color("red", &red, &green, &blue)) {
|
|
|
|
xcb_lookup_color_cookie_t c =
|
|
|
|
xcb_lookup_color(HostX.conn, screen->default_colormap, 3, "red");
|
|
|
|
xcb_lookup_color_reply_t *reply =
|
|
|
|
xcb_lookup_color_reply(HostX.conn, c, NULL);
|
|
|
|
red = reply->exact_red;
|
|
|
|
green = reply->exact_green;
|
|
|
|
blue = reply->exact_blue;
|
|
|
|
free(reply);
|
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
{
|
|
|
|
xcb_alloc_color_cookie_t c = xcb_alloc_color(HostX.conn,
|
|
|
|
screen->default_colormap,
|
|
|
|
red, green, blue);
|
|
|
|
xcb_alloc_color_reply_t *r = xcb_alloc_color_reply(HostX.conn, c, NULL);
|
|
|
|
red = r->red;
|
|
|
|
green = r->green;
|
|
|
|
blue = r->blue;
|
|
|
|
pixel = r->pixel;
|
|
|
|
free(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
xcb_change_gc(HostX.conn, HostX.gc, XCB_GC_FOREGROUND, &pixel);
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
if (!hostx_want_host_cursor ()) {
|
2012-03-21 20:55:09 +01:00
|
|
|
/* Ditch the cursor, we provide our 'own' */
|
2010-06-20 01:05:40 +02:00
|
|
|
cursor_pxm = xcb_generate_id(HostX.conn);
|
|
|
|
xcb_create_pixmap(HostX.conn, 1, cursor_pxm, HostX.winroot, 1, 1);
|
|
|
|
empty_cursor = xcb_generate_id(HostX.conn);
|
|
|
|
xcb_create_cursor(HostX.conn,
|
|
|
|
empty_cursor,
|
|
|
|
cursor_pxm, cursor_pxm,
|
|
|
|
0,0,0,
|
|
|
|
0,0,0,
|
|
|
|
1,1);
|
2012-03-21 20:55:09 +01:00
|
|
|
for (index = 0; index < HostX.n_screens; index++) {
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_change_window_attributes(HostX.conn,
|
|
|
|
HostX.screens[index].win,
|
|
|
|
XCB_CW_CURSOR,
|
|
|
|
&empty_cursor);
|
2007-10-02 13:25:51 +02:00
|
|
|
}
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_free_pixmap(HostX.conn, cursor_pxm);
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
for (index = 0; index < HostX.n_screens; index++) {
|
|
|
|
HostX.screens[index].ximg = NULL;
|
2007-10-02 13:25:51 +02:00
|
|
|
}
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
/* Try to get share memory ximages for a little bit more speed */
|
|
|
|
shm_rep = xcb_get_extension_data(HostX.conn, &xcb_shm_id);
|
|
|
|
if (!shm_rep || !shm_rep->present || getenv("XEPHYR_NO_SHM")) {
|
2012-03-21 20:55:09 +01:00
|
|
|
fprintf(stderr, "\nXephyr unable to use SHM XImages\n");
|
|
|
|
HostX.have_shm = False;
|
2007-10-02 13:25:51 +02:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
else {
|
2010-06-20 01:05:40 +02:00
|
|
|
/* Really really check we have shm - better way ?*/
|
|
|
|
xcb_shm_segment_info_t shminfo;
|
|
|
|
xcb_generic_error_t *e;
|
|
|
|
xcb_void_cookie_t cookie;
|
|
|
|
xcb_shm_seg_t shmseg;
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2007-10-02 13:25:51 +02:00
|
|
|
HostX.have_shm = True;
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
shminfo.shmid = shmget(IPC_PRIVATE, 1, IPC_CREAT|0777);
|
|
|
|
shminfo.shmaddr = shmat(shminfo.shmid,0,0);
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
shmseg = xcb_generate_id(HostX.conn);
|
|
|
|
cookie = xcb_shm_attach_checked(HostX.conn, shmseg, shminfo.shmid,
|
|
|
|
True);
|
|
|
|
e = xcb_request_check(HostX.conn, cookie);
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
if (e) {
|
2007-10-02 13:25:51 +02:00
|
|
|
fprintf(stderr, "\nXephyr unable to use SHM XImages\n");
|
|
|
|
HostX.have_shm = False;
|
2010-06-20 01:05:40 +02:00
|
|
|
free(e);
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
2007-10-02 13:25:51 +02:00
|
|
|
|
|
|
|
shmdt(shminfo.shmaddr);
|
|
|
|
shmctl(shminfo.shmid, IPC_RMID, 0);
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_flush(HostX.conn);
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
/* Setup the pause time between paints when debugging updates */
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
HostX.damage_debug_msec = 20000; /* 1/50 th of a second */
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
if (getenv("XEPHYR_PAUSE")) {
|
|
|
|
HostX.damage_debug_msec = strtol(getenv("XEPHYR_PAUSE"), NULL, 0);
|
|
|
|
EPHYR_DBG("pause is %li\n", HostX.damage_debug_msec);
|
2004-09-01 17:30:58 +02:00
|
|
|
}
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
return 1;
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_get_depth(void)
|
2004-08-31 18:33:05 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
return HostX.depth;
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
|
|
|
|
2004-11-08 23:39:47 +01:00
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_get_server_depth(EphyrScreenInfo screen)
|
2004-11-08 23:39:47 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
|
2007-10-02 13:25:51 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
return host_screen ? host_screen->server_depth : 0;
|
2004-11-08 23:39:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_set_server_depth(EphyrScreenInfo screen, int depth)
|
2004-11-08 23:39:47 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
|
2007-10-02 13:25:51 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
if (host_screen)
|
|
|
|
host_screen->server_depth = depth;
|
2004-11-08 23:39:47 +01:00
|
|
|
}
|
|
|
|
|
2004-08-31 18:33:05 +02:00
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_get_bpp(EphyrScreenInfo screen)
|
2004-08-31 18:33:05 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
|
2007-10-02 13:25:51 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
if (!host_screen)
|
|
|
|
return 0;
|
2007-10-02 13:25:51 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
if (host_depth_matches_server(host_screen))
|
|
|
|
return HostX.visual->bits_per_rgb;
|
|
|
|
else
|
|
|
|
return host_screen->server_depth; /*XXX correct ? */
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_get_visual_masks(EphyrScreenInfo screen,
|
|
|
|
CARD32 *rmsk, CARD32 *gmsk, CARD32 *bmsk)
|
2004-08-31 18:33:05 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
|
2007-10-02 13:25:51 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
if (!host_screen)
|
|
|
|
return;
|
2007-10-02 13:25:51 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
if (host_depth_matches_server(host_screen)) {
|
|
|
|
*rmsk = HostX.visual->red_mask;
|
|
|
|
*gmsk = HostX.visual->green_mask;
|
|
|
|
*bmsk = HostX.visual->blue_mask;
|
2004-11-08 23:39:47 +01:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
else if (host_screen->server_depth == 16) {
|
|
|
|
/* Assume 16bpp 565 */
|
|
|
|
*rmsk = 0xf800;
|
|
|
|
*gmsk = 0x07e0;
|
|
|
|
*bmsk = 0x001f;
|
2004-11-08 23:39:47 +01:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
else {
|
|
|
|
*rmsk = 0x0;
|
|
|
|
*gmsk = 0x0;
|
|
|
|
*bmsk = 0x0;
|
2004-11-08 23:39:47 +01:00
|
|
|
}
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
static int
|
2008-11-26 01:26:44 +01:00
|
|
|
hostx_calculate_color_shift(unsigned long mask)
|
2008-07-01 22:37:12 +02:00
|
|
|
{
|
2008-11-26 01:26:44 +01:00
|
|
|
int shift = 1;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2008-11-26 01:26:44 +01:00
|
|
|
/* count # of bits in mask */
|
2012-03-21 20:55:09 +01:00
|
|
|
while ((mask = (mask >> 1)))
|
|
|
|
shift++;
|
2008-11-26 01:26:44 +01:00
|
|
|
/* cmap entry is an unsigned char so adjust it by size of that */
|
|
|
|
shift = shift - sizeof(unsigned char) * 8;
|
2012-03-21 20:55:09 +01:00
|
|
|
if (shift < 0)
|
|
|
|
shift = 0;
|
2008-07-01 22:37:12 +02:00
|
|
|
return shift;
|
|
|
|
}
|
|
|
|
|
2004-11-08 23:39:47 +01:00
|
|
|
void
|
2007-10-02 13:25:51 +02:00
|
|
|
hostx_set_cmap_entry(unsigned char idx,
|
2012-03-21 20:55:09 +01:00
|
|
|
unsigned char r, unsigned char g, unsigned char b)
|
2004-11-08 23:39:47 +01:00
|
|
|
{
|
2008-07-01 22:37:12 +02:00
|
|
|
/* need to calculate the shifts for RGB because server could be BGR. */
|
|
|
|
/* XXX Not sure if this is correct for 8 on 16, but this works for 8 on 24.*/
|
|
|
|
static int rshift, bshift, gshift = 0;
|
|
|
|
static int first_time = 1;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2008-07-01 22:37:12 +02:00
|
|
|
if (first_time) {
|
2012-03-21 20:55:09 +01:00
|
|
|
first_time = 0;
|
|
|
|
rshift = hostx_calculate_color_shift(HostX.visual->red_mask);
|
|
|
|
gshift = hostx_calculate_color_shift(HostX.visual->green_mask);
|
|
|
|
bshift = hostx_calculate_color_shift(HostX.visual->blue_mask);
|
2008-07-01 22:37:12 +02:00
|
|
|
}
|
|
|
|
HostX.cmap[idx] = ((r << rshift) & HostX.visual->red_mask) |
|
2012-03-21 20:55:09 +01:00
|
|
|
((g << gshift) & HostX.visual->green_mask) |
|
|
|
|
((b << bshift) & HostX.visual->blue_mask);
|
2004-11-08 23:39:47 +01:00
|
|
|
}
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2006-03-10 22:36:24 +01:00
|
|
|
/**
|
|
|
|
* hostx_screen_init creates the XImage that will contain the front buffer of
|
|
|
|
* the ephyr screen, and possibly offscreen memory.
|
|
|
|
*
|
|
|
|
* @param width width of the screen
|
|
|
|
* @param height height of the screen
|
|
|
|
* @param buffer_height height of the rectangle to be allocated.
|
|
|
|
*
|
|
|
|
* hostx_screen_init() creates an XImage, using MIT-SHM if it's available.
|
|
|
|
* buffer_height can be used to create a larger offscreen buffer, which is used
|
|
|
|
* by fakexa for storing offscreen pixmap data.
|
|
|
|
*/
|
2012-03-21 20:55:09 +01:00
|
|
|
void *
|
|
|
|
hostx_screen_init(EphyrScreenInfo screen,
|
2012-12-20 13:50:17 +01:00
|
|
|
int width, int height, int buffer_height,
|
|
|
|
int *bytes_per_line, int *bits_per_pixel)
|
2004-08-31 18:33:05 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
Bool shm_success = False;
|
|
|
|
|
|
|
|
struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
|
|
|
|
|
|
|
|
if (!host_screen) {
|
|
|
|
fprintf(stderr, "%s: Error in accessing hostx data\n", __func__);
|
|
|
|
exit(1);
|
2007-10-02 13:25:51 +02:00
|
|
|
}
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
EPHYR_DBG("host_screen=%p wxh=%dx%d, buffer_height=%d",
|
|
|
|
host_screen, width, height, buffer_height);
|
|
|
|
|
|
|
|
if (host_screen->ximg != NULL) {
|
|
|
|
/* Free up the image data if previously used
|
|
|
|
* i.ie called by server reset
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (HostX.have_shm) {
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_shm_detach(HostX.conn, host_screen->shminfo.shmseg);
|
|
|
|
xcb_image_destroy (host_screen->ximg);
|
2012-03-21 20:55:09 +01:00
|
|
|
shmdt(host_screen->shminfo.shmaddr);
|
|
|
|
shmctl(host_screen->shminfo.shmid, IPC_RMID, 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
free(host_screen->ximg->data);
|
|
|
|
host_screen->ximg->data = NULL;
|
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_image_destroy(host_screen->ximg);
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
if (HostX.have_shm) {
|
2010-06-20 01:05:40 +02:00
|
|
|
host_screen->ximg = xcb_image_create_native(HostX.conn,
|
|
|
|
width,
|
|
|
|
buffer_height,
|
|
|
|
XCB_IMAGE_FORMAT_Z_PIXMAP,
|
|
|
|
HostX.depth,
|
|
|
|
NULL,
|
|
|
|
~0,
|
|
|
|
NULL);
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
host_screen->shminfo.shmid =
|
|
|
|
shmget(IPC_PRIVATE,
|
2010-06-20 01:05:40 +02:00
|
|
|
host_screen->ximg->stride * buffer_height,
|
2012-03-21 20:55:09 +01:00
|
|
|
IPC_CREAT | 0777);
|
|
|
|
host_screen->ximg->data = shmat(host_screen->shminfo.shmid, 0, 0);
|
|
|
|
host_screen->shminfo.shmaddr = host_screen->ximg->data;
|
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
if (host_screen->ximg->data == (uint8_t *) -1) {
|
2012-03-21 20:55:09 +01:00
|
|
|
EPHYR_DBG
|
|
|
|
("Can't attach SHM Segment, falling back to plain XImages");
|
|
|
|
HostX.have_shm = False;
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_image_destroy (host_screen->ximg);
|
2012-03-21 20:55:09 +01:00
|
|
|
shmctl(host_screen->shminfo.shmid, IPC_RMID, 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
EPHYR_DBG("SHM segment attached %p", host_screen->shminfo.shmaddr);
|
2010-06-20 01:05:40 +02:00
|
|
|
host_screen->shminfo.shmseg = xcb_generate_id(HostX.conn);
|
|
|
|
xcb_shm_attach(HostX.conn,
|
|
|
|
host_screen->shminfo.shmseg,
|
|
|
|
host_screen->shminfo.shmid,
|
|
|
|
False);
|
2012-03-21 20:55:09 +01:00
|
|
|
shm_success = True;
|
|
|
|
}
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
if (!shm_success) {
|
|
|
|
EPHYR_DBG("Creating image %dx%d for screen host_screen=%p\n",
|
|
|
|
width, buffer_height, host_screen);
|
2010-06-20 01:05:40 +02:00
|
|
|
host_screen->ximg = xcb_image_create_native(HostX.conn,
|
|
|
|
width,
|
|
|
|
buffer_height,
|
|
|
|
XCB_IMAGE_FORMAT_Z_PIXMAP,
|
|
|
|
HostX.depth,
|
|
|
|
NULL,
|
|
|
|
~0,
|
|
|
|
NULL);
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
host_screen->ximg->data =
|
2010-06-20 01:05:40 +02:00
|
|
|
malloc(host_screen->ximg->stride * buffer_height);
|
2007-10-02 13:25:51 +02:00
|
|
|
}
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
*bytes_per_line = host_screen->ximg->stride;
|
|
|
|
*bits_per_pixel = host_screen->ximg->bpp;
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2012-12-11 17:23:55 +01:00
|
|
|
if (host_screen->win_pre_existing == None && !EphyrWantResize) {
|
2010-06-20 01:05:40 +02:00
|
|
|
/* Ask the WM to keep our size static */
|
|
|
|
xcb_size_hints_t size_hints = {0};
|
|
|
|
size_hints.max_width = size_hints.min_width = width;
|
|
|
|
size_hints.max_height = size_hints.min_height = height;
|
|
|
|
size_hints.flags = (XCB_ICCCM_SIZE_HINT_P_MIN_SIZE |
|
|
|
|
XCB_ICCCM_SIZE_HINT_P_MAX_SIZE);
|
|
|
|
xcb_icccm_set_wm_normal_hints(HostX.conn, host_screen->win,
|
|
|
|
&size_hints);
|
2012-07-30 20:32:09 +02:00
|
|
|
}
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_map_window(HostX.conn, host_screen->win);
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_aux_sync(HostX.conn);
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
host_screen->win_width = width;
|
|
|
|
host_screen->win_height = height;
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
if (host_depth_matches_server(host_screen)) {
|
|
|
|
EPHYR_DBG("Host matches server");
|
|
|
|
return host_screen->ximg->data;
|
2004-11-08 23:39:47 +01:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
else {
|
|
|
|
EPHYR_DBG("server bpp %i", host_screen->server_depth >> 3);
|
|
|
|
host_screen->fb_data =
|
|
|
|
malloc(width * buffer_height * (host_screen->server_depth >> 3));
|
|
|
|
return host_screen->fb_data;
|
2004-11-08 23:39:47 +01:00
|
|
|
}
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
static void hostx_paint_debug_rect(struct EphyrHostScreen *host_screen,
|
|
|
|
int x, int y, int width, int height);
|
2007-10-02 13:25:51 +02:00
|
|
|
|
2004-08-31 18:33:05 +02:00
|
|
|
void
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_paint_rect(EphyrScreenInfo screen,
|
|
|
|
int sx, int sy, int dx, int dy, int width, int height)
|
2004-08-31 18:33:05 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
|
2007-10-02 13:25:51 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
EPHYR_DBG("painting in screen %d\n", host_screen->mynum);
|
2007-10-02 13:25:51 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
/*
|
|
|
|
* Copy the image data updated by the shadow layer
|
|
|
|
* on to the window
|
|
|
|
*/
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
if (HostXWantDamageDebug) {
|
|
|
|
hostx_paint_debug_rect(host_screen, dx, dy, width, height);
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
/*
|
|
|
|
* If the depth of the ephyr server is less than that of the host,
|
|
|
|
* the kdrive fb does not point to the ximage data but to a buffer
|
|
|
|
* ( fb_data ), we shift the various bits from this onto the XImage
|
|
|
|
* so they match the host.
|
|
|
|
*
|
|
|
|
* Note, This code is pretty new ( and simple ) so may break on
|
|
|
|
* endian issues, 32 bpp host etc.
|
|
|
|
* Not sure if 8bpp case is right either.
|
|
|
|
* ... and it will be slower than the matching depth case.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!host_depth_matches_server(host_screen)) {
|
|
|
|
int x, y, idx, bytes_per_pixel = (host_screen->server_depth >> 3);
|
|
|
|
unsigned char r, g, b;
|
|
|
|
unsigned long host_pixel;
|
|
|
|
|
|
|
|
EPHYR_DBG("Unmatched host depth host_screen=%p\n", host_screen);
|
|
|
|
for (y = sy; y < sy + height; y++)
|
|
|
|
for (x = sx; x < sx + width; x++) {
|
|
|
|
idx =
|
|
|
|
(host_screen->win_width * y * bytes_per_pixel) +
|
|
|
|
(x * bytes_per_pixel);
|
|
|
|
|
|
|
|
switch (host_screen->server_depth) {
|
|
|
|
case 16:
|
|
|
|
{
|
|
|
|
unsigned short pixel =
|
|
|
|
*(unsigned short *) (host_screen->fb_data + idx);
|
|
|
|
|
|
|
|
r = ((pixel & 0xf800) >> 8);
|
|
|
|
g = ((pixel & 0x07e0) >> 3);
|
|
|
|
b = ((pixel & 0x001f) << 3);
|
|
|
|
|
|
|
|
host_pixel = (r << 16) | (g << 8) | (b);
|
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_image_put_pixel(host_screen->ximg, x, y, host_pixel);
|
2012-03-21 20:55:09 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
unsigned char pixel =
|
|
|
|
*(unsigned char *) (host_screen->fb_data + idx);
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_image_put_pixel(host_screen->ximg, x, y,
|
|
|
|
HostX.cmap[pixel]);
|
2012-03-21 20:55:09 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-11-08 23:39:47 +01:00
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
if (HostX.have_shm) {
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_image_shm_put(HostX.conn, host_screen->win,
|
|
|
|
HostX.gc, host_screen->ximg,
|
|
|
|
host_screen->shminfo,
|
|
|
|
sx, sy, dx, dy, width, height, False);
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
else {
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_image_put(HostX.conn, host_screen->win, HostX.gc, host_screen->ximg,
|
|
|
|
dx, dy, 0);
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_aux_sync(HostX.conn);
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
|
|
|
|
2007-10-02 13:25:51 +02:00
|
|
|
static void
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_paint_debug_rect(struct EphyrHostScreen *host_screen,
|
|
|
|
int x, int y, int width, int height)
|
2004-08-31 18:33:05 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
struct timespec tspec;
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_rectangle_t rect = { .x = x, .y = y, .width = width, .height = height };
|
|
|
|
xcb_void_cookie_t cookie;
|
|
|
|
xcb_generic_error_t *e;
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
tspec.tv_sec = HostX.damage_debug_msec / (1000000);
|
|
|
|
tspec.tv_nsec = (HostX.damage_debug_msec % 1000000) * 1000;
|
2004-09-01 17:30:58 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
EPHYR_DBG("msec: %li tv_sec %li, tv_msec %li",
|
|
|
|
HostX.damage_debug_msec, tspec.tv_sec, tspec.tv_nsec);
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
/* fprintf(stderr, "Xephyr updating: %i+%i %ix%i\n", x, y, width, height); */
|
2004-12-06 23:29:31 +01:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
cookie = xcb_poly_fill_rectangle_checked(HostX.conn, host_screen->win,
|
|
|
|
HostX.gc, 1, &rect);
|
|
|
|
e = xcb_request_check(HostX.conn, cookie);
|
|
|
|
free(e);
|
2004-08-31 18:33:05 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
/* nanosleep seems to work better than usleep for me... */
|
|
|
|
nanosleep(&tspec, NULL);
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
hostx_load_keymap(void)
|
|
|
|
{
|
2010-06-25 18:59:13 +02:00
|
|
|
int min_keycode, max_keycode;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2010-06-21 00:34:03 +02:00
|
|
|
min_keycode = xcb_get_setup(HostX.conn)->min_keycode;
|
|
|
|
max_keycode = xcb_get_setup(HostX.conn)->max_keycode;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
EPHYR_DBG("min: %d, max: %d", min_keycode, max_keycode);
|
|
|
|
|
|
|
|
ephyrKeySyms.minKeyCode = min_keycode;
|
|
|
|
ephyrKeySyms.maxKeyCode = max_keycode;
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
|
|
|
|
2007-10-02 13:25:51 +02:00
|
|
|
static struct EphyrHostScreen *
|
2012-03-21 20:55:09 +01:00
|
|
|
host_screen_from_window(Window w)
|
2007-10-02 13:25:51 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
int index = 0;
|
|
|
|
struct EphyrHostScreen *result = NULL;
|
2007-10-02 13:25:51 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
for (index = 0; index < HostX.n_screens; index++) {
|
2012-10-30 17:02:58 +01:00
|
|
|
if (HostX.screens[index].win == w
|
|
|
|
|| HostX.screens[index].peer_win == w
|
|
|
|
|| HostX.screens[index].win_pre_existing == w) {
|
2012-03-21 20:55:09 +01:00
|
|
|
result = &HostX.screens[index];
|
|
|
|
goto out;
|
2007-10-02 13:25:51 +02:00
|
|
|
}
|
|
|
|
}
|
2008-02-21 15:33:02 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
out:
|
|
|
|
return result;
|
2007-10-02 13:25:51 +02:00
|
|
|
}
|
|
|
|
|
2004-08-31 18:33:05 +02:00
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_get_event(EphyrHostXEvent * ev)
|
2004-08-31 18:33:05 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
XEvent xev;
|
|
|
|
static int grabbed_screen = -1;
|
2010-06-25 00:26:48 +02:00
|
|
|
static xcb_key_symbols_t *keysyms;
|
|
|
|
|
|
|
|
if (!keysyms)
|
|
|
|
keysyms = xcb_key_symbols_alloc(HostX.conn);
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
if (XPending(HostX.dpy)) {
|
|
|
|
XNextEvent(HostX.dpy, &xev);
|
|
|
|
|
|
|
|
switch (xev.type) {
|
|
|
|
case Expose:
|
|
|
|
/* Not so great event compression, but works ok */
|
|
|
|
while (XCheckTypedWindowEvent(HostX.dpy, xev.xexpose.window,
|
|
|
|
Expose, &xev));
|
|
|
|
{
|
|
|
|
struct EphyrHostScreen *host_screen =
|
|
|
|
host_screen_from_window(xev.xexpose.window);
|
|
|
|
if (host_screen) {
|
|
|
|
hostx_paint_rect(host_screen->info, 0, 0, 0, 0,
|
|
|
|
host_screen->win_width,
|
|
|
|
host_screen->win_height);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
EPHYR_LOG_ERROR("failed to get host screen\n");
|
|
|
|
ev->type = EPHYR_EV_EXPOSE;
|
|
|
|
ev->data.expose.window = xev.xexpose.window;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case MotionNotify:
|
|
|
|
{
|
|
|
|
struct EphyrHostScreen *host_screen =
|
|
|
|
host_screen_from_window(xev.xmotion.window);
|
|
|
|
|
|
|
|
ev->type = EPHYR_EV_MOUSE_MOTION;
|
|
|
|
ev->data.mouse_motion.x = xev.xmotion.x;
|
|
|
|
ev->data.mouse_motion.y = xev.xmotion.y;
|
|
|
|
ev->data.mouse_motion.window = xev.xmotion.window;
|
|
|
|
ev->data.mouse_motion.screen =
|
|
|
|
(host_screen ? host_screen->mynum : -1);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case ButtonPress:
|
|
|
|
ev->type = EPHYR_EV_MOUSE_PRESS;
|
|
|
|
ev->key_state = xev.xkey.state;
|
|
|
|
/*
|
|
|
|
* This is a bit hacky. will break for button 5 ( defined as 0x10 )
|
|
|
|
* Check KD_BUTTON defines in kdrive.h
|
|
|
|
*/
|
|
|
|
ev->data.mouse_down.button_num = 1 << (xev.xbutton.button - 1);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case ButtonRelease:
|
|
|
|
ev->type = EPHYR_EV_MOUSE_RELEASE;
|
|
|
|
ev->key_state = xev.xkey.state;
|
|
|
|
ev->data.mouse_up.button_num = 1 << (xev.xbutton.button - 1);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case KeyPress:
|
|
|
|
{
|
|
|
|
ev->type = EPHYR_EV_KEY_PRESS;
|
|
|
|
ev->key_state = xev.xkey.state;
|
|
|
|
ev->data.key_down.scancode = xev.xkey.keycode;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case KeyRelease:
|
2010-06-25 00:26:48 +02:00
|
|
|
if ((xcb_key_symbols_get_keysym(keysyms,xev.xkey.keycode, 0) == XK_Shift_L
|
|
|
|
|| xcb_key_symbols_get_keysym(keysyms,xev.xkey.keycode, 0) == XK_Shift_R)
|
|
|
|
&& (xev.xkey.state & XCB_MOD_MASK_CONTROL)) {
|
2012-03-21 20:55:09 +01:00
|
|
|
struct EphyrHostScreen *host_screen =
|
|
|
|
host_screen_from_window(xev.xexpose.window);
|
|
|
|
|
|
|
|
if (grabbed_screen != -1) {
|
2010-06-21 00:34:39 +02:00
|
|
|
xcb_ungrab_keyboard(HostX.conn, XCB_TIME_CURRENT_TIME);
|
|
|
|
xcb_ungrab_pointer(HostX.conn, XCB_TIME_CURRENT_TIME);
|
2012-03-21 20:55:09 +01:00
|
|
|
grabbed_screen = -1;
|
|
|
|
hostx_set_win_title(host_screen->info,
|
|
|
|
"(ctrl+shift grabs mouse and keyboard)");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Attempt grab */
|
2010-06-21 00:34:39 +02:00
|
|
|
xcb_grab_keyboard_cookie_t kbgrabc =
|
|
|
|
xcb_grab_keyboard(HostX.conn,
|
|
|
|
True,
|
|
|
|
host_screen->win,
|
|
|
|
XCB_TIME_CURRENT_TIME,
|
|
|
|
XCB_GRAB_MODE_ASYNC,
|
|
|
|
XCB_GRAB_MODE_ASYNC);
|
|
|
|
xcb_grab_keyboard_reply_t *kbgrabr;
|
|
|
|
xcb_grab_pointer_cookie_t pgrabc =
|
|
|
|
xcb_grab_pointer(HostX.conn,
|
|
|
|
True,
|
|
|
|
host_screen->win,
|
|
|
|
0,
|
|
|
|
XCB_GRAB_MODE_ASYNC,
|
|
|
|
XCB_GRAB_MODE_ASYNC,
|
|
|
|
host_screen->win,
|
|
|
|
XCB_NONE,
|
|
|
|
XCB_TIME_CURRENT_TIME);
|
|
|
|
xcb_grab_pointer_reply_t *pgrabr;
|
|
|
|
kbgrabr = xcb_grab_keyboard_reply(HostX.conn, kbgrabc, NULL);
|
|
|
|
if (!kbgrabr || kbgrabr->status != XCB_GRAB_STATUS_SUCCESS) {
|
|
|
|
xcb_discard_reply(HostX.conn, pgrabc.sequence);
|
|
|
|
xcb_ungrab_pointer(HostX.conn, XCB_TIME_CURRENT_TIME);
|
|
|
|
} else {
|
|
|
|
pgrabr = xcb_grab_pointer_reply(HostX.conn, pgrabc, NULL);
|
|
|
|
if (!pgrabr || pgrabr->status != XCB_GRAB_STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
xcb_ungrab_keyboard(HostX.conn,
|
|
|
|
XCB_TIME_CURRENT_TIME);
|
|
|
|
} else {
|
2012-03-21 20:55:09 +01:00
|
|
|
grabbed_screen = host_screen->mynum;
|
|
|
|
hostx_set_win_title
|
|
|
|
(host_screen->info,
|
|
|
|
"(ctrl+shift releases mouse and keyboard)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Still send the release event even if above has happened
|
|
|
|
* server will get confused with just an up event.
|
|
|
|
* Maybe it would be better to just block shift+ctrls getting to
|
|
|
|
* kdrive all togeather.
|
|
|
|
*/
|
|
|
|
ev->type = EPHYR_EV_KEY_RELEASE;
|
|
|
|
ev->key_state = xev.xkey.state;
|
|
|
|
ev->data.key_up.scancode = xev.xkey.keycode;
|
|
|
|
return 1;
|
|
|
|
|
2012-07-30 20:32:09 +02:00
|
|
|
case ConfigureNotify:
|
|
|
|
{
|
2012-12-11 17:23:55 +01:00
|
|
|
struct EphyrHostScreen *host_screen;
|
|
|
|
|
|
|
|
/* event compression as for Expose events, cause
|
|
|
|
* we don't want to resize the framebuffer for
|
|
|
|
* every single change */
|
|
|
|
while (XCheckTypedWindowEvent(HostX.dpy, xev.xconfigure.window,
|
|
|
|
ConfigureNotify, &xev));
|
|
|
|
host_screen = host_screen_from_window(xev.xconfigure.window);
|
|
|
|
|
|
|
|
if (!host_screen ||
|
|
|
|
(host_screen->win_pre_existing == None && !EphyrWantResize)) {
|
|
|
|
return 0;
|
2012-07-30 20:32:09 +02:00
|
|
|
}
|
|
|
|
|
2012-12-11 17:23:55 +01:00
|
|
|
ev->type = EPHYR_EV_CONFIGURE;
|
|
|
|
ev->data.configure.width = xev.xconfigure.width;
|
|
|
|
ev->data.configure.height = xev.xconfigure.height;
|
|
|
|
ev->data.configure.window = xev.xconfigure.window;
|
|
|
|
ev->data.configure.screen = host_screen->mynum;
|
|
|
|
|
|
|
|
return 1;
|
2012-07-30 20:32:09 +02:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
return 0;
|
2004-08-31 18:33:05 +02:00
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
void *
|
2007-07-21 12:08:39 +02:00
|
|
|
hostx_get_display(void)
|
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
return HostX.dpy;
|
2007-07-21 12:08:39 +02:00
|
|
|
}
|
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_connection_t *
|
|
|
|
hostx_get_xcbconn(void)
|
|
|
|
{
|
|
|
|
return HostX.conn;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
hostx_get_screen(void)
|
|
|
|
{
|
|
|
|
return DefaultScreen(HostX.dpy);
|
|
|
|
}
|
|
|
|
|
2007-08-03 01:10:39 +02:00
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_get_window(int a_screen_number)
|
2007-08-03 01:10:39 +02:00
|
|
|
{
|
Xephyr: port XV/GL stuff of the new multiscreen architecture
We can now launch GL or XV apps in any of the
Xephyr screens we want.
* hw/kdrive/ephyr/hostx.c,h:
(hostx_get_window):
(hostx_create_window): make these functions be screen
number aware.
* hw/kdrive/ephyr/XF86dri.c : fix some compiler warnings.
* hw/kdrive/ephyr/ephyrdri.c:
(ephyrDRIQueryDirectRenderingCapable),
(ephyrDRIOpenConnection),
(ephyrDRIAuthConnection),
(ephyrDRICloseConnection),
(ephyrDRIGetClientDriverName),
(ephyrDRICreateContext),
(ephyrDRIDestroyContext),
(ephyrDRICreateDrawable),
(ephyrDRIGetDrawableInfo),
(ephyrDRIGetDeviceInfo): in all those functions, don't forward
the screen number we receive - from the client - to the host X.
We (Xephyr) are always targetting the same X display screen, which is
the one Xephyr got launched against. So we enforce that in the code.
* hw/kdrive/ephyr/ephyrdriext.c:
(EphyrMirrorHostVisuals): make this duplicate the visuals of the host X
default screen into a given Xephyr screen. This way we have a chance
to update the visuals of all Xephyr screen to make them mirror those
of the host X.
(many other places): specify screen number where required by the api
change in hostx.h.
* hw/kdrive/ephyr/ephyrglxext.c: specify screen number where required
by the api change in hostx.h
* hw/kdrive/ephyr/ephyrhostglx.c: don't forward the screen number we
receive - from the client - to the host X.
We (Xephyr) are always targetting the same
X display screen, which is
the one Xephyr got launched against. So we enforce that in the code.
* hw/kdrive/ephyr/ephyrhostvideo.c,h: take in account the screen number received
from the client app. This is useful to know on which Xephyr screen we
need to display video stuff.
* hw/kdrive/ephyr/ephyrvideo.c: update this to reflect the API change
in hw/kdrive/ephyr/ephyrhostvideo.h.
(ephyrSetPortAttribute): when parameters are not valid
- they exceed their validity range - send them to the host anyway
and do not return an error to clients.
Some host expose buggy validity range, so rejecting client for that
is too harsh.
2007-10-03 13:03:34 +02:00
|
|
|
if (a_screen_number < 0 || a_screen_number >= HostX.n_screens) {
|
2012-03-21 20:55:09 +01:00
|
|
|
EPHYR_LOG_ERROR("bad screen number:%d\n", a_screen_number);
|
Xephyr: port XV/GL stuff of the new multiscreen architecture
We can now launch GL or XV apps in any of the
Xephyr screens we want.
* hw/kdrive/ephyr/hostx.c,h:
(hostx_get_window):
(hostx_create_window): make these functions be screen
number aware.
* hw/kdrive/ephyr/XF86dri.c : fix some compiler warnings.
* hw/kdrive/ephyr/ephyrdri.c:
(ephyrDRIQueryDirectRenderingCapable),
(ephyrDRIOpenConnection),
(ephyrDRIAuthConnection),
(ephyrDRICloseConnection),
(ephyrDRIGetClientDriverName),
(ephyrDRICreateContext),
(ephyrDRIDestroyContext),
(ephyrDRICreateDrawable),
(ephyrDRIGetDrawableInfo),
(ephyrDRIGetDeviceInfo): in all those functions, don't forward
the screen number we receive - from the client - to the host X.
We (Xephyr) are always targetting the same X display screen, which is
the one Xephyr got launched against. So we enforce that in the code.
* hw/kdrive/ephyr/ephyrdriext.c:
(EphyrMirrorHostVisuals): make this duplicate the visuals of the host X
default screen into a given Xephyr screen. This way we have a chance
to update the visuals of all Xephyr screen to make them mirror those
of the host X.
(many other places): specify screen number where required by the api
change in hostx.h.
* hw/kdrive/ephyr/ephyrglxext.c: specify screen number where required
by the api change in hostx.h
* hw/kdrive/ephyr/ephyrhostglx.c: don't forward the screen number we
receive - from the client - to the host X.
We (Xephyr) are always targetting the same
X display screen, which is
the one Xephyr got launched against. So we enforce that in the code.
* hw/kdrive/ephyr/ephyrhostvideo.c,h: take in account the screen number received
from the client app. This is useful to know on which Xephyr screen we
need to display video stuff.
* hw/kdrive/ephyr/ephyrvideo.c: update this to reflect the API change
in hw/kdrive/ephyr/ephyrhostvideo.h.
(ephyrSetPortAttribute): when parameters are not valid
- they exceed their validity range - send them to the host anyway
and do not return an error to clients.
Some host expose buggy validity range, so rejecting client for that
is too harsh.
2007-10-03 13:03:34 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
return HostX.screens[a_screen_number].win;
|
2007-08-03 01:10:39 +02:00
|
|
|
}
|
2007-08-24 16:30:50 +02:00
|
|
|
|
2007-08-30 23:54:49 +02:00
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_get_window_attributes(int a_window, EphyrHostWindowAttributes * a_attrs)
|
2007-08-30 23:54:49 +02:00
|
|
|
{
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_get_geometry_cookie_t geom_cookie;
|
|
|
|
xcb_get_window_attributes_cookie_t attr_cookie;
|
|
|
|
xcb_get_geometry_reply_t *geom_reply;
|
|
|
|
xcb_get_window_attributes_reply_t *attr_reply;
|
|
|
|
|
|
|
|
geom_cookie = xcb_get_geometry(HostX.conn, a_window);
|
|
|
|
attr_cookie = xcb_get_window_attributes(HostX.conn, a_window);
|
|
|
|
geom_reply = xcb_get_geometry_reply(HostX.conn, geom_cookie, NULL);
|
|
|
|
attr_reply = xcb_get_window_attributes_reply(HostX.conn, attr_cookie, NULL);
|
|
|
|
|
|
|
|
a_attrs->x = geom_reply->x;
|
|
|
|
a_attrs->y = geom_reply->y;
|
|
|
|
a_attrs->width = geom_reply->width;
|
|
|
|
a_attrs->height = geom_reply->height;
|
|
|
|
a_attrs->visualid = attr_reply->visual;
|
|
|
|
|
|
|
|
free(geom_reply);
|
|
|
|
free(attr_reply);
|
2012-03-21 20:55:09 +01:00
|
|
|
return TRUE;
|
2007-08-30 23:54:49 +02:00
|
|
|
}
|
|
|
|
|
2007-08-28 15:58:55 +02:00
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_get_visuals_info(EphyrHostVisualInfo ** a_visuals, int *a_num_entries)
|
2007-08-28 15:58:55 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
Bool is_ok = False;
|
|
|
|
EphyrHostVisualInfo *host_visuals = NULL;
|
2010-06-21 00:34:54 +02:00
|
|
|
int nb_items = 0, i = 0, screen_num;
|
|
|
|
xcb_screen_iterator_t screens;
|
|
|
|
xcb_depth_iterator_t depths;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2010-06-21 00:34:54 +02:00
|
|
|
EPHYR_RETURN_VAL_IF_FAIL(a_visuals && a_num_entries, False);
|
2012-03-21 20:55:09 +01:00
|
|
|
EPHYR_LOG("enter\n");
|
2010-06-21 00:34:54 +02:00
|
|
|
|
|
|
|
screens = xcb_setup_roots_iterator(xcb_get_setup(HostX.conn));
|
|
|
|
for (screen_num = 0; screens.rem; screen_num++, xcb_screen_next(&screens)) {
|
|
|
|
depths = xcb_screen_allowed_depths_iterator(screens.data);
|
|
|
|
for (; depths.rem; xcb_depth_next(&depths)) {
|
|
|
|
xcb_visualtype_t *visuals = xcb_depth_visuals(depths.data);
|
|
|
|
EphyrHostVisualInfo *tmp_visuals =
|
|
|
|
realloc(host_visuals,
|
|
|
|
(nb_items + depths.data->visuals_len)
|
|
|
|
* sizeof(EphyrHostVisualInfo));
|
|
|
|
if (!tmp_visuals) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
host_visuals = tmp_visuals;
|
|
|
|
for (i = 0; i < depths.data->visuals_len; i++) {
|
|
|
|
host_visuals[nb_items + i].visualid = visuals[i].visual_id;
|
|
|
|
host_visuals[nb_items + i].screen = screen_num;
|
|
|
|
host_visuals[nb_items + i].depth = depths.data->depth;
|
|
|
|
host_visuals[nb_items + i].class = visuals[i]._class;
|
|
|
|
host_visuals[nb_items + i].red_mask = visuals[i].red_mask;
|
|
|
|
host_visuals[nb_items + i].green_mask = visuals[i].green_mask;
|
|
|
|
host_visuals[nb_items + i].blue_mask = visuals[i].blue_mask;
|
|
|
|
host_visuals[nb_items + i].colormap_size = visuals[i].colormap_entries;
|
|
|
|
host_visuals[nb_items + i].bits_per_rgb = visuals[i].bits_per_rgb_value;
|
|
|
|
}
|
|
|
|
nb_items += depths.data->visuals_len;
|
|
|
|
}
|
2007-08-28 15:58:55 +02:00
|
|
|
}
|
2010-06-21 00:34:54 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
EPHYR_LOG("host advertises %d visuals\n", nb_items);
|
|
|
|
*a_visuals = host_visuals;
|
2007-08-28 15:58:55 +02:00
|
|
|
*a_num_entries = nb_items;
|
2012-03-21 20:55:09 +01:00
|
|
|
host_visuals = NULL;
|
2007-08-28 15:58:55 +02:00
|
|
|
|
|
|
|
is_ok = TRUE;
|
2010-06-21 00:34:54 +02:00
|
|
|
out:
|
2010-06-09 23:08:54 +02:00
|
|
|
free(host_visuals);
|
|
|
|
host_visuals = NULL;
|
2012-03-21 20:55:09 +01:00
|
|
|
EPHYR_LOG("leave\n");
|
|
|
|
return is_ok;
|
2007-08-28 15:58:55 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-09-08 00:33:59 +02:00
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_create_window(int a_screen_number,
|
|
|
|
EphyrBox * a_geometry,
|
|
|
|
int a_visual_id, int *a_host_peer /*out parameter */ )
|
2007-09-08 00:33:59 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
Bool is_ok = FALSE;
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_window_t win;
|
|
|
|
int winmask = 0;
|
|
|
|
uint32_t attrs[2];
|
|
|
|
xcb_screen_t *screen = xcb_aux_get_screen(HostX.conn, hostx_get_screen());
|
|
|
|
xcb_visualtype_t *visual;
|
|
|
|
int depth = 0;
|
|
|
|
EPHYR_RETURN_VAL_IF_FAIL(screen && a_geometry, FALSE);
|
2007-09-08 00:33:59 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
EPHYR_LOG("enter\n");
|
2007-09-08 00:33:59 +02:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
visual = xcb_aux_find_visual_by_id(screen, a_visual_id);
|
|
|
|
if (!visual) {
|
|
|
|
EPHYR_LOG_ERROR ("argh, could not find a remote visual with id:%d\n",
|
|
|
|
a_visual_id);
|
2012-03-21 20:55:09 +01:00
|
|
|
goto out;
|
2007-09-08 00:33:59 +02:00
|
|
|
}
|
2010-06-20 01:05:40 +02:00
|
|
|
depth = xcb_aux_get_depth_of_visual(screen, a_visual_id);
|
|
|
|
|
|
|
|
winmask = XCB_CW_EVENT_MASK | XCB_CW_COLORMAP;
|
|
|
|
attrs[0] = XCB_EVENT_MASK_BUTTON_PRESS
|
|
|
|
|XCB_EVENT_MASK_BUTTON_RELEASE
|
|
|
|
|XCB_EVENT_MASK_POINTER_MOTION
|
|
|
|
|XCB_EVENT_MASK_KEY_PRESS
|
|
|
|
|XCB_EVENT_MASK_KEY_RELEASE
|
|
|
|
|XCB_EVENT_MASK_EXPOSURE;
|
|
|
|
attrs[1] = xcb_generate_id(HostX.conn);
|
|
|
|
xcb_create_colormap(HostX.conn,
|
|
|
|
XCB_COLORMAP_ALLOC_NONE,
|
|
|
|
attrs[1],
|
|
|
|
hostx_get_window(a_screen_number),
|
|
|
|
a_visual_id);
|
|
|
|
|
|
|
|
win = xcb_generate_id(HostX.conn);
|
|
|
|
xcb_create_window(HostX.conn,
|
|
|
|
depth,
|
|
|
|
win,
|
|
|
|
hostx_get_window (a_screen_number),
|
|
|
|
a_geometry->x, a_geometry->y,
|
|
|
|
a_geometry->width, a_geometry->height, 0,
|
|
|
|
XCB_WINDOW_CLASS_COPY_FROM_PARENT,
|
|
|
|
a_visual_id, winmask, attrs);
|
|
|
|
|
|
|
|
if (HostX.screens[a_screen_number].peer_win == XCB_NONE) {
|
2012-03-21 20:55:09 +01:00
|
|
|
HostX.screens[a_screen_number].peer_win = win;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
EPHYR_LOG_ERROR("multiple peer windows created for same screen\n");
|
2008-10-22 22:12:53 +02:00
|
|
|
}
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_flush(HostX.conn);
|
|
|
|
xcb_map_window(HostX.conn, win);
|
2012-03-21 20:55:09 +01:00
|
|
|
*a_host_peer = win;
|
|
|
|
is_ok = TRUE;
|
|
|
|
out:
|
|
|
|
EPHYR_LOG("leave\n");
|
|
|
|
return is_ok;
|
2007-09-08 00:33:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_destroy_window(int a_win)
|
2007-09-08 00:33:59 +02:00
|
|
|
{
|
2010-06-20 01:05:40 +02:00
|
|
|
xcb_destroy_window(HostX.conn, a_win);
|
|
|
|
xcb_flush(HostX.conn);
|
2012-03-21 20:55:09 +01:00
|
|
|
return TRUE;
|
2007-09-08 00:33:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_set_window_geometry(int a_win, EphyrBox * a_geo)
|
2007-09-08 00:33:59 +02:00
|
|
|
{
|
2010-06-20 01:05:40 +02:00
|
|
|
uint32_t mask = XCB_CONFIG_WINDOW_X
|
|
|
|
| XCB_CONFIG_WINDOW_Y
|
|
|
|
| XCB_CONFIG_WINDOW_WIDTH
|
|
|
|
| XCB_CONFIG_WINDOW_HEIGHT;
|
|
|
|
uint32_t values[4];
|
2007-09-08 00:33:59 +02:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
EPHYR_RETURN_VAL_IF_FAIL(a_geo, FALSE);
|
2007-09-08 00:33:59 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
EPHYR_LOG("enter. x,y,w,h:(%d,%d,%d,%d)\n",
|
|
|
|
a_geo->x, a_geo->y, a_geo->width, a_geo->height);
|
2007-09-08 00:33:59 +02:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
values[0] = a_geo->x;
|
|
|
|
values[1] = a_geo->y;
|
|
|
|
values[2] = a_geo->width;
|
|
|
|
values[3] = a_geo->height;
|
|
|
|
xcb_configure_window(HostX.conn, a_win, mask, values);
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
EPHYR_LOG("leave\n");
|
2007-09-08 00:33:59 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-09-17 18:15:03 +02:00
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_set_window_bounding_rectangles(int a_window,
|
|
|
|
EphyrRect * a_rects, int a_num_rects)
|
2007-09-17 18:15:03 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
Bool is_ok = FALSE;
|
|
|
|
int i = 0;
|
2010-06-25 00:00:38 +02:00
|
|
|
xcb_rectangle_t *rects = NULL;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2010-06-25 00:00:38 +02:00
|
|
|
EPHYR_RETURN_VAL_IF_FAIL(a_rects, FALSE);
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
EPHYR_LOG("enter. num rects:%d\n", a_num_rects);
|
|
|
|
|
2010-06-25 00:00:38 +02:00
|
|
|
rects = calloc(a_num_rects, sizeof (xcb_rectangle_t));
|
|
|
|
if (!rects)
|
|
|
|
goto out;
|
2012-03-21 20:55:09 +01:00
|
|
|
for (i = 0; i < a_num_rects; i++) {
|
|
|
|
rects[i].x = a_rects[i].x1;
|
|
|
|
rects[i].y = a_rects[i].y1;
|
|
|
|
rects[i].width = abs(a_rects[i].x2 - a_rects[i].x1);
|
|
|
|
rects[i].height = abs(a_rects[i].y2 - a_rects[i].y1);
|
|
|
|
EPHYR_LOG("borders clipped to rect[x:%d,y:%d,w:%d,h:%d]\n",
|
|
|
|
rects[i].x, rects[i].y, rects[i].width, rects[i].height);
|
2007-09-17 18:15:03 +02:00
|
|
|
}
|
2010-06-25 00:00:38 +02:00
|
|
|
xcb_shape_rectangles(HostX.conn,
|
|
|
|
XCB_SHAPE_SO_SET,
|
|
|
|
XCB_SHAPE_SK_BOUNDING,
|
|
|
|
XCB_CLIP_ORDERING_YX_BANDED,
|
|
|
|
a_window,
|
|
|
|
0, 0,
|
|
|
|
a_num_rects,
|
|
|
|
rects);
|
2012-03-21 20:55:09 +01:00
|
|
|
is_ok = TRUE;
|
2007-09-17 18:15:03 +02:00
|
|
|
|
2010-06-25 00:00:38 +02:00
|
|
|
out:
|
2010-06-09 23:08:54 +02:00
|
|
|
free(rects);
|
|
|
|
rects = NULL;
|
2012-03-21 20:55:09 +01:00
|
|
|
EPHYR_LOG("leave\n");
|
2007-09-17 18:15:03 +02:00
|
|
|
return is_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_set_window_clipping_rectangles(int a_window,
|
|
|
|
EphyrRect * a_rects, int a_num_rects)
|
2007-09-17 18:15:03 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
Bool is_ok = FALSE;
|
|
|
|
Display *dpy = hostx_get_display();
|
|
|
|
int i = 0;
|
2010-06-25 00:00:38 +02:00
|
|
|
xcb_rectangle_t *rects = NULL;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
EPHYR_RETURN_VAL_IF_FAIL(dpy && a_rects, FALSE);
|
|
|
|
|
|
|
|
EPHYR_LOG("enter. num rects:%d\n", a_num_rects);
|
|
|
|
|
2010-06-25 00:00:38 +02:00
|
|
|
rects = calloc(a_num_rects, sizeof (xcb_rectangle_t));
|
|
|
|
if (!rects)
|
|
|
|
goto out;
|
2012-03-21 20:55:09 +01:00
|
|
|
for (i = 0; i < a_num_rects; i++) {
|
|
|
|
rects[i].x = a_rects[i].x1;
|
|
|
|
rects[i].y = a_rects[i].y1;
|
|
|
|
rects[i].width = abs(a_rects[i].x2 - a_rects[i].x1);
|
|
|
|
rects[i].height = abs(a_rects[i].y2 - a_rects[i].y1);
|
|
|
|
EPHYR_LOG("clipped to rect[x:%d,y:%d,w:%d,h:%d]\n",
|
|
|
|
rects[i].x, rects[i].y, rects[i].width, rects[i].height);
|
2007-09-17 18:15:03 +02:00
|
|
|
}
|
2010-06-25 00:00:38 +02:00
|
|
|
xcb_shape_rectangles(HostX.conn,
|
|
|
|
XCB_SHAPE_SO_SET,
|
|
|
|
XCB_SHAPE_SK_CLIP,
|
|
|
|
XCB_CLIP_ORDERING_YX_BANDED,
|
|
|
|
a_window,
|
|
|
|
0, 0,
|
|
|
|
a_num_rects,
|
|
|
|
rects);
|
2012-03-21 20:55:09 +01:00
|
|
|
is_ok = TRUE;
|
2007-09-17 18:15:03 +02:00
|
|
|
|
2010-06-25 00:00:38 +02:00
|
|
|
out:
|
2010-06-09 23:08:54 +02:00
|
|
|
free(rects);
|
|
|
|
rects = NULL;
|
2012-03-21 20:55:09 +01:00
|
|
|
EPHYR_LOG("leave\n");
|
2007-09-17 18:15:03 +02:00
|
|
|
return is_ok;
|
|
|
|
}
|
|
|
|
|
2007-09-19 15:35:51 +02:00
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_has_xshape(void)
|
2007-09-19 15:35:51 +02:00
|
|
|
{
|
2010-06-20 01:05:40 +02:00
|
|
|
const xcb_query_extension_reply_t *rep;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
rep = xcb_get_extension_data(HostX.conn, &xcb_shape_id);
|
|
|
|
return rep && rep->present;
|
2007-09-19 15:35:51 +02:00
|
|
|
}
|
|
|
|
|
2008-04-23 16:46:30 +02:00
|
|
|
#ifdef XF86DRI
|
2008-01-15 06:27:16 +01:00
|
|
|
typedef struct {
|
2012-03-21 20:55:09 +01:00
|
|
|
int is_valid;
|
|
|
|
int local_id;
|
|
|
|
int remote_id;
|
|
|
|
} ResourcePair;
|
2008-01-15 06:27:16 +01:00
|
|
|
|
|
|
|
#define RESOURCE_PEERS_SIZE 1024*10
|
2012-03-21 20:55:09 +01:00
|
|
|
static ResourcePair resource_peers[RESOURCE_PEERS_SIZE];
|
2008-01-15 06:27:16 +01:00
|
|
|
|
2007-09-19 15:35:51 +02:00
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_allocate_resource_id_peer(int a_local_resource_id,
|
|
|
|
int *a_remote_resource_id)
|
2007-09-19 15:35:51 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
int i = 0;
|
|
|
|
ResourcePair *peer = NULL;
|
2007-09-19 15:35:51 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* first make sure a resource peer
|
|
|
|
* does not exist already for
|
|
|
|
* a_local_resource_id
|
|
|
|
*/
|
2012-03-21 20:55:09 +01:00
|
|
|
for (i = 0; i < RESOURCE_PEERS_SIZE; i++) {
|
2007-09-19 15:35:51 +02:00
|
|
|
if (resource_peers[i].is_valid
|
|
|
|
&& resource_peers[i].local_id == a_local_resource_id) {
|
2012-03-21 20:55:09 +01:00
|
|
|
peer = &resource_peers[i];
|
|
|
|
break;
|
2007-09-19 15:35:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* find one free peer entry, an feed it with
|
|
|
|
*/
|
|
|
|
if (!peer) {
|
2012-03-21 20:55:09 +01:00
|
|
|
for (i = 0; i < RESOURCE_PEERS_SIZE; i++) {
|
2007-09-19 15:35:51 +02:00
|
|
|
if (!resource_peers[i].is_valid) {
|
2012-03-21 20:55:09 +01:00
|
|
|
peer = &resource_peers[i];
|
|
|
|
break;
|
2007-09-19 15:35:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (peer) {
|
2010-06-20 01:05:40 +02:00
|
|
|
peer->remote_id = xcb_generate_id(HostX.conn);
|
2012-03-21 20:55:09 +01:00
|
|
|
peer->local_id = a_local_resource_id;
|
|
|
|
peer->is_valid = TRUE;
|
2007-09-19 15:35:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (peer) {
|
2012-03-21 20:55:09 +01:00
|
|
|
*a_remote_resource_id = peer->remote_id;
|
|
|
|
return TRUE;
|
2007-09-19 15:35:51 +02:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
return FALSE;
|
2007-09-19 15:35:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_get_resource_id_peer(int a_local_resource_id, int *a_remote_resource_id)
|
2007-09-19 15:35:51 +02:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
int i = 0;
|
|
|
|
ResourcePair *peer = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < RESOURCE_PEERS_SIZE; i++) {
|
2007-09-19 15:35:51 +02:00
|
|
|
if (resource_peers[i].is_valid
|
|
|
|
&& resource_peers[i].local_id == a_local_resource_id) {
|
2012-03-21 20:55:09 +01:00
|
|
|
peer = &resource_peers[i];
|
|
|
|
break;
|
2007-09-19 15:35:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (peer) {
|
2012-03-21 20:55:09 +01:00
|
|
|
*a_remote_resource_id = peer->remote_id;
|
|
|
|
return TRUE;
|
2007-09-19 15:35:51 +02:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
return FALSE;
|
2007-09-19 15:35:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_has_dri(void)
|
2007-09-19 15:35:51 +02:00
|
|
|
{
|
2010-06-20 01:05:40 +02:00
|
|
|
const xcb_query_extension_reply_t *dri;
|
2007-09-19 15:35:51 +02:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
dri = xcb_get_extension_data(HostX.conn, &xcb_xf86dri_id);
|
2007-10-04 13:05:29 +02:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
return dri && dri->present;
|
2007-09-19 15:35:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
hostx_has_glx(void)
|
2007-09-19 15:35:51 +02:00
|
|
|
{
|
2010-06-20 01:05:40 +02:00
|
|
|
const xcb_query_extension_reply_t *glx;
|
2007-09-19 15:35:51 +02:00
|
|
|
|
2010-06-20 01:05:40 +02:00
|
|
|
glx = xcb_get_extension_data(HostX.conn, &xcb_glx_id);
|
|
|
|
|
|
|
|
return glx && glx->present;
|
2007-09-19 15:35:51 +02:00
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
#endif /* XF86DRI */
|