Exemplo n.º 1
0
void TopWindow::GuiPlatformConstruct()
{
	size_hints = XAllocSizeHints();
	wm_hints = XAllocWMHints();
	class_hint = XAllocClassHint();
	topmost = false;
}
/* Returns a pointer to the profile of the currently selected
 * window, or defaultProfile if there is no specific profile for it or the window is invalid. */
char* getWindowClass(Window w) {
	char * result = NULL;
	if (w != None) {

		XClassHint* classHint = XAllocClassHint();

		/* Read WM_CLASS member */
		if (XGetClassHint(display, w, classHint)) {

			if(classHint->res_class != NULL) {

				result = malloc((strlen(classHint->res_name) + 1) * sizeof(char));
				if(result != NULL) {
					strcpy(result, classHint->res_name);
				}
				XFree(classHint->res_class);

			}

			if(classHint->res_name != NULL) XFree(classHint->res_name);
			XFree(classHint);
		}
	}

	return result;

}
Exemplo n.º 3
0
/**
 * @brief Set basic properties on a window.
 */
void
wm_wid_set_info(session_t *ps, Window wid, const char *name,
		Atom window_type) {
	// Set window name
	{
		char *textcpy = mstrjoin("skippy-xd ", name);
		{
			XTextProperty text_prop = { };
			if (Success == XmbTextListToTextProperty(ps->dpy, &textcpy, 1,
						XStdICCTextStyle, &text_prop))
				XSetWMName(ps->dpy, wid, &text_prop);
			sxfree(text_prop.value);
		}
		wm_wid_set_prop_utf8(ps, wid, _NET_WM_NAME, textcpy);
		free(textcpy);
	}

	// Set window class
	{
		XClassHint *classh = allocchk(XAllocClassHint());
		classh->res_name = "skippy-xd";
		classh->res_class = "skippy-xd";
		XSetClassHint(ps->dpy, wid, classh);
		XFree(classh);
	}

	// Set window type
	{
		if (!window_type)
			window_type = _NET_WM_WINDOW_TYPE_NORMAL;
		long val = window_type;
		XChangeProperty(ps->dpy, wid, _NET_WM_WINDOW_TYPE, XA_ATOM, 32,
				PropModeReplace, (unsigned char *) &val, 1);
	}
}
Exemplo n.º 4
0
static void xdpy_set_window_title_default(ALLEGRO_DISPLAY *display, const char *title)
{
   ALLEGRO_SYSTEM_XGLX *system = (ALLEGRO_SYSTEM_XGLX *)al_get_system_driver();
   ALLEGRO_DISPLAY_XGLX *glx = (ALLEGRO_DISPLAY_XGLX *)display;

   {
      Atom WM_NAME = XInternAtom(system->x11display, "WM_NAME", False);
      Atom _NET_WM_NAME = XInternAtom(system->x11display, "_NET_WM_NAME", False);
      char *list[1] = { (char *) title };
      XTextProperty property;

      Xutf8TextListToTextProperty(system->x11display, list, 1, XUTF8StringStyle,
         &property);
      XSetTextProperty(system->x11display, glx->window, &property, WM_NAME);
      XSetTextProperty(system->x11display, glx->window, &property, _NET_WM_NAME);
      XSetTextProperty(system->x11display, glx->window, &property, XA_WM_NAME);
      XFree(property.value);
   }
   {
      XClassHint *hint = XAllocClassHint();
      if (hint) {
         ALLEGRO_PATH *exepath = al_get_standard_path(ALLEGRO_EXENAME_PATH);
         // hint doesn't use a const char*, so we use strdup to create a non const string
         hint->res_name = strdup(al_get_path_basename(exepath));
         hint->res_class = strdup(al_get_path_basename(exepath));
         XSetClassHint(system->x11display, glx->window, hint);
         free(hint->res_name);
         free(hint->res_class);
         XFree(hint);
         al_destroy_path(exepath);
      }
   }
}
Exemplo n.º 5
0
static void InternalLinkScreenAndGo( const char * WindowName )
{
	XGetWindowAttributes( CNFGDisplay, CNFGWindow, &CNFGWinAtt );

	XGetClassHint( CNFGDisplay, CNFGWindow, CNFGClassHint );
	if (!CNFGClassHint) {
		CNFGClassHint = XAllocClassHint();
		if (CNFGClassHint) {
			CNFGClassHint->res_name = "cnping";
			CNFGClassHint->res_class = "cnping";
			XSetClassHint( CNFGDisplay, CNFGWindow, CNFGClassHint );
		} else {
			fprintf( stderr, "Failed to allocate XClassHint!\n" );
		}
	} else {
		fprintf( stderr, "Pre-existing XClassHint\n" );
	}

	XSelectInput (CNFGDisplay, CNFGWindow, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | ExposureMask | PointerMotionMask );
	XSetStandardProperties( CNFGDisplay, CNFGWindow, WindowName, WindowName, None, NULL, 0, NULL );

	CNFGWindowGC = XCreateGC(CNFGDisplay, CNFGWindow, 0, 0);

	CNFGPixmap = XCreatePixmap( CNFGDisplay, CNFGWindow, CNFGWinAtt.width, CNFGWinAtt.height, CNFGWinAtt.depth );
	CNFGGC = XCreateGC(CNFGDisplay, CNFGPixmap, 0, 0);
}
Exemplo n.º 6
0
QString GestureHandler::getAppClass(Window window) const
{
    XClassHint *classHint = XAllocClassHint();
    XGetClassHint(QX11Info::display(), window, classHint);
    QString ret = classHint->res_class;
    XFree(classHint->res_class);
    XFree(classHint->res_name);
    return ret;
}
Exemplo n.º 7
0
static void set_wm_class(void)
{
	XClassHint *classhint = XAllocClassHint();

	classhint->res_name = (char *)"jgmenu";
	classhint->res_class = (char *)"jgmenu";
	XSetClassHint(ui->dpy, ui->w[ui->cur].win, classhint);
	XFree(classhint);
}
Exemplo n.º 8
0
XClassHint *
count_xallocclasshint(const char *fname, int line)
{
    XClassHint *wmclass ;
    wmclass = XAllocClassHint();
    if( wmclass != NULL )
        count_alloc (fname, line, (void *)wmclass, sizeof(XClassHint), C_XMEM | C_XALLOCCLASSHINT );
    return wmclass;
}
Exemplo n.º 9
0
bool X11Helper::MakeWindow( Window &win, int screenNum, int depth, Visual *visual, int width, int height, bool overrideRedirect )
{
	if( !Dpy )
		return false;

	XSetWindowAttributes winAttribs;
	winAttribs.border_pixel = 0;
	winAttribs.event_mask = 0L;

	if( win )
	{
		// Preserve the event mask.
		XWindowAttributes attribs;
		XGetWindowAttributes( Dpy, win, &attribs );
		winAttribs.event_mask = attribs.your_event_mask;
		XDestroyWindow( Dpy, win );
	}
	// XXX: Error catching/handling?
	winAttribs.colormap = XCreateColormap( Dpy, RootWindow(Dpy, screenNum), visual, AllocNone );
	unsigned long mask = CWBorderPixel | CWColormap | CWEventMask;

	if( overrideRedirect )
	{
		winAttribs.override_redirect = True;
		mask |= CWOverrideRedirect;
	}
	win = XCreateWindow( Dpy, RootWindow(Dpy, screenNum), 0, 0, width, height, 0,
			     depth, InputOutput, visual, mask, &winAttribs );
	if( win == None )
		return false;

	XClassHint *hint = XAllocClassHint();
	if ( hint == nullptr ) {
		LOG->Warn("Could not set class hint for X11 Window");
	} else {
		hint->res_name   = (char*)g_XWMName.Get().c_str();
		hint->res_class  = (char*)PRODUCT_FAMILY;
		XSetClassHint(Dpy, win, hint);
		XFree(hint);
	}

	// Hide the mouse cursor in certain situations.
    if( !PREFSMAN->m_bShowMouseCursor )
	{
		const char pBlank[] = { 0,0,0,0,0,0,0,0 };
		Pixmap BlankBitmap = XCreateBitmapFromData( Dpy, win, pBlank, 8, 8 );

		XColor black = { 0, 0, 0, 0, 0, 0 };
		Cursor pBlankPointer = XCreatePixmapCursor( Dpy, BlankBitmap, BlankBitmap, &black, &black, 0, 0 );
		XFreePixmap( Dpy, BlankBitmap );

		XDefineCursor( Dpy, win, pBlankPointer );
		XFreeCursor( Dpy, pBlankPointer );
	}

	return true;
}
static void setClassHint(Display *disp, Window window, jlong wm_name, jlong wm_class) {
	XClassHint* hint = XAllocClassHint();
	
	hint->res_name = (char *)(intptr_t)wm_name;
	hint->res_class = (char *)(intptr_t)wm_class;
	
	XSetClassHint(disp, window, hint);
	
	XFree(hint);
}
Exemplo n.º 11
0
static void set_class_hint(Display *p_display, Window p_window) {
	XClassHint *classHint;

	/* set the name and class hints for the window manager to use */
	classHint = XAllocClassHint();
	if (classHint) {
		classHint->res_name = (char *)"Godot_Engine";
		classHint->res_class = (char *)"Godot";
	}
	XSetClassHint(p_display, p_window, classHint);
	XFree(classHint);
}
Exemplo n.º 12
0
void
x_window_rep::set_hints (int min_w, int min_h, int max_w, int max_h) {
  XSizeHints* size_hints;
  XWMHints*   wm_hints;
  XClassHint* class_hints;
  ASSERT (size_hints= XAllocSizeHints (), "out of memory (X server)");
  ASSERT (wm_hints= XAllocWMHints (), "out of memory (X server)");
  ASSERT (class_hints= XAllocClassHint (), "out of memory (X server)");

  XTextProperty Window_Name;
  XTextProperty Icon_Name;
  ASSERT (XStringListToTextProperty (&name, 1, &Window_Name) != 0,
	  "out of memory (X server)");
  ASSERT (XStringListToTextProperty (&name, 1, &Icon_Name) != 0,
	  "out of memory (X server)");

  // time_t start_1= texmacs_time ();
  Pixmap pm= retrieve_pixmap (load_xpm ("TeXmacs.xpm"));
  // cout << "Getting pixmap required " << (texmacs_time ()-start_1) << " ms\n";

  // time_t start_2= texmacs_time ();
  size_hints->flags       = PPosition | PSize | PMinSize | PMaxSize;
  size_hints->min_width   = min_w;
  size_hints->min_height  = min_h;
  size_hints->max_width   = max_w;
  size_hints->max_height  = max_h;
  wm_hints->initial_state = NormalState;
  wm_hints->input         = true;
  wm_hints->icon_pixmap   = pm;
  wm_hints->flags         = StateHint | IconPixmapHint | InputHint;
  class_hints->res_name   = name;
  class_hints->res_class  = name;

  XSetWMProperties (
    dpy,
    win,
    &Window_Name,
    &Icon_Name,
    gui->argv,
    gui->argc,
    size_hints,
    wm_hints,
    class_hints
  );

  XFree(size_hints);
  XFree(wm_hints);
  XFree(class_hints);
  XFree(Window_Name.value);
  XFree(Icon_Name.value);
  // cout << "Setting hints required " << (texmacs_time ()-start_2) << " ms\n";
}
Exemplo n.º 13
0
void init_client(WM* wm, Window w, Client* c) {
  char* name;
  XClassHint* ch = XAllocClassHint();
  memset(c,0,sizeof(Client));
  c->win = w;
  c->manager = wm;
  c->x =c->y = 0;
  c->w = c->h = 10;

  if (XGetClassHint(wm->dpy, w, ch)) {
    sprintf(c->class,"%s",ch->res_class);
    if (ch->res_class) XFree(ch->res_class);
    if (ch->res_name) XFree(ch->res_name);
  }
Exemplo n.º 14
0
xfWindow* xf_CreateDesktopWindow(xfInfo* xfi, char* name, int width, int height, boolean decorations)
{
	xfWindow* window;

	window = (xfWindow*) xzalloc(sizeof(xfWindow));

	if (window != NULL)
	{
		int input_mask;
		XClassHint* class_hints;

		window->width = width;
		window->height = height;
		window->fullscreen = False;
		window->decorations = decorations;

		window->handle = XCreateWindow(xfi->display, RootWindowOfScreen(xfi->screen),
			xfi->workArea.x, xfi->workArea.y, xfi->width, xfi->height, 0, xfi->depth, InputOutput, xfi->visual,
			CWBackPixel | CWBackingStore | CWOverrideRedirect | CWColormap |
			CWBorderPixel, &xfi->attribs);

		class_hints = XAllocClassHint();

		if (class_hints != NULL)
		{
			class_hints->res_name = "xfreerdp";
			class_hints->res_class = "xfreerdp";
			XSetClassHint(xfi->display, window->handle, class_hints);
			XFree(class_hints);
		}

		xf_ResizeDesktopWindow(xfi, window, width, height);
		xf_SetWindowDecorations(xfi, window, decorations);

		input_mask =
			KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
			VisibilityChangeMask | FocusChangeMask | StructureNotifyMask |
			PointerMotionMask | ExposureMask | PropertyChangeMask;

		if (xfi->grab_keyboard)
			input_mask |= EnterWindowMask | LeaveWindowMask;

		XSelectInput(xfi->display, window->handle, input_mask);
		XMapWindow(xfi->display, window->handle);
	}

	XStoreName(xfi->display, window->handle, name);

	return window;
}
Exemplo n.º 15
0
void hook_init() {
    g_event_window = XCreateSimpleWindow(g_display, g_root, 42, 42, 42, 42, 0, 0, 0);
    // set wm_class for window
    XClassHint *hint = XAllocClassHint();
    hint->res_name = (char*)HERBST_HOOK_CLASS;
    hint->res_class = (char*)HERBST_HOOK_CLASS;
    XSetClassHint(g_display, g_event_window, hint);
    XFree(hint);
    // ignore all events for this window
    XSelectInput(g_display, g_event_window, 0l);
    // set its window id in root window
    XChangeProperty(g_display, g_root, ATOM(HERBST_HOOK_WIN_ID_ATOM),
        XA_ATOM, 32, PropModeReplace, (unsigned char*)&g_event_window, 1);
}
Exemplo n.º 16
0
xfWindow* xf_CreateWindow(xfInfo* xfi, rdpWindow* wnd, int x, int y, int width, int height, uint32 id)
{
	xfWindow* window;

	window = (xfWindow*) xzalloc(sizeof(xfWindow));

	if ((width * height) < 1)
		return NULL;

	xf_FixWindowCoordinates(xfi, &x, &y, &width, &height);

	window->left = x;
	window->top = y;
	window->right = x + width - 1;
	window->bottom = y + height - 1;
	window->width = width;
	window->height = height;

	if (window != NULL)
	{
		XGCValues gcv;
		int input_mask;
		XClassHint* class_hints;

		window->decorations = False;
		window->fullscreen = False;
		window->window = wnd;
		window->localMoveSize = False;

		window->handle = XCreateWindow(xfi->display, RootWindowOfScreen(xfi->screen),
			x, y, window->width, window->height, 0, xfi->depth, InputOutput, xfi->visual,
			CWBackPixel | CWBackingStore | CWOverrideRedirect | CWColormap |
			CWBorderPixel, &xfi->attribs);

		xf_SetWindowDecorations(xfi, window, window->decorations);

		class_hints = XAllocClassHint();

		if (class_hints != NULL)
		{
			char* class;
			class = xmalloc(sizeof(rail_window_class));
			snprintf(class, sizeof(rail_window_class), "RAIL:%08X", id);
			class_hints->res_name = "RAIL";
			class_hints->res_class = class;
			XSetClassHint(xfi->display, window->handle, class_hints);
			XFree(class_hints);
			xfree(class);
		}
Exemplo n.º 17
0
void OS_X11::set_context(int p_context) {

	XClassHint* classHint = NULL;
	classHint = XAllocClassHint();
	if (classHint) {

		if (p_context == CONTEXT_EDITOR)
			classHint->res_name = (char *)"Godot_Editor";
		if (p_context == CONTEXT_PROJECTMAN)
			classHint->res_name = (char *)"Godot_ProjectList";
		classHint->res_class = (char *)"Godot";
		XSetClassHint(x11_display, x11_window, classHint);
		XFree(classHint);
	}
}
Exemplo n.º 18
0
void setXorgClassHint(const video::SExposedVideoData &video_data,
	const std::string &name)
{
#ifdef XORG_USED
	if (video_data.OpenGLLinux.X11Display == NULL)
		return;

	XClassHint *classhint = XAllocClassHint();
	classhint->res_name  = (char *)name.c_str();
	classhint->res_class = (char *)name.c_str();

	XSetClassHint((Display *)video_data.OpenGLLinux.X11Display,
		video_data.OpenGLLinux.X11Window, classhint);
	XFree(classhint);
#endif
}
Exemplo n.º 19
0
void set_wm_class(window *win, wm_class_context *ctx)
{
    XClassHint *hint = XAllocClassHint();

    if (hint == NULL) {
        print_error("system error: XAllocClassHint");
        exit(EXIT_FAILURE);
    }

    hint->res_name = ctx->name;
    hint->res_class = ctx->class;
    XSetClassHint(win->display, win->window, hint);

    *(ctx->done) += 1;

    XFree(hint);
}
Exemplo n.º 20
0
/**
 * Set a window name & class.
 * @param win The window
 * @param n The name string
 * @param c The class string
 *
 * Set a window name * class
 */
EAPI void
ecore_x_icccm_name_class_set(Ecore_X_Window win,
                             const char *n,
                             const char *c)
{
   XClassHint *xch;

   xch = XAllocClassHint();
   if (!xch)
     return;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   xch->res_name = (char *)n;
   xch->res_class = (char *)c;
   XSetClassHint(_ecore_x_disp, win, xch);
   if (_ecore_xlib_sync) ecore_x_sync();
   XFree(xch);
}
Exemplo n.º 21
0
XClassHint* xobj_get_wm_class(struct _xobj *p)
{
	Window window = p->find_win_byatom(p, "WM_CLASS");
	if (window == None)
		window = p->xWindow;

	XClassHint *wm_class = XAllocClassHint();
	if (!XGetClassHint(p->xDisplay, window, wm_class))
	{
		log_message(ERROR, "Can't get WM_CLASS");

		XFree(wm_class->res_class);
		XFree(wm_class->res_name);
		XFree(wm_class);
		return NULL;
	}
	return wm_class;
}
Exemplo n.º 22
0
char* get_wm_class_name(Window window)
{
    if (window == None)
        return NULL;

    Window named_window = find_window_with_atom(window, XInternAtom(main_window->display, "WM_CLASS", True));
    if (named_window == None)
    {

        named_window = find_window_with_atom(window, XInternAtom(main_window->display, "WM_NAME", True));

        if (named_window == None)
            return NULL;

        Atom type;
        int size;
        long nitems;

        Atom request = XInternAtom(main_window->display, "WM_NAME", False);
        unsigned char *data = get_win_prop(named_window, request, &nitems, &type, &size);

        if (nitems > 0)
            return (char *)data;

        return NULL;
    }

    XClassHint *wm_class = XAllocClassHint();

    if (!XGetClassHint(main_window->display, named_window, wm_class))
    {
        XFree(wm_class);
        return NULL;
    }

    char *string = strdup(wm_class->res_class);

    XFree(wm_class->res_class);
    XFree(wm_class->res_name);
    XFree(wm_class);

    return string;
}
Exemplo n.º 23
0
bool RotationDaemon::checkApplicationBlacklistToForceLandscape()
{
    // Find active window
    Window activeWindow = activeWindowId();

    // Now find what it is called
    XClassHint *xh = XAllocClassHint();
    //Status s = 
    XGetClassHint(QX11Info::display(), activeWindow, xh);

    qDebug() << "Active window is " << xh->res_name << xh->res_class;

    // clean up
    XFree(xh->res_name);
    XFree(xh->res_class);
    XFree(xh);

    return false;
}
Exemplo n.º 24
0
int PropGetWMClass(Window window, char **wm_class, char **wm_instance)
{
	XClassHint *class_hint;

	class_hint = XAllocClassHint();
	if (XGetClassHint(dpy, window, class_hint) == 0) {
		*wm_class = strdup("default");
		*wm_instance = strdup("default");
		XFree(class_hint);
		return False;
	}
	*wm_instance = strdup(class_hint->res_name);
	*wm_class = strdup(class_hint->res_class);

	XFree(class_hint->res_name);
	XFree(class_hint->res_class);
	XFree(class_hint);

	return True;
}
Exemplo n.º 25
0
Arquivo: aosd.c Projeto: Walms/libaosd
void
aosd_set_name(Aosd* aosd, XClassHint* name)
{
  Bool flag = False;

  if (aosd == NULL)
    return;

  if (name == NULL)
  {
    name = XAllocClassHint();
    name->res_name = "libaosd";
    name->res_class = "Atheme";
    flag = True;
  }

  XSetClassHint(aosd->display, aosd->win, name);

  if (flag)
    XFree(name);
}
void XLibWindowManagerAdapterPrivate::handleCreatedWindow(Window window)
{
    QString targetName;
    if (window != XDefaultRootWindow(m_display)) {
        XClassHint *classHint = XAllocClassHint();
        XGetClassHint(m_display, window, classHint);
        targetName = QString(classHint->res_class);
        XFree(classHint->res_name);
        XFree(classHint->res_class);
        XFree(classHint);
    }
    if (q_ptr->m_listener) {
        bool grabTouches = true;
        qDebug() << "Created: " << window << " " << targetName;
        q_ptr->m_listener->onWindowCreated(window, targetName, &grabTouches);
        if (grabTouches) {
            XIGrabTouchBegin(m_display, XIAllMasterDevices, window, 0,
                             &m_mask, 1, &m_mods);
        }
    }
}
Exemplo n.º 27
0
bool hc_create_client_window(HCConnection* con) {
    if (con->client_window) {
        return true;
    }
    /* ensure that classhint and the command is set when the hlwm-server
     * receives the XCreateWindowEvent */
    XGrabServer(con->display);
    // create window
    con->client_window = XCreateSimpleWindow(con->display, con->root,
                                             42, 42, 42, 42, 0, 0, 0);
    // set wm_class for window
    XClassHint *hint = XAllocClassHint();
    hint->res_name = HERBST_IPC_CLASS;
    hint->res_class = HERBST_IPC_CLASS;
    XSetClassHint(con->display, con->client_window, hint);
    XFree(hint);
    XSelectInput(con->display, con->client_window, PropertyChangeMask);
    /* the window has been initialized properly, now allow the server to
     * receive the event for it */
    XUngrabServer(con->display);
    return true;
}
Exemplo n.º 28
0
void
setup_window(void)
{
   XSetWindowAttributes att;
   XClassHint *xch;

   att.background_pixmap = None;
   att.colormap = DefaultColormap(disp, DefaultScreen(disp));
   att.border_pixel = 0;
   att.event_mask = 
     ButtonPressMask | 
     ButtonReleaseMask |
     EnterWindowMask |
     LeaveWindowMask |
     PointerMotionMask | 
     ExposureMask | 
     StructureNotifyMask | 
     KeyPressMask | 
     KeyReleaseMask;
   win = XCreateWindow(disp,
		       RootWindow(disp, DefaultScreen(disp)),
		       0, 0, win_w, win_h, 0,
		       DefaultDepth(disp, DefaultScreen(disp)),
		       InputOutput,
		       DefaultVisual(disp, DefaultScreen(disp)),
		       CWColormap | CWBorderPixel | CWEventMask | CWBackPixmap,
		       &att);
   XStoreName(disp, win, "Render Test Program");
   xch = XAllocClassHint();
   xch->res_name = "Main";
   xch->res_class = "Render_Demo";
   XSetClassHint(disp, win, xch);
   XFree(xch);
   XMapWindow(disp, win);
   XSync(disp, False);
   usleep(200000);
   XSync(disp, False);
}
Exemplo n.º 29
0
EIF_BOOLEAN basic_gui_initialize(EIF_POINTER display_name,
				 EIF_BOOLEAN sync,
				 EIF_BOOLEAN no_xshm,
				 EIF_POINTER name,
				 EIF_POINTER progclass,
				 EIF_POINTER gxid_host,
				 EIF_INTEGER gxid_port) {
  /*
     Called only once at the very beginning to initialize the Window Manager.
  */
  int synchronize = sync;
  XKeyboardState keyboard_state;
  XClassHint *class_hint;
  X_GETTIMEOFDAY (&start);
  gdk_display_name = display_name;
  XSetErrorHandler (gui_x_error);
  XSetIOErrorHandler (gui_x_io_error);
  g_get_prgname = name;
  gdk_display_name = display_name;
  if (no_xshm) gdk_use_xshm = FALSE;
  gdk_progclass = progclass;
#ifdef XINPUT_GXI
  gdk_input_gxid_host = gxid_host;
  gdk_input_gxid_port = gxid_port;
#endif

  gdk_display = XOpenDisplay (gdk_display_name);
  if (!gdk_display)
    return FALSE;

  if (synchronize)
    XSynchronize (gdk_display, True);

  gdk_screen = DefaultScreen (gdk_display);

  gdk_root_window = RootWindow (gdk_display, gdk_screen);

  gdk_leader_window = XCreateSimpleWindow(gdk_display, gdk_root_window,
					  10, 10, 10, 10, 0, 0 , 0);
  class_hint = XAllocClassHint();
  class_hint->res_name = g_get_prgname;
  if (gdk_progclass == NULL) {
    gdk_progclass = g_get_prgname;
  }
  class_hint->res_class = gdk_progclass;
  XmbSetWMProperties (gdk_display, gdk_leader_window,
		      NULL, NULL, se_argv, se_argc,
		      NULL, NULL, class_hint);
  XFree (class_hint);
  gdk_wm_delete_window = XInternAtom (gdk_display, "WM_DELETE_WINDOW", False);
  gdk_wm_take_focus = XInternAtom (gdk_display, "WM_TAKE_FOCUS", False);
  gdk_wm_protocols = XInternAtom (gdk_display, "WM_PROTOCOLS", False);
  gdk_wm_window_protocols[0] = gdk_wm_delete_window;
  gdk_wm_window_protocols[1] = gdk_wm_take_focus;
  gdk_selection_property = XInternAtom (gdk_display, "GDK_SELECTION", False);

  XGetKeyboardControl (gdk_display, &keyboard_state);

  autorepeat = keyboard_state.global_auto_repeat;

  timer.tv_sec = 0;
  timer.tv_usec = 0;
  timerp = NULL;

  /* @@@ Keep This ?:
     gdk_events_init ();
     gdk_visual_init ();
     gdk_window_init ();
     gdk_image_init ();
     gdk_input_init ();
     gdk_dnd_init ();

#ifdef USE_XIM
  gdk_im_open ();
#endif
  */
  return 1;
}
Exemplo n.º 30
0
/* Returns the active top-level window. A top-level window is one that has WM_CLASS set.
 * May also return None. */
Window getCurrentWindow() {

	/* First get the window that has the input focus */
	Window currentWindow;
	int revert;
	XGetInputFocus(display, &currentWindow, &revert);

	if (currentWindow == None) {
		//if(debugMode) printf("Leave getCurrentWindow\n");
		return currentWindow;
	}

	/* Now go through parent windows until we find one with WM_CLASS set. */


	XClassHint* classHint = XAllocClassHint();
	if(classHint == NULL) {
		if(debugMode) printf("Couldn't allocate class hint!!\n");
		return None;
	}

	int i = 0;
	while (1) {
		//if(debugMode) printf("in Loop\n");
		i++;
		if(i >= 5) {
			if(debugMode) printf("Too many iterations in getCurrentWindow\n");
			XFree(classHint);
			//if(debugMode) printf("Leave getCurrentWindow\n");
			return None;
		}
		if (currentWindow == root || currentWindow == None) {
			//if(debugMode) printf("Reached root!\n");
			/* No top-level window available. Should never happen. */
			XFree(classHint);
			//if(debugMode) printf("Leave getCurrentWindow\n");
			return currentWindow;
		}

		//if(debugMode) printf("Call XGetClassHint!\n");
		if (XGetClassHint(display, currentWindow, classHint) == 0) {
			//if(debugMode) printf("Has no Class!\n");
			/* Has no WM_CLASS, thus no top-level window */
			Window parent = getParentWindow(currentWindow);

			if(parent == None || currentWindow == parent) {
				/* something wrong */
				XFree(classHint);
				return currentWindow;
			}
			/* Continue with parent until we find WM_CLASS */
			currentWindow = parent;
		} else {
			//if(debugMode) printf("Clean up class name!\n");
			if(classHint->res_class != NULL) XFree(classHint->res_class);
			if(classHint->res_name != NULL) XFree(classHint->res_name);
			XFree(classHint);
			//if(debugMode) printf("Leave getCurrentWindow\n");
			return currentWindow;
		}
	}
}