int main () {
  Display   *display;
  Window     main, grouptran, child, group;
  XEvent     report;
  XWMHints  *wmhints;

  display = XOpenDisplay(NULL);

  if (display == NULL) {
    fprintf(stderr, "couldn't connect to X server :0\n");
    return 0;
  }

  group = XCreateWindow(display, RootWindow(display, 0),
                        0,0,1,1, 10, CopyFromParent, CopyFromParent,
			 CopyFromParent, 0, 0);

  main = XCreateWindow(display, RootWindow(display, 0),
                      0,0,100,100, 10, CopyFromParent, CopyFromParent,
			 CopyFromParent, 0, 0);
  grouptran = XCreateWindow(display, RootWindow(display, 0),
                            10,10,80,180, 10, CopyFromParent, CopyFromParent,
                            CopyFromParent, 0, 0);
  child = XCreateWindow(display, RootWindow(display, 0),
                        20,20,60,60, 10, CopyFromParent, CopyFromParent,
                        CopyFromParent, 0, 0);

  XSetWindowBackground(display,main,WhitePixel(display,0));
  XSetWindowBackground(display,grouptran,BlackPixel(display,0));
  XSetWindowBackground(display,child,WhitePixel(display,0));

  XSetTransientForHint(display, grouptran, RootWindow(display,0));
  XSetTransientForHint(display, child, grouptran);

  wmhints = XAllocWMHints();

  wmhints->flags = WindowGroupHint;
  wmhints->window_group = group;

  XSetWMHints(display, main, wmhints);
  XSetWMHints(display, grouptran, wmhints);
  XSetWMHints(display, child, wmhints);

  XFree(wmhints);

  XMapWindow(display, main);
  XMapWindow(display, grouptran);
  XMapWindow(display, child);
  XFlush(display);

  while (1) {
    XNextEvent(display, &report);
  }

  return 1;
}
Example #2
0
void xisCreateSimple()
{
    XWMHints wm_hints;
    XSizeHints size_hints;

    xisDummyFocusWindow =
               XCreateSimpleWindow( xisDisplay, xisRootWindow,
                                    DisplayWidth(xisDisplay,xisScreen) - 50,
                                    DisplayHeight(xisDisplay,xisScreen) - 50,
                                    50,50,2,BlackPixel(xisDisplay,xisScreen),
                                    WhitePixel(xisDisplay,xisScreen));

    wm_hints.flags = (InputHint | StateHint);
    wm_hints.input = False;
    wm_hints.initial_state = NormalState;
    XSetWMHints(xisDisplay,xisDummyFocusWindow,&wm_hints);
    size_hints.flags = (USPosition | USSize);
    size_hints.x = DisplayWidth(xisDisplay,xisScreen)-50;
    size_hints.y = DisplayHeight(xisDisplay,xisScreen)-50;
    size_hints.width = 50;
    size_hints.height = 50;
    XSetWMNormalHints(xisDisplay,xisDummyFocusWindow,&size_hints);
    XMapWindow(xisDisplay,xisDummyFocusWindow);

} /* End xisCreateSimple() */
Example #3
0
GtkWidget *create_main_dockapp_icon_window
		(GtkWidget *mw,
		unsigned int s)
{
	GtkWidget *dockappbox; // This will become icon box
	Window xmw;
	XWMHints *wm_hints;

	xmw = GDK_WINDOW_XWINDOW(mw->window);

	dockappbox = gtk_event_box_new();
	gtk_widget_set_usize(dockappbox, s, s);
	gtk_container_add (GTK_CONTAINER (mw), dockappbox);
	gtk_widget_realize(dockappbox);

	// Time for game with Xlib
	wm_hints = XAllocWMHints();
	wm_hints->window_group = xmw;
	wm_hints->icon_window = GDK_WINDOW_XWINDOW(dockappbox->window);
	wm_hints->icon_x = 0;
	wm_hints->icon_y = 0;
	wm_hints->initial_state = WithdrawnState;
	wm_hints->flags = StateHint |
		IconPositionHint |
		WindowGroupHint |
		IconWindowHint;

	XSetWMHints(GDK_DISPLAY(), xmw, wm_hints);

	XFree(wm_hints);

	return dockappbox;
} // end create_main_dockapp_icon_window
Example #4
0
void
SplashCreateWindow(Splash * splash) {
    XSizeHints sizeHints;

    XSetWindowAttributes attr;

    attr.backing_store = NotUseful;
    attr.colormap = XDefaultColormapOfScreen(splash->screen);
    attr.save_under = True;
    attr.cursor = splash->cursor = XCreateFontCursor(splash->display, XC_watch);
    attr.event_mask = ExposureMask;

    SplashCenter(splash);

    splash->window = XCreateWindow(splash->display, XRootWindowOfScreen(splash->screen),
        splash->x, splash->y, splash->width, splash->height, 0, CopyFromParent,
        InputOutput, CopyFromParent, CWColormap | CWBackingStore | CWSaveUnder | CWCursor | CWEventMask,
        &attr);
    SplashUpdateSizeHints(splash);


    splash->wmHints = XAllocWMHints();
    if (splash->wmHints) {
        splash->wmHints->flags = InputHint | StateHint;
        splash->wmHints->input = False;
        splash->wmHints->initial_state = NormalState;
        XSetWMHints(splash->display, splash->window, splash->wmHints);
    }
}
Example #5
0
static void
newwin(void *foo, int item, Time time)
{
    Window win;
    XClassHint classhint;
    char title[100];

    win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy),
                              0, 0, 200, 100, 0, 0, 0);
    prots[0] = delete_win;
    XSetWMProtocols(dpy, win, prots, 1);
    sprintf(title, "Notify Test Window");
    XStoreName(dpy, win, title);

    /* set class hint */
    classhint.res_name = "notest";
    classhint.res_class = "Notest";
    XSetClassHint(dpy, win, &classhint);

    hints = XAllocWMHints();
    /* set window group leader */
    hints->window_group = leader;
    hints->flags = WindowGroupHint;
    XSetWMHints(dpy, win, hints);

    WMAppAddWindow(app, win);
    XMapWindow(dpy, win);
}
Example #6
0
void CreateDock(int argc, char *argv[])    /* this part comes from http://www.linuxmag-france.org/ */
{
   Window root;
   XWMHints wmHints;
   XSizeHints sizeHints;
   XClassHint classHint;
   Pixmap pixmask;
   unsigned long p_blanc;
   unsigned long p_noir;
   unsigned int borderWidth = 2;
   char *wname = argv[0] ;

   dpy = XOpenDisplay(NULL) ;

   if(dpy == NULL)
	  {
	     fprintf(stderr, "Can't open display\n") ;
	     exit(1) ;
	  }

   root = RootWindow(dpy,screen);
   p_blanc = WhitePixel(dpy,screen) ;
   p_noir = BlackPixel(dpy,screen) ;
   gc = XDefaultGC(dpy,screen) ;
   XSetForeground(dpy, gc, p_noir);
   XSetBackground(dpy, gc,p_noir);

   sizeHints.x = 0 ;
   sizeHints.y = 0 ;
   sizeHints.width = 64 ;
   sizeHints.height = 64 ;

   win = XCreateSimpleWindow(dpy,root,sizeHints.x,sizeHints.y , sizeHints.width, sizeHints.height, borderWidth, p_noir,p_noir) ;
   iconWin = XCreateSimpleWindow(dpy,root,sizeHints.x,sizeHints.y,sizeHints.width, sizeHints.height, borderWidth, p_noir,p_noir ) ;

   sizeHints.flags = USSize | USPosition ;
   XSetWMNormalHints(dpy,win,&sizeHints) ;
   wmHints.initial_state = WithdrawnState ;
   wmHints.icon_window = iconWin ;
   wmHints.icon_x = sizeHints.x ;
   wmHints.icon_y = sizeHints.y ;
   wmHints.window_group = win ;
   wmHints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint ;
   XSetWMHints(dpy, win, &wmHints) ;
   classHint.res_name = wname ;
   classHint.res_class = wname ;

   XSetClassHint(dpy, win, &classHint) ;
   XSetCommand(dpy,win, argv, argc) ;

   pixmask = XCreateBitmapFromData(dpy,win,fond_bits, fond_width, fond_height) ;
   XShapeCombineMask(dpy,win,ShapeBounding,0,0,pixmask,ShapeSet) ;
   XShapeCombineMask(dpy,iconWin,ShapeBounding, 0, 0, pixmask, ShapeSet) ;
   XpmCreatePixmapFromData(dpy,root,wmAppKill_xpm, &XPM, NULL,NULL) ;

   XSelectInput(dpy,win, ExposureMask | ButtonPressMask) ;
   XSelectInput(dpy,iconWin, ExposureMask | ButtonPressMask) ;

   XMapWindow(dpy,win) ;
}
Example #7
0
int
XSetStandardProperties (
    	Display *dpy,
    	Window w,		/* window to decorate */
    	_Xconst char *name,	/* name of application */
    	_Xconst char *icon_string,/* name string for icon */
	Pixmap icon_pixmap,	/* pixmap to use as icon, or None */
    	char **argv,		/* command to be used to restart application */
    	int argc,		/* count of arguments */
    	XSizeHints *hints)	/* size hints for window in its normal state */
{
	XWMHints phints;
	phints.flags = 0;

	if (name != NULL) XStoreName (dpy, w, name);

	if (icon_string != NULL) {
	    XChangeProperty (dpy, w, XA_WM_ICON_NAME, XA_STRING, 8,
		PropModeReplace, (unsigned char *)icon_string, safestrlen(icon_string));
		}

	if (icon_pixmap != None) {
		phints.icon_pixmap = icon_pixmap;
		phints.flags |= IconPixmapHint;
		}
	if (argv != NULL) XSetCommand(dpy, w, argv, argc);

	if (hints != NULL) XSetNormalHints(dpy, w, hints);

	if (phints.flags != 0) XSetWMHints(dpy, w, &phints);

	return 1;
}
Example #8
0
void win::make(win *back,int wx,int wy,int sizex,int sizey)
{
    if (mask == -1) return;
    if (disp == NULL){
        disp = XOpenDisplay(disp_string);
        if (disp == NULL){
            fprintf(stderr, "xlwin: can't open display\n");
            exit(1);
        }
        scr = DefaultScreen(disp);
    }
    x = wx;
    y = wy;
    sx = sizex;
    sy = sizey;
    acm = XInternAtom(disp, "ACM",False);
    Window bk; 
    if (back == NULL) bk = RootWindow(disp,scr);
    else bk = back->w;
    w = XCreateSimpleWindow(disp,bk,x,y,sx,sy,
                            1,BlackPixel(disp,scr),WhitePixel(disp,scr));

    XSelectInput(disp,w,mask);
    mask = -1;

    XWMHints wmhint;
    icon = XCreateBitmapFromData(disp, w, icon_bitmap, 64, 64);
    wmhint.icon_pixmap = icon;
    wmhint.flags = IconPixmapHint;
    XSetWMHints(disp, w, &wmhint);
}
Example #9
0
File: wmurgent.c Project: z24/zwm
//------------------------------------------------------------------------------
int main(int argc,char *argv[])
{
    if (argc!=2)
    {
        fprintf(stderr,"Usage: %s WindowID\n",argv[0]);
        fprintf(stderr,"  WindowID: a hex number, e.x. 0x1\n");
        return 1;
    }

    Window wm;
    sscanf(argv[1],"%x",(unsigned int*)&wm);
    
    Display *dpy = XOpenDisplay(NULL);
    if (dpy==NULL)
        return 1;

    XWMHints *wmh = XGetWMHints(dpy,wm);
    if (wmh)
    {
        wmh->flags |= XUrgencyHint;
        XSetWMHints(dpy,wm,wmh);
        XFree(wmh);
    }

    XCloseDisplay(dpy);

    return 0;
}
Example #10
0
void wsSetIcon(Display *dsp, Window win, guiIcon_t *icon)
{
    XWMHints *wm;
    Atom iconatom;
    CARD32 data[2];

    if (icon->normal) {
        wm = XGetWMHints(dsp, win);

        if (!wm)
            wm = XAllocWMHints();

        wm->icon_pixmap = icon->normal;
        wm->icon_mask   = icon->normal_mask;
        wm->flags      |= IconPixmapHint | IconMaskHint;

        XSetWMHints(dsp, win, wm);
        XFree(wm);
    }

    if (icon->small || icon->normal) {
        iconatom = XInternAtom(dsp, "KWM_WIN_ICON", False);
        data[0]  = (icon->small ? icon->small : icon->normal);
        data[1]  = (icon->small ? icon->small_mask : icon->normal_mask);

        XChangeProperty(dsp, win, iconatom, iconatom, 32, PropModeReplace, (unsigned char *)data, 2);
    }

    if (icon->collection) {
        iconatom = XInternAtom(dsp, "_NET_WM_ICON", False);
        XChangeProperty(dsp, win, iconatom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)icon->collection, icon->collection_size);
    }
}
Example #11
0
// heavily inspired by dwm.c
void client_update_wm_hints(HSClient* client) {
    XWMHints* wmh = XGetWMHints(g_display, client->window);
    if (!wmh) {
        return;
    }

    Window focused_window = frame_focused_window(g_cur_frame);
    if ((focused_window == client->window)
        && wmh->flags & XUrgencyHint) {
        // remove urgency hint if window is focused
        wmh->flags &= ~XUrgencyHint;
        XSetWMHints(g_display, client->window, wmh);
    } else {
        bool newval = (wmh->flags & XUrgencyHint) ? true : false;
        if (newval != client->urgent) {
            client->urgent = newval;
            char winid_str[STRING_BUF_SIZE];
            snprintf(winid_str, STRING_BUF_SIZE, "0x%lx", client->window);
            client_setup_border(client, focused_window == client->window);
            hook_emit_list("urgent", client->urgent ? "on":"off", winid_str, NULL);
            tag_set_flags_dirty();
        }
    }
    if (wmh->flags & InputHint) {
        client->neverfocus = !wmh->input;
    } else {
        client->neverfocus = false;
    }
    XFree(wmh);
}
Example #12
0
static void
urgent(void)
{
	/* This is from deryni/tuomov's urgent_test.c */
	Display *dpy;
	Window id;
	const char *ids;
	XWMHints *hints;

	ids = getenv("WINDOWID");
	if (ids == NULL)
		return;

	id = atoi(ids);

	dpy = XOpenDisplay(NULL);
	if (dpy == NULL)
		return;

	XSetErrorHandler(error_handler);
	hints = XGetWMHints(dpy, id);
	if (hints) {
		hints->flags|=XUrgencyHint;
		XSetWMHints(dpy, id, hints);
		XFree(hints);
	}
	XSetErrorHandler(NULL);

	XFlush(dpy);
	XCloseDisplay(dpy);
}
Example #13
0
static void wxgtk_window_set_urgency_hint (GtkWindow *win,
                                           gboolean setting)
{
#if GTK_CHECK_VERSION(2,7,0)
    if (gtk_check_version(2,7,0) == NULL)
        gtk_window_set_urgency_hint(win, setting);
    else
#endif
    {
#ifdef GDK_WINDOWING_X11
        GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(win));
        wxCHECK_RET(window, "wxgtk_window_set_urgency_hint: GdkWindow not realized");

        Display* dpy = GDK_WINDOW_XDISPLAY(window);
        Window xid = GDK_WINDOW_XID(window);
        XWMHints* wm_hints = XGetWMHints(dpy, xid);

        if (!wm_hints)
            wm_hints = XAllocWMHints();

        if (setting)
            wm_hints->flags |= XUrgencyHint;
        else
            wm_hints->flags &= ~XUrgencyHint;

        XSetWMHints(dpy, xid, wm_hints);
        XFree(wm_hints);
#endif // GDK_WINDOWING_X11
    }
}
Example #14
0
File: events.c Project: Limsik/e17
unsigned char
handle_key_press(event_t *ev)
{
    XWMHints *wm_hints;
#ifdef COUNT_X_EVENTS
    static unsigned long keypress_cnt = 0;
#endif

    PROF_INIT(handle_key_press);
    D_EVENTS(("handle_key_press(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window));
#if UNUSED_BLOCK
    REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0);
#endif

    COUNT_EVENT(keypress_cnt);
    if (!(BITFIELD_IS_SET(eterm_options, ETERM_OPTIONS_NO_INPUT))) {
        lookup_key(ev);
    }
    if (BITFIELD_IS_SET(vt_options, VT_OPTIONS_URG_ALERT)) {
        wm_hints = XGetWMHints(Xdisplay, TermWin.parent);
        wm_hints->flags &= ~XUrgencyHint;
        XSetWMHints(Xdisplay, TermWin.parent, wm_hints);
        XFree(wm_hints);
    }
    PROF_DONE(handle_key_press);
    PROF_TIME(handle_key_press);
    return 1;
}
Example #15
0
int plugin_hide(int ph)
{
	int i;
	XWMHints *hints;
	Display *display = XtDisplay(topLevel);
	Screen *screen = XtScreen(topLevel);
	Window w = plugin[ph].victim;

	XSync(display, False);
	XWithdrawWindow(display, w, XScreenNumberOfScreen(screen));
        XSync(display, False);
        hints = XGetWMHints(display, w);
        hints->flags |= WindowGroupHint;
        hints->window_group = RootWindowOfScreen(screen);
        XSetWMHints(display, w, hints);
#if 1	/* testing */
	for (i = 0; i < REPARENT_LOOPS; i++) {
		Window root, parent, *child;
		Cardinal n;
		XQueryTree(display, w, &root, &parent, &child, &n);
		XReparentWindow(display, w, root, 0, 0);
		XSync(display, False);
	}
#endif
	if (plugin[ph].core != None) {
		XtDestroyWidget(plugin[ph].core);
		plugin[ph].core = None;
	}
	return 0;
}
Example #16
0
// we use logo.xpm as the Application icon
void setIcon (void)
{
    int             rv;
    Pixmap          pixmap = 0;
    Pixmap          mask = 0;
    XpmAttributes   attrib;
    XWMHints       *h = XGetWMHints (dpy, aboutWindow);
    XWMHints        wm_hints;
    Bool            got_hints = h != 0;

    attrib.valuemask = 0;
    rv = XCreatePixmapFromData (dpy, aboutWindow, about_icon_xpm, &pixmap, &mask, &attrib);
    if (rv != XpmSuccess) {
	fprintf (stderr, "Failed to read xpm file: %s\n", XpmGetErrorString (rv));
	return;
    }

    if (!got_hints) {
	h = &wm_hints;
	h->flags = 0;
    }
    h->icon_pixmap = pixmap;
    h->icon_mask = mask;
    h->flags |= IconPixmapHint | IconMaskHint;
    XSetWMHints (dpy, aboutWindow, h);
    if (got_hints)
	XFree ((char *) h);
}
Example #17
0
void CStdWindow::FlashWindow() {
#ifdef USE_X11

// This tries to implement flashing via
// _NET_WM_STATE_DEMANDS_ATTENTION, but it simply does not work for me.
// -ck.
#if 0
	XEvent e;
	e.xclient.type = ClientMessage;
	e.xclient.message_type = XInternAtom(dpy, "_NET_WM_STATE", True);
	e.xclient.window = wnd;
	e.xclient.display = dpy;
	e.xclient.format = 32;
	e.xclient.data.l[0] = 1;
	e.xclient.data.l[1] = XInternAtom(dpy, "_NET_WM_STATE_DEMANDS_ATTENTION", True);
	e.xclient.data.l[2] = 0l;
	e.xclient.data.l[3] = 0l;
	e.xclient.data.l[4] = 0l;

	XSendEvent(dpy, DefaultRootWindow(dpy), false, SubstructureNotifyMask | SubstructureRedirectMask, &e);
#endif

  if (!HasFocus) {
    XWMHints *wm_hint = static_cast<XWMHints *>(Hints);
    wm_hint->flags |= XUrgencyHint;
    XSetWMHints(dpy, wnd, wm_hint);
  }
#endif
}
Example #18
0
static void
set_name_and_icon(void)
{
    char *icon_name = "HyperDoc";
    char *s;
    Pixmap icon_pixmap;
    XWMHints wmhints;
    XClassHint ch;

    ch.res_name = "HyperDoc";
    ch.res_class = gArgv[0];
    for (s = gArgv[0] + strlen(gArgv[0]) - 1; s != gArgv[0]; s--) {
        if (*s == '/') {
            ch.res_class = s + 1;
            break;
        }
    }
    XSetClassHint(gXDisplay, gWindow->fMainWindow, &ch);

    XStoreName(gXDisplay, gWindow->fMainWindow, "HyperDoc");

    /* define and assign the pixmap for the icon */
    icon_pixmap = XCreateBitmapFromData(gXDisplay, gWindow->fMainWindow,
                                        ucharp_to_charp(ht_icon_bits),
                                        ht_icon_width, ht_icon_height);
    wmhints.icon_pixmap = icon_pixmap;
    wmhints.flags = IconPixmapHint;

    XSetWMHints(gXDisplay, gWindow->fMainWindow, &wmhints);

    /* name the icon */
    XSetIconName(gXDisplay, gWindow->fMainWindow, icon_name);
}
Example #19
0
File: xfont.c Project: knaka/src
int
main(int argc, char *argv[])
{
    Display        *display;
    int             screen;
    GC              gc;
    Window          window;
    XWMHints        hints;
    Atom            protocols;
    XEvent          event;
    unsigned long   mask;
    Font            xfont1, xfont2;

    display = XOpenDisplay("");
    screen = DefaultScreen(display);
    gc = DefaultGC(display, screen);

    /*
     * Font names are hard-coded.
     */
    xfont1 = XLoadFont(display, "a14");
    xfont2 = XLoadFont(display, "k14");

    window = XCreateSimpleWindow(display, RootWindow(display, screen),
     0, 0, W_WIDTH, W_HEIGHT, 2,
     BlackPixel(display, screen), WhitePixel(display, screen));
    XStoreName(display, window, "XFontStruct demo");

    hints.flags = InputHint;
    hints.input = True;
    XSetWMHints(display, window, &hints);
    protocols = XInternAtom(display, "WM_DELETE_WINDOW", True);
    XSetWMProtocols(display, window, &protocols, 1);

    mask = ExposureMask;
    XSelectInput(display, window, mask);

    XMapWindow(display, window);

    for (;;) {
        XNextEvent(display, &event);
        if (XFilterEvent(&event, window) == True)
            continue;
        switch (event.type) {
            case Expose: {
                XSetFont(display, gc, xfont1);
                XDrawString(display, window, gc, 10, 50, "abcdef", 6);
                XSetFont(display, gc, xfont2);
                /* JIS */
                XDrawString16(display, window, gc, 10, 80,
                 (XChar2b *) "\x24\x22\x24\x24", 4);
                break;
            }
            default: {
                break;
            }
        }
    }
}
Example #20
0
void prompt_show(ObPrompt *self, ObClient *parent, gboolean modal)
{
    gint i;

    if (self->mapped) {
        /* activate the prompt */
        OBT_PROP_MSG(ob_screen, self->super.window, NET_ACTIVE_WINDOW,
                     1, /* from an application.. */
                     event_time(),
                     0,
                     0, 0);
        return;
    }

    /* set the focused button (if not found then the first button is used) */
    self->focus = &self->button[0];
    for (i = 0; i < self->n_buttons; ++i)
        if (self->button[i].result == self->default_result) {
            self->focus = &self->button[i];
            break;
        }

    if (parent) {
        Atom states[1];
        gint nstates;
        Window p;
        XWMHints h;

        if (parent->group) {
            /* make it transient for the window's group */
            h.flags = WindowGroupHint;
            h.window_group = parent->group->leader;
            p = obt_root(ob_screen);
        }
        else {
            /* make it transient for the window directly */
            h.flags = 0;
            p = parent->window;
        }

        XSetWMHints(obt_display, self->super.window, &h);
        OBT_PROP_SET32(self->super.window, WM_TRANSIENT_FOR, WINDOW, p);

        states[0] = OBT_PROP_ATOM(NET_WM_STATE_MODAL);
        nstates = (modal ? 1 : 0);
        OBT_PROP_SETA32(self->super.window, NET_WM_STATE, ATOM,
                        states, nstates);
    }
    else
        OBT_PROP_ERASE(self->super.window, WM_TRANSIENT_FOR);

    /* set up the dialog and render it */
    prompt_layout(self);
    render_all(self);

    client_manage(self->super.window, self);

    self->mapped = TRUE;
}
Example #21
0
////////////////////////////////////////////////////////////
/// /see WindowImpl::SetIcon
////////////////////////////////////////////////////////////
void WindowImplX11::SetIcon(unsigned int Width, unsigned int Height, const Uint8* Pixels)
{
    // X11 wants BGRA pixels : swap red and blue channels
    // Note : this memory will never be freed, but it seems to cause a bug on exit if I do so
    Uint8* IconPixels = new Uint8[Width * Height * 4];
    for (std::size_t i = 0; i < Width * Height; ++i)
    {
        IconPixels[i * 4 + 0] = Pixels[i * 4 + 2];
        IconPixels[i * 4 + 1] = Pixels[i * 4 + 1];
        IconPixels[i * 4 + 2] = Pixels[i * 4 + 0];
        IconPixels[i * 4 + 3] = Pixels[i * 4 + 3];
    }

    // Create the icon pixmap
    Visual*      DefVisual = DefaultVisual(ourDisplay, ourScreen);
    unsigned int DefDepth  = DefaultDepth(ourDisplay, ourScreen);
    XImage* IconImage = XCreateImage(ourDisplay, DefVisual, DefDepth, ZPixmap, 0, (char*)IconPixels, Width, Height, 32, 0);
    if (!IconImage)
    {
        std::cerr << "Failed to set the window's icon" << std::endl;
        return;
    }
    Pixmap IconPixmap = XCreatePixmap(ourDisplay, RootWindow(ourDisplay, ourScreen), Width, Height, DefDepth);
    XGCValues Values;
    GC IconGC = XCreateGC(ourDisplay, IconPixmap, 0, &Values);
    XPutImage(ourDisplay, IconPixmap, IconGC, IconImage, 0, 0, 0, 0, Width, Height);
    XFreeGC(ourDisplay, IconGC);
    XDestroyImage(IconImage);

    // Create the mask pixmap (must have 1 bit depth)
    std::size_t Pitch = (Width + 7) / 8;
    static std::vector<Uint8> MaskPixels(Pitch * Height, 0);
    for (std::size_t j = 0; j < Height; ++j)
    {
        for (std::size_t i = 0; i < Pitch; ++i)
        {
            for (std::size_t k = 0; k < 8; ++k)
            {
                if (i * 8 + k < Width)
                {
                    Uint8 Opacity = (Pixels[(i * 8 + k + j * Width) * 4 + 3] > 0) ? 1 : 0;
                    MaskPixels[i + j * Pitch] |= (Opacity << k);                    
                }
            }
        }
    }
    Pixmap MaskPixmap = XCreatePixmapFromBitmapData(ourDisplay, myWindow, (char*)&MaskPixels[0], Width, Height, 1, 0, 1);

    // Send our new icon to the window through the WMHints
    XWMHints* Hints = XAllocWMHints();
    Hints->flags       = IconPixmapHint | IconMaskHint;
    Hints->icon_pixmap = IconPixmap;
    Hints->icon_mask   = MaskPixmap;
    XSetWMHints(ourDisplay, myWindow, Hints);
    XFree(Hints);

    XFlush(ourDisplay);
}
Example #22
0
/********************************************************************
* makeIcon
*
* This function creates an icon for the program.
*********************************************************************/
void makeIcon()
{
    XWMHints theWMHints;

    theWMHints.icon_pixmap = pgmIconPattern;
    theWMHints.initial_state = NormalState;
    theWMHints.flags = IconPixmapHint | StateHint;
    XSetWMHints( theDisplay, outerWindow, &theWMHints );
}
Example #23
0
EAPI void
ecore_x_icccm_hints_set(Ecore_X_Window win,
                        Eina_Bool accepts_focus,
                        Ecore_X_Window_State_Hint initial_state,
                        Ecore_X_Pixmap icon_pixmap,
                        Ecore_X_Pixmap icon_mask,
                        Ecore_X_Window icon_window,
                        Ecore_X_Window window_group,
                        Eina_Bool is_urgent)
{
   XWMHints *hints;

   hints = XAllocWMHints();
   if (!hints)
     return;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   hints->flags = InputHint | StateHint;
   hints->input = accepts_focus;
   if (initial_state == ECORE_X_WINDOW_STATE_HINT_WITHDRAWN)
     hints->initial_state = WithdrawnState;
   else if (initial_state == ECORE_X_WINDOW_STATE_HINT_NORMAL)
     hints->initial_state = NormalState;
   else if (initial_state == ECORE_X_WINDOW_STATE_HINT_ICONIC)
     hints->initial_state = IconicState;

   if (icon_pixmap != 0)
     {
        hints->icon_pixmap = icon_pixmap;
        hints->flags |= IconPixmapHint;
     }

   if (icon_mask != 0)
     {
        hints->icon_mask = icon_mask;
        hints->flags |= IconMaskHint;
     }

   if (icon_window != 0)
     {
        hints->icon_window = icon_window;
        hints->flags |= IconWindowHint;
     }

   if (window_group != 0)
     {
        hints->window_group = window_group;
        hints->flags |= WindowGroupHint;
     }

   if (is_urgent)
     hints->flags |= XUrgencyHint;

   XSetWMHints(_ecore_x_disp, win, hints);
   if (_ecore_xlib_sync) ecore_x_sync();
   XFree(hints);
}
Example #24
0
void geSetIcon(ge_Image* icon){
	LibGE_LinuxContext* context = (LibGE_LinuxContext*)libge_context->syscontext;

	Pixmap icon_pixmap = XCreatePixmapFromBitmapData(context->dpy, context->win, (char*)icon->data, icon->width, icon->height, 1, 0, 32);

	win_hints->flags |= IconPixmapHint;
	win_hints->icon_pixmap = icon_pixmap;
	XSetWMHints(context->dpy, context->win, win_hints);
}
Example #25
0
static void sendhints(Window w,struct hints *h)
  {
  if(h->flg&1) XSetWMName(dsp,w,&h->window_name);
  if(h->flg&2) XSetWMIconName(dsp,w,&h->icon_name);
  if(h->flg&4) XSetCommand(dsp,w,h->argv,h->argc);
  if(h->flg&8) XSetClassHint(dsp,w,&h->class_hints);
  if(h->normal_hints.flags) XSetWMNormalHints(dsp,w,&h->normal_hints);  
  if(h->wm_hints.flags) XSetWMHints(dsp,w,&h->wm_hints);
  }
Example #26
0
void X11Window::internalCreateWindow()
{
    Visual *vis;
    int depth;
    unsigned int attrsMask;
    XSetWindowAttributes attrs;
    memset(&attrs, 0, sizeof(attrs));

    attrs.event_mask = KeyPressMask | KeyReleaseMask |
                       ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
                       ExposureMask | VisibilityChangeMask |
                       StructureNotifyMask | FocusChangeMask;

    m_colormap = XCreateColormap(m_display, m_rootWindow, m_visual->visual, AllocNone);
    attrs.colormap = m_colormap;
    attrs.border_pixel = 0;
    attrs.override_redirect = False;
    vis = m_visual->visual;
    depth = m_visual->depth;
    attrsMask = CWEventMask | CWBorderPixel | CWColormap;

#ifdef OPENGL_ES
    attrs.override_redirect = False;
    attrsMask |= CWOverrideRedirect;
#endif

    updateUnmaximizedCoords();
    m_window = XCreateWindow(m_display, m_rootWindow,
                             m_position.x, m_position.y, m_size.width(), m_size.height(),
                             0,
                             depth,
                             InputOutput,
                             vis,
                             attrsMask, &attrs);
    m_visible = true;

    if(!m_window)
        g_logger.fatal("Unable to create X11 window!");

    // ensure window input focus
    XWMHints hints;
    hints.input = True;
    hints.flags = InputHint;
    XSetWMHints(m_display, m_window, &hints);

    // ensure window position
    XMoveWindow(m_display, m_window, m_position.x, m_position.y);

    // handle wm_delete events
    m_wmDelete = XInternAtom(m_display, "WM_DELETE_WINDOW", True);
    XSetWMProtocols(m_display, m_window, &m_wmDelete , 1);

    if(!internalSetupWindowInput())
        g_logger.warning("Input of special keys may be messed up, because window input initialization failed");

    internalConnectGLContext();
}
Example #27
0
void initXWin(int argc, char **argv)
{
	int pos;
	XWMHints wmhints;
	XSizeHints shints;

	winsize=astep ? ASTEPSIZE : NORMSIZE;

	if((d_display=XOpenDisplay(display))==NULL)
	{
		fprintf(stderr,"%s : Unable to open X display '%s'.\n", NAME, XDisplayName(display));
		exit(1);
	}
	_XA_GNUSTEP_WM_FUNC=XInternAtom(d_display, "_GNUSTEP_WM_FUNCTION", 0);
	deleteWin=XInternAtom(d_display, "WM_DELETE_WINDOW", 0);

	w_root=DefaultRootWindow(d_display);

	shints.x=0;
	shints.y=0;
	shints.flags=0;
	pos=(XWMGeometry(d_display, DefaultScreen(d_display), position, NULL, 0, &shints, &shints.x, &shints.y, &shints.width, &shints.height, &shints.win_gravity) & (XValue | YValue));
	shints.min_width=winsize;
	shints.min_height=winsize;
	shints.max_width=winsize;
	shints.max_height=winsize;
	shints.base_width=winsize;
	shints.base_height=winsize;
	shints.flags=PMinSize | PMaxSize | PBaseSize;

	createWin(&w_main, shints.x, shints.y);

	if(wmaker || astep || pos)
		shints.flags |= USPosition;
	if(wmaker)
	{
		wmhints.initial_state=WithdrawnState;
		wmhints.flags=WindowGroupHint | StateHint | IconWindowHint;
		createWin(&w_icon, shints.x, shints.y);
		w_activewin=w_icon;
		wmhints.icon_window=w_icon;
	}
	else
	{
		wmhints.initial_state=NormalState;
		wmhints.flags=WindowGroupHint | StateHint;
		w_activewin=w_main;
	}
	wmhints.window_group=w_main;
	XSetWMHints(d_display, w_main, &wmhints);
	XSetWMNormalHints(d_display, w_main, &shints);
	XSetCommand(d_display, w_main, argv, argc);
	XStoreName(d_display, w_main, NAME);
	XSetIconName(d_display, w_main, NAME);
	XSetWMProtocols(d_display, w_activewin, &deleteWin, 1);
}
Example #28
0
int main(int argc, char **argv)
{
    XEvent   msg;
    XSetWindowAttributes xswa;
    XWMHints wmhints;
    Pixmap icon;
    const long evt_mask = ExposureMask | ButtonPressMask | ButtonReleaseMask | StructureNotifyMask | PointerMotionMask;

    dpy=XOpenDisplay(NULL);
    if (!dpy) {
        fprintf(stderr, "Could not open X11 display.\n");
        return 1;
        }

    scr = DefaultScreen(dpy);

    /* Create the main window and display it */
    wnd = XCreateSimpleWindow(dpy, RootWindow(dpy,scr), 0,0,400,400,0,
                              WhitePixel(dpy,scr), BlackPixel(dpy,scr));
    xswa.backing_store = Always;
    //  XChangeWindowAttributes(dpy, wnd, CWBackingStore, &xswa);

    if(!wnd){
        fprintf(stderr, "Window creation failed !\n");
        return 1;
        }

    XpmCreatePixmapFromData(dpy, wnd, mgldog_xpm, &icon, NULL, NULL);
    wmhints.icon_pixmap = icon;
    wmhints.flags = IconPixmapHint;
    XSetWMHints(dpy, wnd, &wmhints);

    /* Initialise the MGL */
    InitMGL();

    XSelectInput(dpy, wnd, evt_mask);
    XMapRaised(dpy,wnd);
    XStoreName(dpy,wnd,szAppName);
    XSync(dpy, false);


    MGL_bitBltCoord(winDC,memDC,0,0,sizex,sizey,0,0,MGL_REPLACE_MODE);
    /* Polling messages from event queue */
    for(;;) {
        XNextEvent(dpy, &msg);
        // XWindowEvent(dpy, wnd, evt_mask, &msg);
        ProcessEvent(wnd, &msg);
        }

    /* Clean up the MGL before exit */
    MGL_exit();
    XCloseDisplay(dpy);
    return 0;
}
Example #29
0
KPagerMainWindow::KPagerMainWindow(QWidget *parent, const char *name)
	: DCOPObject("KPagerIface"), KMainWindow(parent, name)
{
    m_reallyClose=false;

    m_pPager = new KPager(this, 0);
    setCentralWidget(m_pPager);

    KConfig *cfg = kapp->config();
    cfg->setGroup("KPager");

    // Update the last used geometry
    int w = cfg->readNumEntry(m_pPager->lWidth(),-1);
    int h = cfg->readNumEntry(m_pPager->lHeight(),-1);
    if (w > 0 && h > 0)
        resize(w,h);
    else
        resize(m_pPager->sizeHint());
    //  resize(cfg->readNumEntry(lWidth(),200),cfg->readNumEntry(lHeight(),90));

    int xpos=cfg->readNumEntry("xPos",-1);
    int ypos=cfg->readNumEntry("yPos",-1);
    if (xpos > 0 && ypos > 0)
      move(xpos,ypos);
    else
    {
//      NETRootInfo ri( qt_xdisplay(), NET::WorkArea );
//      NETRect rect=ri.workArea(1);
//      move(rect.pos.x+rect.size.width-m_pPager->width(),
//	  rect.pos.y+rect.size.height-m_pPager->height());
// antonio:The above lines don't work. I should look at them when I have
// more time
        move(kapp->desktop()->width()-m_pPager->sizeHint().width()-5,kapp->desktop()->height()-m_pPager->sizeHint().height()-25);
    }

    // Set the wm flags to this window
    KWin::setState( winId(), NET::StaysOnTop | NET::SkipTaskbar | NET::Sticky | NET::SkipPager );
    KWin::setOnAllDesktops( winId(), true);
    if ( KWin::windowInfo( winId(), NET::WMWindowType, 0 ).windowType(NET::Normal) == NET::Normal )
    {
       KWin::setType( winId(), NET::Utility );
    }

    XWMHints *hints = XGetWMHints(x11Display(), winId());
    if( hints == NULL )
        hints = XAllocWMHints();
    hints->input = false;
    hints->flags |= InputHint;
    XSetWMHints(x11Display(), winId(), hints);
    XFree(reinterpret_cast<char *>(hints));

    timeout=new QTimer(this,"timeoutToQuit");
    connect(timeout,SIGNAL(timeout()),this, SLOT(reallyClose()));
}
Example #30
0
void
piglit_glx_window_set_no_input(Display *dpy, GLXDrawable win)
{
	XWMHints *hints;
	hints = XAllocWMHints();
	hints->flags |= InputHint;
	hints->input = False;

	XSetWMHints(dpy, win, hints);

	XFree(hints);
}