コード例 #1
0
ファイル: icon.c プロジェクト: GNOME/gnome-hello
void
gdk_get_icon_sizes(GdkIconSize** size_list, guint* count)
{
  XIconSize* xsizes;
  int xcount;

  if (XGetIconSizes (gdk_display, gdk_root_window, &xsizes, &xcount))
    {
      int i;

      g_assert (xcount > 0);

      *size_list = g_new (GdkIconSize, xcount);
      *count = (guint)xcount;

      i = 0;
      while (i < xcount)
        {
          (*size_list)[i].min_width  = xsizes[i].min_width;
          (*size_list)[i].min_height = xsizes[i].min_height;
          (*size_list)[i].max_width  = xsizes[i].max_width;
          (*size_list)[i].max_width  = xsizes[i].max_width;
          (*size_list)[i].width_inc  = xsizes[i].width_inc;
          (*size_list)[i].height_inc = xsizes[i].height_inc;

          ++i;
        }
    }
  else
    {
      *size_list = NULL;
      *count = 0;
    }
}
コード例 #2
0
ファイル: xwin.c プロジェクト: omnister/pdplot
void initX() {
    int x,y;
    unsigned int border_width = 4;
    unsigned int display_width, display_height;
    char *window_name = "postplot";
    char *icon_name = "postplot";
    Pixmap icon_pixmap;
    XSizeHints *size_hints;
    XIconSize *size_list;
    XWMHints *wm_hints;
    XClassHint *class_hints;
    XTextProperty windowName, iconName;
    XSetWindowAttributes attr;
    int icount;
    XFontStruct *font_info;
    char *display_name = NULL;

    int dbug=0;

    if (!(size_hints = XAllocSizeHints())) {
        fprintf(stderr, "%s: failure allocating SizeHints memory\n", progname);
        exit (0);
    }
    if (!(wm_hints = XAllocWMHints())) {
        fprintf(stderr, "%s: failure allocating WMHints memory\n", progname);
        exit (0);
    }
    if (!(class_hints = XAllocClassHint())) {
        fprintf(stderr, "%s: failure allocating ClassHint memory\n", progname);
        exit (0);
    }

    /* Connect to X server */
    if ( (dpy=XOpenDisplay(display_name)) == NULL ) {
        (void) fprintf( stderr, "%s: cannot connect to X server %s\n",
            progname, XDisplayName(display_name));
        exit(-1);
    }

    /* Get screen size from display structure macro */
    screen_num = DefaultScreen(dpy);
    display_width = DisplayWidth(dpy, screen_num);
    display_height = DisplayHeight(dpy, screen_num);

    /* eventually we want to set x,y from command line or
       resource database */

    x=y=0;

    /* Size window */
    width = display_width/2, height = display_height/2;


    /* Create opaque window */
    win = XCreateSimpleWindow(dpy, RootWindow(dpy,screen_num),
        x,y,width, height, border_width, WhitePixel(dpy,screen_num),
        BlackPixel(dpy,screen_num));

    /* Get available icon sizes from window manager */

    if (XGetIconSizes(dpy, RootWindow(dpy, screen_num),
            &size_list, &icount) == 0) {
        if (dbug) fprintf(stderr, 
		"%s: WM didn't set icon sizes - using default.\n", progname);
    } else {
        /* should eventually create a pixmap here */
        ;
    }

    /* Create pixmap of depth 1 (bitmap) for icon */
    icon_pixmap = XCreateBitmapFromData(dpy, win,
        icon_bitmap_bits, icon_bitmap_width, icon_bitmap_height);
    
    size_hints->flags = PPosition | PSize | PMinSize;
    size_hints->min_width =  300;
    size_hints->min_height = 200;

    if (XStringListToTextProperty(&window_name, 1, &windowName) == 0) {
        fprintf(stderr, "%s: structure allocation for windowName failed.\n",
            progname);
        exit(-1);
    }

    if (XStringListToTextProperty(&icon_name, 1, &iconName) == 0) {
        fprintf(stderr, "%s: structure allocation for iconName failed.\n",
            progname);
        exit(-1);
    }
    
    wm_hints->initial_state = NormalState;
    wm_hints->input = True;
    wm_hints->icon_pixmap = icon_pixmap;

    wm_hints->flags = StateHint | IconPixmapHint | InputHint;

    class_hints->res_name = progname;
    class_hints->res_class = "pdp";

    XSetWMProperties(dpy, win, &windowName, &iconName,
             (char **) NULL, (int) 0, size_hints, wm_hints, class_hints);

    /* Select event types wanted */
    XSelectInput(dpy, win, ExposureMask | KeyPressMask |
        ButtonPressMask | ButtonReleaseMask | StructureNotifyMask | 
	Button1MotionMask );

    init_colors();
    load_font(&font_info);

    /* Create GC for text and drawing */
    getGC(win, &gc, font_info);
    getGC(win, &gcx, font_info);
    XSetFunction(dpy, gcx, GXxor);

    /* Display window */
    XMapWindow(dpy, win);

    /* turn on backing store */
    attr.backing_store = Always;
    XChangeWindowAttributes(dpy,win,CWBackingStore,&attr);     
}
コード例 #3
0
ファイル: DrvWindows.c プロジェクト: ErisBlastar/osfree
static DWORD
DrvCreateWindows(LPARAM dwParm1, LPARAM dwParm2, LPVOID lpStruct)
{
    LPWINCREATESTRUCT lpwcs = (LPWINCREATESTRUCT)lpStruct;
    UINT input_class;
    DWORD dwEventMask;
    DWORD dwCWMask;
    XSetWindowAttributes xattr;
    XSizeHints size_hints;
    XWMHints wm_hints;
    Window win_parent, frame_win;
    Pixmap icon_pixmap = None,icon_mask = None;
    DRVIMAGEDATA *lpimage;
    GC gc;
    PRIVATEDISPLAY *Disp = GETDP();
    WM_WINDOW_STATE WMWindowState;

    input_class = (lpwcs->dwExStyle & WS_EX_TRANSPARENT)?
		InputOnly:InputOutput;

    /* set general default values and mask for xattr */
    /* default white X background */
#ifdef	LATER
    these should call color subsystem
#endif
#ifdef TWIN_PALETTE
    xattr.background_pixel = DrvMakePixel(RGB(255,255,255), NULL);
    xattr.border_pixel = DrvMakePixel(RGB(0,0,0), NULL);
#else
    xattr.background_pixel = DrvMakePixel(RGB(255,255,255));
    xattr.border_pixel = DrvMakePixel(RGB(0,0,0));
#endif
    /* default NorthWestGravity */
    xattr.bit_gravity = NorthWestGravity;

#ifdef TWIN_PALETTE
    xattr.colormap = Disp->SystemPalette;
#else
    xattr.colormap = Disp->color_map;
#endif

    dwCWMask = CWBackPixel|CWBorderPixel|CWBitGravity|CWColormap;

	win_parent = RootWindow(Disp->display, Disp->screen);

	/* for top-level window without caption use override_redirect */
	if ((lpwcs->dwStyle & WS_CAPTION) != WS_CAPTION)
	    xattr.override_redirect = True;
	else
	    xattr.override_redirect = False;

	/* if SAVEBITS and server supports save_under, use it */
	if ((lpwcs->dwExStyle & WS_EX_SAVEBITS) &&
	    XDoesSaveUnders(XScreenOfDisplay(Disp->display,Disp->screen)))
	    xattr.save_under = True;
	else
	    xattr.save_under = False;

	if (lpwcs->Cursor) 
	    xattr.cursor = (Cursor)lpwcs->Cursor;
	else
	    xattr.cursor = None;


	/* X does not tolerate zero-size windows */
	lpwcs->rcFrame.right = max(lpwcs->rcFrame.right,1);
	lpwcs->rcFrame.bottom = max(lpwcs->rcFrame.bottom,1);

	if (input_class != InputOnly)
	    frame_win = XCreateWindow(Disp->display, win_parent,
		lpwcs->rcFrame.left,lpwcs->rcFrame.top,
		lpwcs->rcFrame.right,lpwcs->rcFrame.bottom,
		lpwcs->nBorder,
		CopyFromParent,
		input_class,
		CopyFromParent,
		dwCWMask | CWOverrideRedirect| CWSaveUnder | CWCursor,
		&xattr);
	else
	    frame_win = XCreateWindow(Disp->display, win_parent,
		lpwcs->rcFrame.left,lpwcs->rcFrame.top,
		lpwcs->rcFrame.right,lpwcs->rcFrame.bottom,
		0,
		CopyFromParent,
		InputOnly,
		CopyFromParent,
		CWOverrideRedirect,
		&xattr);

	if (frame_win == 0)
	    return 0L;

	/* save necessary contexts in the frame window */
	XSaveContext(Disp->display, frame_win, Disp->client_hwnd,
		(caddr_t)MAKELONG(lpwcs->hWndClient,lpwcs->hWndFrame));
	XSaveContext(Disp->display, frame_win, Disp->window_style,
		(caddr_t)lpwcs->dwStyle);
	XSaveContext(Disp->display, frame_win, Disp->window_ex_style,
		(caddr_t)lpwcs->dwExStyle);

#ifdef	LATER
	/* Use XSetWMProperties for top-level windows instead */
#endif
	/* Set standard hints for window manager */
#ifdef	LATER
	/* we can set user-specified values, min/maxsize, basesize etc. here */
#endif
	size_hints.flags = PPosition | PSize;
	size_hints.x = lpwcs->rcFrame.left;
	size_hints.y = lpwcs->rcFrame.top;
	size_hints.width = lpwcs->rcFrame.right;
	size_hints.height = lpwcs->rcFrame.bottom;

	if (lpwcs->lpIconANDData) {
	    XGCValues values;

	    lpimage = (DRVIMAGEDATA *)lpwcs->lpIconANDData;
	    if (lpimage->image) {
		icon_mask = XCreatePixmap(Disp->display,
				DefaultRootWindow(Disp->display),
				X_ICON_SIZE,X_ICON_SIZE,1);
		values.foreground = 0;
		values.background = 1;
		gc = XCreateGC(Disp->display,icon_mask,
				GCForeground|GCBackground,&values);
		XPutImage(Disp->display,
			  icon_mask,
			  gc,
			  lpimage->image,
			  0,0,0,0,
			  lpimage->nWidth,lpimage->nHeight);
		XFreeGC(Disp->display,gc);
	    }
	}

	if (lpwcs->lpIconXORData) {

	    lpimage = (DRVIMAGEDATA *)lpwcs->lpIconXORData;
	    if (lpimage->image) {
#if 1
		icon_pixmap = XCreateBitmapFromData(Disp->display, 
			DefaultRootWindow(Disp->display), lpimage->image->data,
			lpimage->nWidth, lpimage->nHeight);
#else
		{
	        int xOffset,yOffset;
		icon_pixmap = XCreatePixmap(Disp->display,
				DefaultRootWindow(Disp->display),
				X_ICON_SIZE,X_ICON_SIZE,1);
		gc = XCreateGC(Disp->display,icon_pixmap,0,0L);
		XSetForeground(Disp->display,gc,
				WhitePixel(Disp->display,Disp->screen));
		XFillRectangle(Disp->display,icon_pixmap,gc,0,0,
				X_ICON_SIZE,X_ICON_SIZE);
		xOffset = (X_ICON_SIZE - lpimage->nWidth)/2;
		yOffset = (X_ICON_SIZE - lpimage->nHeight)/2;
		XSetClipMask(Disp->display,gc,icon_mask);
		XSetClipOrigin(Disp->display,gc,xOffset,yOffset);
		XPutImage(Disp->display,
			  icon_pixmap,
			  gc,
			  lpimage->image,
			  0,0,xOffset,yOffset,
			  lpimage->nWidth,lpimage->nHeight);
		XFreeGC(Disp->display,gc);
		}
#endif
	    }
	}

	/* set properties for window manager */
	XSetStandardProperties(Disp->display, frame_win,
	    (HIWORD(lpwcs->lpszName))?lpwcs->lpszName:"",
	    (HIWORD(lpwcs->lpszName))?lpwcs->lpszName:"",
	    icon_pixmap,
#ifdef	LATER
	/* pass argv and argc here */
#else
	    0,0,
#endif
	    &size_hints);

#ifdef	LATER
	/* can this be False??? */
#endif
	wm_hints.input = True;
	wm_hints.icon_pixmap = icon_pixmap;
	wm_hints.icon_mask = icon_mask;
#ifdef	LATER
	/* we can set icon_window,icon position,initial state,group here */
#endif
	wm_hints.flags = InputHint | StateHint;
	if (icon_pixmap != None)
	    wm_hints.flags |= IconPixmapHint;
#ifdef LATER
    	if (lpwcs->dwStyle & WS_MINIMIZE)
		wm_hints.initial_state = IconicState;
	else
#endif
		wm_hints.initial_state = NormalState;
#ifdef LATER
	if ( XGetIconSizes ( Disp->display, frame_win, &pIconSizes, 
	                     &nIconSizes ) )
	{
		IconHeight = pIconSizes->max_height;
		IconWidth  = pIconSizes->max_width;
	}
	else
	{
		IconHeight = IconWidth = X_ICON_SIZE;
	}
	wm_hints.icon_window = XCreateSimpleWindow ( Disp->display,
	                                             win_parent, 0, 0,
	                                             IconWidth, IconHeight,
	                                             0, 0, 0xffffffff );
	xattr.override_redirect = True;
	xattr.background_pixmap = icon_pixmap;
	xattr.background_pixel  = DrvMakePixel(RGB(255,255,255), NULL);
	XChangeWindowAttributes ( Disp->display, wm_hints.icon_window,
	                          CWOverrideRedirect | CWBackPixel,
	                          &xattr );
#endif
	XSetWMHints(Disp->display, frame_win, &wm_hints);

	WMWindowState.State = wm_hints.initial_state;
	WMWindowState.IconWindow = wm_hints.icon_window;
	WMWindowState.PixmapWindow = icon_pixmap;
	DrvGetSetWMState ( frame_win, &WMWindowState, DRV_GETSET_SET );

#ifdef	LATER
	/* can other protocols (WM_TAKE_FOCUS etc.) be used??? */
#endif
	if (Disp->wm_delete_window != None)
	    XSetWMProtocols(Disp->display,frame_win,&Disp->wm_delete_window,1);

	dwEventMask = TOPLEVEL_EVENTS;

	/* Select event types wanted */
	XSelectInput(Disp->display, frame_win, dwEventMask);

    return (DWORD)frame_win;
}