Ejemplo n.º 1
0
Archivo: x11.c Proyecto: engur/fs-uae
static void set_above_state() {
    printf("_NET_WM_STATE = _NET_WM_STATE_ABOVE\n");
    Atom ATOM = XInternAtom(g_display, "ATOM", False);
    Atom _NET_WM_STATE = XInternAtom(g_display, "_NET_WM_STATE", False);
    Atom _NET_WM_STATE_ABOVE = XInternAtom(
        g_display, "_NET_WM_STATE_ABOVE", False);
    XChangeProperty(g_display, g_window, _NET_WM_STATE, ATOM, 32,
            PropModeReplace, (unsigned char *) &_NET_WM_STATE_ABOVE, 1);

    XEvent ev;
    memset(&ev, 0, sizeof(ev));
    ev.type = ClientMessage;
    ev.xclient.type         = ClientMessage;
    ev.xclient.message_type = XInternAtom(g_display, "_NET_WM_STATE", 0);
    ev.xclient.display      = g_display;
    ev.xclient.window       = g_window;
    ev.xclient.format       = 32;
    ev.xclient.data.l[0]    = 1; // set ? 1 : 0;

    // *_STAYS_ON_TOP is probably KDE-specific
    ev.xclient.data.l[1] = XInternAtom(
        g_display, "_NET_WM_STATE_STAYS_ON_TOP", 0);
    XLockDisplay(g_display);
    XSendEvent(g_display, XDefaultRootWindow(g_display), 0,
               SubstructureRedirectMask | SubstructureNotifyMask, &ev);

    // to work with some non-KDE WMs we should use _NET_WM_STATE_ABOVE
    ev.xclient.data.l[1] = XInternAtom(
        g_display, "_NET_WM_STATE_ABOVE", 0);
    XSendEvent(g_display, XDefaultRootWindow(g_display), 0,
               SubstructureRedirectMask | SubstructureNotifyMask, &ev);
    XUnlockDisplay(g_display);
}
Ejemplo n.º 2
0
//---------------------------------------------------------------------------
bool hxc_popuphints::create()
{
  if (XD==NULL) return 0;
  if (handle) close();

  hxc::load_res(XD);

  if (max_width==0) max_width=XDisplayWidth(XD,XDefaultScreen(XD))/2;

  int th=hxc::font->ascent+hxc::font->descent+2;
  EasyStringList lines;
  get_current_lines(&lines);

  w=border+2+2+border;
  h=border+2+border;
  for (int n=0;n<lines.NumStrings;n++){
    w=max(border+2+(int)hxc::get_text_width(XD,lines[n].String)+2+border,w);
    h+=th;
  }

  Window in_win,in_child;
  int childx,childy,mx,my;
  x=XDisplayWidth(XD,XDefaultScreen(XD))/2;
  y=XDisplayWidth(XD,XDefaultScreen(XD))/2;
  UINT mask;
  XQueryPointer(XD,XDefaultRootWindow(XD),&in_win,&in_child,
                    &mx,&my,&childx,&childy,&mask);
  x=mx;
  y=my+20;

  int sw=XDisplayWidth(XD,XDefaultScreen(XD));
  int sh=XDisplayHeight(XD,XDefaultScreen(XD));
  if (x+w>sw) x=sw-w;
	if (y+h>sh) y=my-5-h;

  XSetWindowAttributes swa;
  swa.backing_store=NotUseful;
  swa.override_redirect=True;
  swa.cursor=hxc::arrow_cursor;
  handle=XCreateWindow(XD,XDefaultRootWindow(XD),x,y,w,h,0,
                           CopyFromParent,InputOutput,CopyFromParent,
                           CWBackingStore | CWOverrideRedirect | CWCursor,
                           &swa);

  SetProp(XD,handle,cWinProc,(DWORD)WinProc);
  SetProp(XD,handle,cWinThis,(DWORD)this);
  SetProp(XD,handle,hxc::cModal,(DWORD)0xffffffff);

  XSelectInput(XD,handle,ExposureMask);

  XMapWindow(XD,handle);
  return false;
}
Ejemplo n.º 3
0
bool CursorImpl::loadFromPixels(const Uint8* pixels, Vector2u size, Vector2u hotspot)
{
    release();

    // Convert the image into a bitmap (monochrome!).
    std::size_t bytes = (size.x + 7) / 8 * size.y;
    std::vector<Uint8> mask(bytes, 0); // Defines which pixel is transparent.
    std::vector<Uint8> data(bytes, 1); // Defines which pixel is white/black.

    for (std::size_t j = 0; j < size.y; ++j)
    {
        for (std::size_t i = 0; i < size.x; ++i)
        {
            std::size_t pixelIndex = i + j * size.x;
            std::size_t byteIndex  = pixelIndex / 8;
            std::size_t bitIndex   = i % 8;

            // Turn on pixel that are not transparent
            Uint8 opacity = pixels[pixelIndex * 4 + 3] > 0 ? 1 : 0;
            mask[byteIndex] |= opacity << bitIndex;

            // Choose between black/background & white/foreground color for each pixel,
            // based on the pixel color intensity: on average, if a channel is "active"
            // at 25%, the bit is white.
            int intensity = pixels[pixelIndex * 4 + 0] + pixels[pixelIndex * 4 + 1] + pixels[pixelIndex * 4 + 2];
            Uint8 bit = intensity > 64 ? 1 : 0;
            data[byteIndex] |= bit << bitIndex;
        }
    }

    Pixmap maskPixmap = XCreateBitmapFromData(m_display, XDefaultRootWindow(m_display),
                                              (char*)&mask[0], size.x, size.y);
    Pixmap dataPixmap = XCreateBitmapFromData(m_display, XDefaultRootWindow(m_display),
                                              (char*)&data[0], size.x, size.y);

    // Define the foreground color as white and the background as black.
    XColor fg, bg;
    fg.red = fg.blue = fg.green = -1;
    bg.red = bg.blue = bg.green =  0;

    // Create the monochrome cursor.
    m_cursor = XCreatePixmapCursor(m_display,
                                   dataPixmap, maskPixmap,
                                   &fg, &bg,
                                   hotspot.x, hotspot.y);

    // Free the resources
    XFreePixmap(m_display, dataPixmap);
    XFreePixmap(m_display, maskPixmap);

    // We assume everything went fine...
    return true;
}
Ejemplo n.º 4
0
GAE_RenderWindow_t* GAE_RenderWindow_open(GAE_RenderWindow_t* window) {
	GAE_X11_RenderWindow_t* x11Window = (GAE_X11_RenderWindow_t*)window->platform;

	x11Window->window = XCreateWindow(x11Window->display 	/* Pointer to the Display */
				, XDefaultRootWindow(x11Window->display)	/* Parent Window */
				, 0											/* X of top-left corner */
				, 0											/* Y of top-left corner */
				, window->width								/* requested width */
				, window->height							/* requested height */
				, 0											/* border width */
				, CopyFromParent							/* window depth */
				, CopyFromParent							/* window class - InputOutput / InputOnly / CopyFromParent */
				, CopyFromParent							/* visual type */
				, 0											/* value mask */
				, 0);										/* attributes */

	XMapWindow(x11Window->display, x11Window->window);

	XStoreName(x11Window->display, x11Window->window, window->name);

	XSelectInput(x11Window->display, x11Window->window, ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask);

	x11Window->deleteMessage = XInternAtom(x11Window->display, "WM_DELETE_WINDOW", 0);
	XSetWMProtocols(x11Window->display, x11Window->window, &x11Window->deleteMessage, 1);

	checkFullscreen(x11Window, window);

	return window;
}
Ejemplo n.º 5
0
// Sends a key press and a key release event to the currently focused window.
// See /usr/include/X11/keysymdef.h for available keys.
void sendKey(int keysym) {
  Display *display = XOpenDisplay(0);
  Window rootWindow = XDefaultRootWindow(display);

  // Get window with focus
  Window focusWindow;
  int revert;
  XGetInputFocus(display, &focusWindow, &revert);

  XKeyEvent event;
  event.display = display;
  event.root = rootWindow;
  event.window = focusWindow;
  event.same_screen = True;
  event.state = 0;
  event.keycode = XKeysymToKeycode(display, keysym);

  // Send KeyPress event
  event.type = KeyPress;
  XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent*)&event);

  // Send KeyRelease event
  event.type = KeyRelease;
  XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent*)&event);

  XCloseDisplay(display);
}
Ejemplo n.º 6
0
static Window get_current_window_ewmh(RoccatWindowMonitor *monitor) {
	RoccatWindowMonitorPrivate *priv = monitor->priv;
	Atom type;
	Window root;
	Window window;
	int status;
	unsigned long nitems;
	unsigned long bytes_after;
	unsigned char *prop;
	int format;

	if (priv->net_active_window == None)
		return None;

	root = XDefaultRootWindow(priv->display);
	if (root == None)
		return None;

	status = XGetWindowProperty(priv->display, root, priv->net_active_window, 0L, ~0L, False,
			AnyPropertyType, &type, &format, &nitems, &bytes_after, &prop);
	if (status == Success && type != None && prop) {
		window = *(Window *)prop;
		XFree(prop);
		return window;
	} else
		return None;
}
Ejemplo n.º 7
0
 void print_window_attrs(Display *display, Window focus_win, int &wx, int &wy){
        XWindowAttributes wattrs;
        XGetWindowAttributes(display, focus_win, &wattrs);
        char *wname;
        XFetchName(display, focus_win, &wname);
        int root_x,root_y;
        Window unused_child;
        Window root = XDefaultRootWindow(display);
        XTranslateCoordinates(display, focus_win, wattrs.root, wattrs.x, wattrs.y, &root_x, &root_y, &unused_child);


        Window root_return;
        int x_return, y_return;
        unsigned int width_return, height_return;
        unsigned int border_width_return;
        unsigned int depth_return;

        XGetGeometry(display, focus_win, &root_return, &x_return, &y_return, &width_return, 
                      &height_return, &border_width_return, &depth_return);

        debug()<<"Window Info: "<<"("<< wattrs.x <<','<< wattrs.y <<") "<< wattrs.width <<'x'<< wattrs.height<<' '<< focus_win<<' '<<wattrs.root<<std::endl
               <<"             "<<"("<< root_x   <<','<<root_y<<')'<<std::endl
               <<"             "<<"("<< x_return <<','<<y_return<<") "<<width_return<<'x'<<height_return<<' '<<root_return<<(root_return==root?'=':'x')<<std::endl
               <<' '<< wname<< std::endl;

        wx = root_x; wy = root_y; // delta (+7,+24)
}
Ejemplo n.º 8
0
/*
 * Initialize SubPopup(color)
 */
void InitSubPopupColor()
{
  int i;
  char buf[4];
  Pixmap checkmarkBitmap;
  String trans2 =
    "<Leave>:  SubPopdown(pctop)";

  checkmarkBitmap = XCreateBitmapFromData(XtDisplay(toplevel),
					  XDefaultRootWindow(XtDisplay(toplevel)),
					  coloritem_bits,
					  coloritem_width,coloritem_height);

  pcTop = Xt_P("pctop" ,simpleMenuWidgetClass,toplevel,NULL);
          Xt_W("pcline",smeLineObjectClass   ,pcTop   ,XtNlineWidth,2,NULL);

  for(i=0;i<POPUP_COLOR_NITEM;i++) {
    sprintf(buf,"pc%1d",i);
    pc[i] = Xt_W(buf,smeBSBObjectClass,pcTop,NULL);

    XtVaSetValues(pc[i],
		  XtNleftBitmap,checkmarkBitmap,
		  XtNleftMargin,72,
		  XtNlabel,"",
		  NULL);
    XtAddCallback(pc[i],XtNcallback,(XtCallbackProc)SelectColor,(XtPointer)i);
  }

  XtOverrideTranslations(pcTop,XtParseTranslationTable(trans2));
}
Ejemplo n.º 9
0
Pixmap XcodaCreatePixmapFromXpm(Widget parent,
				const char** data,
				int    type)
{
  Display        *dpy = XtDisplay(parent);
  Window         win = XDefaultRootWindow(dpy);
  Screen         *scr = XDefaultScreenOfDisplay(dpy);
  int            depth = DefaultDepthOfScreen(scr);
  Colormap       cmap = DefaultColormapOfScreen(scr);
  XpmAttributes  attr;
  unsigned int  valuemask = 0;
  int            err;

  /*unsigned int  pixmap_ret, pixmap_mask;*/
  Pixmap pixmap_ret, pixmap_mask;

  XpmColorSymbol col_symbol[1];
  Arg            arg[5];
  int            ac = 0;
  Pixel          parent_bg;

  if(type){ /* normal background for pixmap */
    XtSetArg (arg[ac], XmNbackground, &parent_bg); ac++;
    XtGetValues (parent, arg, ac);
    ac = 0;
  }
  else{  /* inverted or highlighted pixmap */
    XtSetArg (arg[ac], XmNforeground, &parent_bg); ac++;
    XtGetValues (parent, arg, ac);
    ac = 0;
  }    
  col_symbol[0].name = (char *)NULL;
  col_symbol[0].value = (char *)malloc((strlen("LightBlue")+1)*sizeof(char));
  strcpy(col_symbol[0].value,"LightBlue");
  col_symbol[0].pixel = parent_bg;
  
  attr.colormap = cmap;
  attr.depth = depth;
  attr.colorsymbols = col_symbol;
  attr.valuemask = valuemask;
  attr.numsymbols = 1;
  attr.closeness = 65536;
  
  attr.valuemask |= XpmReturnPixels;
  attr.valuemask |= XpmColormap;
  attr.valuemask |= XpmColorSymbols;
  attr.valuemask |= XpmDepth;
  attr.valuemask |= XpmCloseness;
  /*
  printf("Calling XpmCreatePixmapFromData ...\n");
  */
  err = XpmCreatePixmapFromData(dpy, win, (char **)data, &pixmap_ret, &pixmap_mask, &attr);
  
  free (col_symbol[0].value);
  if(err != XpmSuccess){
    pixmap_ret = 0;
  }

  return pixmap_ret;
}
Ejemplo n.º 10
0
INLINE MMPoint getMousePos()
{
#if defined(IS_MACOSX)
	CGEventRef event = CGEventCreate(NULL);
	CGPoint point = CGEventGetLocation(event);
	CFRelease(event);

	return MMPointFromCGPoint(point);
#elif defined(USE_X11)
	int x, y; /* This is all we care about. Seriously. */
	Window garb1, garb2; /* Why you can't specify NULL as a parameter */
	int garb_x, garb_y;  /* is beyond me. */
	unsigned int more_garbage;

	Display *display = XGetMainDisplay();
	XQueryPointer(display, XDefaultRootWindow(display), &garb1, &garb2,
	              &x, &y, &garb_x, &garb_y, &more_garbage);

	return MMPointMake(x, y);
#elif defined(IS_WINDOWS)
	POINT point;
	GetCursorPos(&point);

	return MMPointFromPOINT(point);
#endif
}
Ejemplo n.º 11
0
const Result ctrlr_sendKeyPressEvent (const KeyPress &keyPress)
{
    Display *display = XOpenDisplay(0);
    if(display == NULL)
        return (Result::fail("Can't open display"));

   Window winRoot = XDefaultRootWindow(display);
   Window winFocus;
   int    revert;
   if (!XGetInputFocus(display, &winFocus, &revert))
   {
       return (Result::fail("XGetInputFocus failed"));
   }

   XKeyEvent event = createKeyEvent(display, winFocus, winRoot, true, keyPress.getKeyCode(), keyPress.getModifiers().getRawFlags());
   if (XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event) == 0)
   {
       return (Result::fail("XSendEvent failed"));
   }

   event = createKeyEvent(display, winFocus, winRoot, false, keyPress.getKeyCode(), keyPress.getModifiers().getRawFlags());
   if (XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event) == 0)
   {
       return (Result::fail("XSendEvent failed"));
   }

   XCloseDisplay(display);
   return (Result::ok());
}
Ejemplo n.º 12
0
void switch_window()
{
	unsigned char *current_window_data, *desktop_data;
	Window root, current_window;
	int i;

	if (display == NULL) return;

	root = XDefaultRootWindow(display);
	
	if ( get_property(root, "_NET_ACTIVE_WINDOW", &current_window_data) < 0)
	{
		return;
	}

	current_window = *((Window *) current_window_data);
	XFree(current_window_data);

	for (i=0; i<top_level_window_list.length 
	         && top_level_window_list.set[i] != current_window; i++);

	// will be replaced with init windowz
	if (i == top_level_window_list.length) return;
	else if (i == top_level_window_list.length-1) i=-1;

	if ( get_property(top_level_window_list.set[i+1], "_NET_WM_DESKTOP", &desktop_data) < 0)
	{
		return;
	}

	send_message("_NET_CURRENT_DESKTOP", root, *((unsigned long *) desktop_data), 0, 0, 0, 0);

	send_message("_NET_ACTIVE_WINDOW", top_level_window_list.set[i+1], 0, 0, 0, 0, 0);
}
Ejemplo n.º 13
0
int send_event( int keycode, Display *active_display)
{
    int res = 0;
    XEvent event;
    Window win;
    int revert_to;
    struct timeval t;
    gettimeofday(&t, NULL);
    XGetInputFocus(active_display, &win, &revert_to);
    event.xkey.type = KeyPress;
    event.xkey.serial = 0;
    event.xkey.send_event = True;
    event.xkey.display = active_display;
    event.xkey.window = win;
    event.xkey.root = XDefaultRootWindow(active_display);
    event.xkey.subwindow = None;
    event.xkey.time = t.tv_usec;
    event.xkey.x = 0;
    event.xkey.y = 0;
    event.xkey.x_root = 0;
    event.xkey.state = 0;
    event.xkey.keycode = keycode;
    event.xkey.same_screen=True;
    res = XSendEvent(active_display, InputFocus, True, 3, &event);
    XFlush(active_display);
    if (res == BadValue || res == BadWindow)
    res = -1;
    return res;
}
int cheese(int keyPress)
{
    // Obtain the X11 display.
    Display *display = XOpenDisplay(0);
    if(display == NULL)
        return -1;

    // Get the root window for the current display.
    Window winRoot = XDefaultRootWindow(display);

    // Find the window which has the current keyboard focus.
    Window winFocus;
    int    revert;
    XGetInputFocus(display, &winFocus, &revert);


    // Send a fake key press event to the window.
    XKeyEvent event = createKeyEvent(display, winFocus, winRoot, true, keyPress, 0);
    XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event);

    // Send a fake key release event to the window.
    event = createKeyEvent(display, winFocus, winRoot, false, keyPress, 0);
    XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event);

    // Done.
    XCloseDisplay(display);

    return 0;
}
Ejemplo n.º 15
0
static int VimRemotingClient_init_internal(VimRemotingClient *client)
{
    prologue(client);

    client->commProperty = XInternAtom(client->dpy, "Comm", False);
    client->vimProperty = XInternAtom(client->dpy, "Vim", False);
    client->registryProperty = XInternAtom(client->dpy, "VimRegistry", False);

    client->window = XCreateSimpleWindow(
            client->dpy, XDefaultRootWindow(client->dpy),
            getpid(), 0, 10, 10, 0,
            WhitePixel(client->dpy, DefaultScreen(client->dpy)),
            WhitePixel(client->dpy, DefaultScreen(client->dpy)));
    XSelectInput(client->dpy, client->window, PropertyChangeMask);

    /* WARNING: Do not step through this while debugging, it will hangup
     * the X server! */
    XGrabServer(client->dpy);
    deleteAnyLingerer(client);
    XUngrabServer(client->dpy);

    /* Make window recognizable as a vim window */
    XChangeProperty(
            client->dpy, client->window,
            client->vimProperty, XA_STRING,
            8, PropModeReplace, (char *)client->vim_version,
            (int)strlen(client->vim_version) + 1);

    XSync(client->dpy, False);

    epilogue(client);
    return client->got_x_error;
}
Ejemplo n.º 16
0
long desktop_count() {
    if (!_check_init()) {
        return -1;
    }
    if (!_is_supported_feature("_NET_NUMBER_OF_DESKTOPS")) {
        fprintf(stderr,
            "Your window manager does not support _NET_NUMBER_OF_DESKTOPS "
            "so I'm returning 1 since you obviously have one desktop");
        return 1;
    }

    Atom type;
    int size = 0;
    long item_count = 0;
    long ret = 1;

    Window root = XDefaultRootWindow(defaults->display);
    Atom request =
        XInternAtom(defaults->display, "_NET_NUMBER_OF_DESKTOPS", FALSE);

    unsigned char *data =
        _window_property(root, request, &item_count, &type, &size);

    if (item_count > 0) {
        ret = *((long*) data);
    }
    if(data) {
        XFree(data);
    }
    return ret;
}
Ejemplo n.º 17
0
long get_current_desktop() {
    Atom type;
    int size = 0;
    long item_count = 0;
    long desktop = 1;

    if (!_is_supported_feature("_NET_CURRENT_DESKTOP")) {
        fprintf(stderr,
            "Apparently your window manager doesn't support "
            "_NET_CURRENT_DESKTOP so I'm returning 1.\n");
        return 1;
    }

    Atom request =
            XInternAtom(defaults->display, "_NET_CURRENT_DESKTOP", FALSE);
    Window root = XDefaultRootWindow(defaults->display);

    unsigned char *desktops =
        _window_property(root, request, &item_count, &type, &size);

    if (item_count > 0) {
        desktop = *((long*) desktops);
    } else {
        desktop = -2; //Signals a problem as opposed to "I don't do that"
    }
    if(desktop) {
        XFree(desktops);
    }
    desktop++; //Force desktop to be one based rather than zero based
    return desktop;
}
Ejemplo n.º 18
0
int WindowInit(unsigned int const major, unsigned int const minor)
{
  display = XOpenDisplay(NULL);

	if(display == NULL) {
		puts("Cannot connect to the X server.\n");
		return -1;
	}

	width = XDisplayWidth(display, 0);
	height = XDisplayHeight(display, 0);

	XVisualInfo *visual = glXChooseVisual(display, 0, (int*)attrs);
	if(visual == NULL) {
		puts("Could not find a visual.\n");
		return -2;
	}

  window = XDefaultRootWindow(display);
  context = glXCreateContext(display, visual, NULL, GL_TRUE);
	glXMakeCurrent(display, window, context);
	XFree(visual);

  XQueryPointer(display, window, &window_returned,
       &window_returned, &root_x, &root_y, &win_x, &win_y,
       &mask_return);

	return 1;
}
Ejemplo n.º 19
0
void Widget::show(const Point &point)
{
    const iint32 x = point.x();
    const iint32 y = point.y();
    const iint32 width = minimumSize().width();
    const iint32 height = minimumSize().height();
    IdealGUI::Application *app = static_cast<IdealGUI::Application*>(application());
    IdealGUI::Application::PrivateImpl *a_d = static_cast<IdealGUI::Application::PrivateImpl*>(app->d);
    Display *dpy = a_d->m_dpy;
    if (!D_I->m_window) {
        if (!d->m_parentWidget) {
            D_I->m_window = XCreateSimpleWindow(dpy, XDefaultRootWindow(dpy), x, y, width, height, 0,
                                                 XWhitePixel(dpy, XDefaultScreen(dpy)),
                                                 XWhitePixel(dpy, XDefaultScreen(dpy)));
        } else {
            D_I->m_window = XCreateSimpleWindow(dpy, static_cast<IdealGUI::Widget::PrivateImpl*>(d->m_parentWidget->d)->m_window,
                                                 x, y, width, height, 0,
                                                 XWhitePixel(dpy, XDefaultScreen(dpy)),
                                                 XWhitePixel(dpy, XDefaultScreen(dpy)));
        }
        a_d->m_widgetMap[D_I->m_window] = this;
        XSelectInput(dpy, D_I->m_window, ExposureMask | ButtonPressMask | ButtonReleaseMask    |
                                          EnterWindowMask | LeaveWindowMask | PointerMotionMask |
                                          FocusChangeMask | KeyPressMask | KeyReleaseMask       |
                                          StructureNotifyMask | SubstructureNotifyMask);
    }
    XMapWindow(dpy, D_I->m_window);
    D_I->m_cs = cairo_xlib_surface_create(dpy, D_I->m_window, DefaultVisual(dpy, 0), width, height);
}
Ejemplo n.º 20
0
Window* NetClientList(Display* display, unsigned long *len)
{
	Window* windowList;
	Atom type;
	int form, errno;
	unsigned long remain;

	errno = XGetWindowProperty(
		display,
		XDefaultRootWindow(display),
		XInternAtom(display, "_NET_CLIENT_LIST", False),
		0,
		65536,
		False,
		XA_WINDOW,
		&type,
		&form,
		len,
		&remain,
		(byte**)&windowList
	);

	if(errno != Success)
	{
		MsgDev(D_ERROR, "VID_EnumerateInstances: Xlib error: %s\n", strerror(errno));
		return NULL;
	}
	return windowList;
}
Ejemplo n.º 21
0
void keyboardEvent(bool pressed,int key)
{
    // Find the window which has the current keyboard focus.
    Window win;
    int    revert;
    XGetInputFocus(display, &win, &revert);
    Window winRoot = XDefaultRootWindow(display);


    XKeyEvent event;

    event.display     = display;
    event.window      = win;
    event.root        = winRoot;
    event.subwindow   = None;
    event.time        = CurrentTime;
    event.x           = 1;
    event.y           = 1;
    event.x_root      = 1;
    event.y_root      = 1;
    event.same_screen = True;
    event.keycode     = XKeysymToKeycode(display, key);
    event.state       = 0;//modifiers;
    event.type = pressed? KeyPress : KeyRelease;
    XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event);

}
Ejemplo n.º 22
0
 cmsHPROFILE GetProfileFromAtom(Display* disp, const char* prop_name)
 {
     Atom atom = XInternAtom(disp, prop_name, True);
     if (atom)
     {
         int actual_format_return;
         unsigned long nitems_return = 0;
         unsigned long bytes_after_return = 0;
         unsigned char* prop_return = 0;
         Atom a;
         Window w = XDefaultRootWindow(disp);
         if (w)
         {
             XGetWindowProperty(disp, w, atom, 0, INT_MAX, False,
                 AnyPropertyType,
                 &a, &actual_format_return, &nitems_return,
                 &bytes_after_return, &prop_return);
             if (nitems_return && prop_return)
             {
                 cmsHPROFILE profile = cmsOpenProfileFromMem(prop_return, nitems_return);
                 XFree(prop_return);
                 if (profile != NULL)
                 {
                     return profile;
                 };
             };
         };
     };
     return NULL;
 }
Ejemplo n.º 23
0
static void send_message(const char *type, Window win, 
                        unsigned long data0, unsigned long data1, unsigned long data2,
                        unsigned long data3, unsigned long data4)
{
	Window root;
	XEvent event;
	long mask = SubstructureRedirectMask | SubstructureNotifyMask;

	root = XDefaultRootWindow(display);

	event.xclient.type = ClientMessage;
	event.xclient.serial = 0;
	event.xclient.send_event = True;
	event.xclient.message_type = XInternAtom(display, type, False);
	event.xclient.window = win;
	event.xclient.format = 32;
	event.xclient.data.l[0] = data0;
	event.xclient.data.l[1] = data1;
	event.xclient.data.l[2] = data2;
	event.xclient.data.l[3] = data3;
	event.xclient.data.l[4] = data4;

	XSendEvent(display, root, False, mask, &event);

	XFlush(display);
}
Ejemplo n.º 24
0
int
loadPixmap (Display * dpy, MyPixmap * pm, char *dir, char *file,
	    XpmColorSymbol * cs, int n)
{
  char filename[512];
  XpmAttributes attr;

#ifdef DEBUG
  printf ("entering loadPixmap\n");
#endif

  pm->pixmap = None;
  pm->mask = None;
  pm->width = 1;
  pm->height = 1;
  snprintf (filename, sizeof (filename), "%s/%s", dir, file);
  attr.colorsymbols = cs;
  attr.numsymbols = n;
  attr.valuemask = XpmSize;
  if (n > 0 && cs)
    attr.valuemask = attr.valuemask | XpmColorSymbols;
  if (XpmReadFileToPixmap
      (dpy, XDefaultRootWindow (dpy), filename, &pm->pixmap, &pm->mask,
       &attr))
    return False;
  pm->width = attr.width;
  pm->height = attr.height;
  XpmFreeAttributes (&attr);
  return True;
}
MouseTool::MouseTool(){
    #ifdef __APPLE__
    #elif __WIN32__
    #else
        dpy = XOpenDisplay(0); // Open the default display (the DISPLAY environment variable)
        root_window = XDefaultRootWindow(dpy); // Get the default root window
    #endif
}
Ejemplo n.º 26
0
Window SDLapplication::X11appRootWin()
{
	LockX11();
	Window win = XDefaultRootWindow(display);
	UnlockX11();

	return (win);
}
Ejemplo n.º 27
0
XinputHandler::XinputHandler() : InputHandlerObjectInterface()
{
    display = XOpenDisplay(0);
    if(display==NULL){
        qFatal("Failed to open display");
    }
    context = XDefaultRootWindow(display);
}
Ejemplo n.º 28
0
GLboolean FWindow::Linux_Initialize()
{
	Attributes = new GLint[12]{GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, DepthBits, GLX_STENCIL_SIZE, StencilBits,
	   GLX_RED_SIZE, ColourBits, GLX_GREEN_SIZE, ColourBits, GLX_BLUE_SIZE, ColourBits, None};

	Decorators = 1;
	CurrentWindowStyle |= LINUX_DECORATOR_CLOSE | LINUX_DECORATOR_MAXIMIZE | LINUX_DECORATOR_MINIMIZE | LINUX_DECORATOR_MOVE;

	if (!WindowManager::GetDisplay())
	{
		PrintErrorMessage(ERROR_LINUX_CANNOTCONNECTXSERVER);
		exit(0);
	}

	VisualInfo = glXGetVisualFromFBConfig(WindowManager::GetDisplay(), GetBestFrameBufferConfig()); 

	//VisualInfo = glXChooseVisual(WindowManager::GetDisplay(), 0, Attributes);

	if (!VisualInfo)
	{
		PrintErrorMessage(ERROR_LINUX_INVALIDVISUALINFO);
		exit(0);
	}

	SetAttributes.colormap = XCreateColormap(WindowManager::GetDisplay(),
		DefaultRootWindow(WindowManager::GetDisplay()),
		VisualInfo->visual, AllocNone);

	SetAttributes.event_mask = ExposureMask | KeyPressMask 
	   	| KeyReleaseMask | MotionNotify | ButtonPressMask | ButtonReleaseMask
	   	| FocusIn | FocusOut | Button1MotionMask | Button2MotionMask | Button3MotionMask | 
		Button4MotionMask | Button5MotionMask | PointerMotionMask | FocusChangeMask
		| VisibilityChangeMask | PropertyChangeMask | SubstructureNotifyMask;

	WindowHandle = XCreateWindow(WindowManager::GetInstance()->m_Display,
		XDefaultRootWindow(WindowManager::GetInstance()->m_Display), 0, 0,
		Resolution[0], Resolution[1],
		0, VisualInfo->depth, InputOutput,
		VisualInfo->visual, CWColormap | CWEventMask,
		&SetAttributes);

	if(!WindowHandle)
	{
		PrintErrorMessage(ERROR_LINUX_CANNOTCREATEWINDOW);
		exit(0);
	}

	XMapWindow(WindowManager::GetDisplay(), WindowHandle);
	XStoreName(WindowManager::GetDisplay(), WindowHandle,
		Name);

	InitializeAtomics();

	XSetWMProtocols(WindowManager::GetDisplay(), WindowHandle, &AtomClose, GL_TRUE);	

	return Linux_InitializeGL();
}
Ejemplo n.º 29
0
static  xrandrt_t *xrandrt_init(const char *display_name)
{
    xrandrt_t *xr;
    int        fd;
    Display   *disp;

    disp = XOpenDisplay(display_name);


    if ((xr = malloc(sizeof(*xr))) == NULL) {
        if (disp != NULL)
            XCloseDisplay(disp);
    }
    else {
        fd = XConnectionNumber(disp);

        memset(xr, 0, sizeof(*xr));
        xr->disp  = disp;
        xr->chan  = g_io_channel_unix_new(fd);
        xr->evsrc = g_io_add_watch(xr->chan, G_IO_IN|G_IO_HUP|G_IO_ERR,
                                   xevent_cb,xr);
        
        printf("videoep: xrandr initialized\n");

        {
            Window root;
            Visual *vis;
            int sno;
            unsigned long wp;
            unsigned long bp;
            Window win;
            int depth;
            XSetWindowAttributes attr;
            unsigned long mask;

            root = XDefaultRootWindow(disp);
            sno = XDefaultScreen(disp);
            vis = XDefaultVisual(disp, sno);
            depth = XDefaultDepth(disp, sno);
            bp  = XBlackPixel(disp, sno);
            wp  = XWhitePixel(disp, sno);

            mask = CWBackPixel | CWBorderPixel | CWEventMask;
            attr.background_pixel = wp;
            attr.border_pixel = bp;
            attr.event_mask = ButtonPressMask | FocusChangeMask;

            win = XCreateWindow(disp, root, 50,50, 400,300, 1, depth,
                                InputOutput, vis, mask, &attr);
            XMapWindow(disp,win);            
            XFlush(disp);
        }
    }

    return xr;
}
void XLibWindowManagerAdapterPrivate::dispatchOpenWindowEvents()
{
    Window root = XDefaultRootWindow(m_display);
    handleCreatedWindow(root);

    getClients(&m_clients, &m_numberOfClients);
    for (unsigned long i = 0; i < m_numberOfClients; ++i) {
        handleCreatedWindow(m_clients[i]);
    }
}