void X11Window::set_size(int width, int height, bool size_is_client_area) { update_frame_extents(); if (!resize_allowed) // If resize has been disabled, we have to temporary enable it { long user_hints; XGetWMNormalHints(handle.display, handle.window, size_hints, &user_hints); size_hints->flags &= ~(PMinSize | PMaxSize); XSetWMNormalHints(handle.display, handle.window, size_hints); } if (!size_is_client_area) { width = std::max(_ResizeMinimumSize_, width - frame_extents.left - frame_extents.right); height = std::max(_ResizeMinimumSize_, height - frame_extents.top - frame_extents.bottom); } auto new_client_area = Rect::xywh(client_area.left, client_area.top, width, height); XResizeWindow(handle.display, handle.window, width, height); if (!resize_allowed) // resize has been temporary enabled { size_hints->min_width = width; size_hints->min_height = height; size_hints->max_width = width; size_hints->max_height = height; size_hints->flags |= PMinSize | PMaxSize; XSetWMNormalHints(handle.display, handle.window, size_hints); } process_window_resize(new_client_area); }
Client * client_new(Window win) { Client *c; long supplied; Atom win_type; XGetWindowAttributes(display, win, &attr); if (attr.override_redirect) return NULL; if (c = client_find(win)) return NULL; c = malloc(sizeof *c); c->next = head; head = c; c->win = win; c->name = ewmh_get_text(c, WM_NAME); c->geom.x = attr.x; c->geom.y = 16; c->geom.w = attr.width; c->geom.h = attr.height; XGetWMNormalHints(display, c->win, &c->size, &supplied); XGetTransientForHint(display, c->win, &c->trans); return c; }
BZclient::BZclient( Display* dpy, Window w ) { XWindowAttributes attr; long dummy ; XWMHints *hints ; XGrabServer(dpy); XGetTransientForHint(dpy, w, &transient); XFetchName(dpy, w, &name); XGetWindowAttributes(dpy, w, &attr); window = w ; ignore_unmap = 0 ; x = attr.x ; y = attr.y ; width = attr.width ; height = attr.height ; cmap = attr.colormap ; size = XAllocSizeHints() ; XGetWMNormalHints(dpy, window, size, &dummy); XSync(dpy, False); XUngrabServer(dpy); }
void subTrayConfigure(SubTray *t) { long supplied = 0; XSizeHints *hints = NULL; assert(t); /* Size hints */ if(!(hints = XAllocSizeHints())) { subSharedLogError("Can't alloc memory. Exhausted?\n"); abort(); } XGetWMNormalHints(subtle->dpy, t->win, hints, &supplied); if(0 < supplied) { if(hints->flags & (USSize|PSize)) ///< User/program size t->width = MINMAX(hints->width, subtle->ph, 2 * subtle->ph); else if(hints->flags & PBaseSize) ///< Base size t->width = MINMAX(hints->base_width, subtle->ph, 2 * subtle->ph); else if(hints->flags & PMinSize) ///< Min size t->width = MINMAX(hints->min_width, subtle->ph, 2 * subtle->ph); } XFree(hints); subSharedLogDebug("Tray: width=%d, supplied=%ld\n", t->width, supplied); } /* }}} */
bool KWM::fixedSize(Window w){ XSizeHints size; long msize; if (XGetWMNormalHints(qt_xdisplay(), w, &size, &msize)) return (size.flags & PMaxSize ) && (size.flags & PMinSize) && (size.max_width <= size.min_width) && (size.max_height <= size.min_height); return FALSE; }
/* Draw the icon */ static void DrawIcon (ClientData clientData) { TrayIcon *icon=clientData; int x,y; unsigned int w,h,b,d; int widthImg, heightImg; Window r; char cmdBuffer[1024]; XSizeHints *hints = NULL; long supplied = 0; if( icon->win == NULL ) { return; } XGetGeometry(display, Tk_WindowId(icon->win), &r, &x, &y, &w, &h, &b, &d); XClearWindow(display, Tk_WindowId(icon->win)); /* * Here we get the window hints because in some cases the XGetGeometry * function returns the wrong width/height. We only check that * min_width <= width <= max_width and min_height <= height <= max_height */ hints = XAllocSizeHints(); XGetWMNormalHints(display, Tk_WindowId(icon->win), hints, &supplied); if( supplied & PMaxSize ) { w = (hints->max_width < w) ? hints->max_width : w; h = (hints->max_height < h) ? hints->max_height : h; } if( supplied & PMinSize ) { w = (hints->min_width > w) ? hints->min_width : w; h = (hints->min_height > h) ? hints->min_height : h; } if(hints) { XFree(hints); hints = NULL; } if (((icon->width != w) || (icon->height != h) || (icon->mustUpdate)) && (icon->cmdCallback[0] != '\0')) { snprintf(cmdBuffer,sizeof(cmdBuffer),"%s %u %u",icon->cmdCallback,w,h); Tcl_EvalEx(globalinterp,cmdBuffer,-1,TCL_EVAL_GLOBAL); icon->mustUpdate = False; icon->width = w; icon->height = h; } Tk_SizeOfImage(icon->pixmap, &widthImg, &heightImg); if (widthImg > w) widthImg = w; if (heightImg > h) heightImg = h; if( !Tk_IsMapped(icon->win) ) Tk_MapWindow(icon->win); Tk_RedrawImage(icon->pixmap, 0, 0, widthImg, heightImg, Tk_WindowId(icon->win), (w-widthImg)/2 , (h-heightImg)/2 ); }
void xwindow_get_sizehints(Window win, XSizeHints *hints) { int minh, minw; long supplied=0; memset(hints, 0, sizeof(*hints)); XGetWMNormalHints(ioncore_g.dpy, win, hints, &supplied); xsizehints_sanity_adjust(hints); }
void Updatera(UltimateContext *uc) { XSizeHints sizehints; long supplied; if(!XGetWMNormalHints(disp,uc->win,&sizehints,&supplied)){ sizehints.flags = 0; uc->flags |= PLACEIT; } if(sizehints.flags & PWinGravity) uc->ra.gravity = sizehints.win_gravity; else uc->ra.gravity = StaticGravity; if(sizehints.flags & USPosition) { uc->flags &= ~PLACEIT; /* uc->ra.x=sizehints.x; OBSOLETE uc->ra.y=sizehints.y; */ } if(sizehints.flags & PResizeInc) { uc->ra.wi=sizehints.width_inc; uc->ra.hi=sizehints.height_inc; } else uc->ra.wi=uc->ra.hi=1; if(sizehints.flags & PBaseSize) { uc->ra.bw=sizehints.base_width+2*uc->BorderWidth; uc->ra.bh=sizehints.base_height+2*uc->BorderWidth+TheScreen.TitleHeight; } else if(sizehints.flags & PMinSize) { uc->ra.bw=sizehints.min_width+2*uc->BorderWidth; uc->ra.bh=sizehints.min_height+2*uc->BorderWidth+TheScreen.TitleHeight; } else { uc->ra.bw= 1 + 2*uc->BorderWidth; uc->ra.bh= 1 + 2*uc->BorderWidth + TheScreen.TitleHeight; } if(sizehints.flags & PMinSize) { uc->ra.minw=sizehints.min_width+2*uc->BorderWidth; uc->ra.minh=sizehints.min_height+2*uc->BorderWidth+TheScreen.TitleHeight; } else { uc->ra.minw=uc->ra.bw; uc->ra.minh=uc->ra.bh; } if(sizehints.flags &PMaxSize) { uc->ra.maxw=sizehints.max_width+2*uc->BorderWidth; uc->ra.maxh=sizehints.max_height+2*uc->BorderWidth+TheScreen.TitleHeight; } else { uc->ra.maxw=TheScreen.width+1; uc->ra.maxh=TheScreen.height+1; } if(uc->ra.bw>uc->ra.minw) uc->ra.minw=uc->ra.bw; if(uc->ra.bh>uc->ra.minh) uc->ra.minh=uc->ra.bh; /*** Aspect ratios not supported (yet?) ***/ }
int xwindow_get_sizehints(Window win, XSizeHints *hints) { long supplied=0; if (XGetWMNormalHints(ioncore_g.dpy, win, hints, &supplied)!=0){ xsizehints_sanity_adjust(hints); return 0; }else{ memset(hints, 0, sizeof(*hints)); return -1; } }
void match_size_hints(Window xterm, int add_y) { XSizeHints * size_hints = XAllocSizeHints(); long returned = 0; XGetWMNormalHints(gdi.display, xterm, size_hints, &returned); size_hints->base_height += add_y; size_hints->max_height += add_y; size_hints->min_height += add_y; size_hints->width_inc = 1; size_hints->height_inc = 1; XSetWMNormalHints(gdi.display, gdi.mainw, size_hints); XFree(size_hints); }
int get_height_inc() { int height_inc = 0; XSizeHints *size; long dummy; size = XAllocSizeHints(); /* wait for terminal to initialize */ while (!size->height_inc) XGetWMNormalHints(dpy, termwin, size, &dummy); height_inc = size->height_inc; XFree(size); return height_inc; }
int PropGetNormalHints(Window window, XSizeHints *size_hints, int *pre_iccm) { long supplied_hints; if (!XGetWMNormalHints(dpy, window, size_hints, &supplied_hints)) { return False; } if (supplied_hints == (USPosition | USSize | PPosition | PSize | PMinSize | PMaxSize | PResizeInc | PAspect)) { *pre_iccm = 1; } else { *pre_iccm = 0; } return True; }
int mlx_int_anti_resize_win(t_xvar *xvar,Window win,int w,int h) { XSizeHints hints; long toto; XGetWMNormalHints(xvar->display,win,&hints,&toto); hints.width = w; hints.height = h; hints.min_width = w; hints.min_height = h; hints.max_width = w; hints.max_height = h; hints.flags = PPosition | PSize | PMinSize | PMaxSize; XSetWMNormalHints(xvar->display,win,&hints); }
window_t * window_init( Display *conn, Window window ) { window_t *w_return; property_t p_value; int length; XSizeHints hints; long flags; w_return = malloc( sizeof(window_t) ); w_return->id = window; /* Set name of window */ length = property_size( conn, window, EA_NET_WM_NAME ); if ( length != 0) { p_value = property_get( conn, window, EA_NET_WM_NAME, length ); } else { length = property_size( conn, window, XA_WM_NAME ); p_value = property_get( conn, window, XA_WM_NAME, length ); } w_return->name = malloc( p_value.size ); snprintf( w_return->name, p_value.size, "%s", p_value.data ); /* Set name of icon */ length = property_size( conn, window, EA_NET_WM_ICON_NAME ); if ( length != 0) { p_value = property_get( conn, window, EA_NET_WM_ICON_NAME, length ); } else { length = property_size( conn, window, XA_WM_ICON_NAME ); p_value = property_get( conn, window, XA_WM_ICON_NAME, length ); } w_return->icon_name = malloc( p_value.size ); snprintf( w_return->icon_name, p_value.size, "%s", p_value.data ); XGetWMNormalHints( conn, window, &hints, &w_return->flags ); w_return->min_width = hints.min_width; w_return->min_height = hints.min_height; w_return->max_width = hints.max_width; w_return->max_height = hints.max_height; w_return->width_inc = hints.width_inc; w_return->height_inc = hints.height_inc; w_return->base_width = hints.base_width; w_return->base_height = hints.base_height; return w_return; }
void X11Window::set_maximum_size(int width, int height, bool size_is_client_area) { maximum_size = Size(width,height); if (!size_is_client_area) { maximum_size.width -= frame_extents.left + frame_extents.right; maximum_size.height -= frame_extents.top + frame_extents.bottom; } long user_hints; XGetWMNormalHints(handle.display, handle.window, size_hints, &user_hints); size_hints->max_width = maximum_size.width; size_hints->max_height = maximum_size.height; size_hints->flags |= PMaxSize; XSetWMNormalHints(handle.display, handle.window, size_hints); }
/*********************************************************************** * Try and do something sensible about window geometry ***********************************************************************/ static void GetWindowGeometry( Display* dpy, Window win, Position* x, Position* y, Dimension* width, Dimension* height, Dimension* border_width, /* the following doesn't really belong here but it saves us from doing another XGetWindowAttributes later on */ Colormap *cmap) { long mask; XSizeHints* sizehints = XAllocSizeHints(); XWindowAttributes wattr; if (XGetWindowAttributes (dpy, win, &wattr)) { *x = wattr.x; *y = wattr.y; *width = wattr.width; *height = wattr.height; *border_width = wattr.border_width; *cmap = wattr.colormap; } if (sizehints) { XGetWMNormalHints (dpy, win, sizehints, &mask); if (mask & (USPosition|PPosition)) { *x = sizehints->x; *y = sizehints->y; *width = sizehints->width; *height = sizehints->height; XFree ((char*) sizehints); return; } XFree ((char*) sizehints); } *x = 0; *y = 0; *width = 0; *height = 0; }
void updatesizehints(Client *c) { long msize; XSizeHints size; if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags) size.flags = PSize; c->flags = size.flags; if(c->flags & PBaseSize) { c->basew = size.base_width; c->baseh = size.base_height; } else c->basew = c->baseh = 0; if(c->flags & PResizeInc) { c->incw = size.width_inc; c->inch = size.height_inc; } else c->incw = c->inch = 0; if(c->flags & PMaxSize) { c->maxw = size.max_width; c->maxh = size.max_height; } else c->maxw = c->maxh = 0; if(c->flags & PMinSize) { c->minw = size.min_width; c->minh = size.min_height; } else c->minw = c->minh = 0; if(c->flags & PAspect) { c->minax = size.min_aspect.x; c->minay = size.min_aspect.y; c->maxax = size.max_aspect.x; c->maxay = size.max_aspect.y; } else c->minax = c->minay = c->maxax = c->maxay = 0; c->isfixed = (c->maxw && c->minw && c->maxh && c->minh && c->maxw == c->minw && c->maxh == c->minh); }
void X11Window::set_position(const Rect &pos, bool pos_is_client_area) { update_frame_extents(); if (!resize_allowed) // If resize has been disabled, we have to temporary enable it { long user_hints; XGetWMNormalHints(handle.display, handle.window, size_hints, &user_hints); size_hints->flags &= ~(PMinSize | PMaxSize); XSetWMNormalHints(handle.display, handle.window, size_hints); } int width = pos.get_width(); int height = pos.get_height(); Rect new_client_area; if (pos_is_client_area) { new_client_area = pos; XMoveResizeWindow(handle.display, handle.window, pos.left - frame_extents.left, pos.top - frame_extents.top, width, height); } else { width = width - frame_extents.left - frame_extents.right; height = height - frame_extents.top - frame_extents.bottom; new_client_area = Rect::xywh(pos.left + frame_extents.left, pos.top + frame_extents.top, width, height); XMoveResizeWindow(handle.display, handle.window, pos.left, pos.top, width, height); } if (!resize_allowed) // resize has been temporary enabled { size_hints->min_width = width; size_hints->min_height = height; size_hints->max_width = width; size_hints->max_height = height; size_hints->flags |= PMinSize | PMaxSize; XSetWMNormalHints(handle.display, handle.window, size_hints); } process_window_resize(new_client_area); }
void Frame::get_wm_normal_hints() // Poor implementation of many applications .... { XSizeHints *xsizehints; long hints = NULL; long wm_flags = NULL; if ((xsizehints = XAllocSizeHints()) != NULL) { if (XGetWMNormalHints(QX11Info::display(), c_win, xsizehints, &hints) == 0) return; wm_flags = xsizehints->flags; win_gravity = xsizehints->win_gravity; qDebug() << "Window flags:" << wm_flags << "Window gravity:" << win_gravity; if (wm_flags & PPosition) { client_x = xsizehints->x; client_y = xsizehints->y; qDebug() << "PPosition:" << client_x << client_y; } if (wm_flags & PSize) { if (xsizehints->width != 0) client_w = xsizehints->width; if (xsizehints->height != 0) client_h = xsizehints->height; qDebug() << "PSize:" << client_w << client_h; } if (wm_flags & PBaseSize) { if (xsizehints->base_width != 0 && xsizehints->base_width >= client_w) client_w = xsizehints->base_width; if (xsizehints->base_height != 0 && xsizehints->base_height >= client_h) client_h = xsizehints->base_height; qDebug() << "PBaseSize:" << client_w << client_h; } qDebug() << "Final Client Size:" << client_w << client_h; } }
void checksizehints(Client *c) { long supplied; XGetWMNormalHints(dpy, c->window, &c->sizehints, &supplied); if(!(c->sizehints.flags&PMinSize)) c->sizehints.min_width=c->sizehints.min_height=0; if(!(c->sizehints.flags&PMaxSize)) c->sizehints.max_width=c->sizehints.max_height=1<<30; if(!(c->sizehints.flags&PResizeInc)) c->sizehints.width_inc=c->sizehints.height_inc=1; if(c->sizehints.flags&PBaseSize) { c->sizehints.min_width=c->sizehints.base_width; c->sizehints.min_height=c->sizehints.base_height; } if(c->sizehints.min_width<1) c->sizehints.min_width=1; if(c->sizehints.min_height<1) c->sizehints.min_height=1; c->sizehints.base_width=c->sizehints.min_width; c->sizehints.base_height=c->sizehints.min_height; if(c->sizehints.flags&PWinGravity) c->gravity=c->sizehints.win_gravity; }
int main() { char *cp; Display *dpy; Window window; XWindowAttributes win_attributes; XSizeHints hints; long longjunk; int dst[2]; _scrsize(dst); cp = getenv("WINDOWID"); if (cp) { dpy = XOpenDisplay(NULL); if (dpy) { if (XGetWindowAttributes(dpy, window = atol(cp), &win_attributes)) if (XGetWMNormalHints(dpy, window, &hints, &longjunk)) if (hints.flags & PResizeInc && hints.width_inc && hints.height_inc) { if (hints.flags & (PBaseSize | PMinSize)) { if (hints.flags & PBaseSize) { win_attributes.width -= hints.base_width; win_attributes.height -= hints.base_height; } else { win_attributes.width -= hints.min_width; win_attributes.height -= hints.min_height; } } dst[0] = win_attributes.width / hints.width_inc; dst[1] = win_attributes.height / hints.height_inc; } XCloseDisplay(dpy); } } printf("%i %i\n", dst[0], dst[1]); return 0; }
void Client::getWMNormalHints() { XSizeHints *xsizehints; if ((xsizehints = XAllocSizeHints()) == NULL) sleep(1); long hints; if (XGetWMNormalHints(display(), clientId, xsizehints, &hints) == 0) xsizehints->flags = 0; wmnflags = xsizehints->flags; qDebug() << "WINDOW FLAGS = " << wmnflags; wingrav = xsizehints->win_gravity; bool pminsize = false; // set max, min and base size (results include window borders) /* if (wmnflags & PMinSize) { qDebug() << "PMINSIZE"; min_w = xsizehints->min_width; min_h = xsizehints->min_height+diff_border_h; pminsize = true; // to get base size if unspecified } else { min_w = 4; min_h = diff_border_h; } if (wmnflags & PMaxSize) { qDebug() << "PMAXSIZE"; max_w = xsizehints->max_width; max_h = xsizehints->max_height+diff_border_h; if (max_w > desk->width()-10) max_w = desk->width()-10; if (max_h > desk->height()-dock_height) max_h = desk->height()-dock_height; } else { max_w = desk->width()-10; max_h = desk->height()-dock_height; } */ /* if (wmnflags & PSize || wmnflags || USSize) { qDebug() << "PSIZE"; base_w = xsizehints->base_width; base_h = xsizehints->base_height + diff_border_h; if (! pminsize) // get from base if unspecified { min_w = base_w; min_h = base_h; } } else if (pminsize) { base_w = xsizehints->min_width; base_h = xsizehints->min_height; } if (wmnflags & PResizeInc) { inc_w = xsizehints->width_inc; inc_h = xsizehints->height_inc; } else inc_w = inc_h = 1; // Some window generate bad values !!! if (base_w > 0 && base_h > 0) resize_request(n_px, n_py, base_w, base_h); qDebug() << "min_w:" << min_w << "min_h:" << min_h << "max_w:" << max_w << "max_h:" << max_h << "base_w:" << base_w << "base_h:" << base_h; XFree(xsizehints); */ }
/** @brief Update frame with available resizing information @return void **/ void get_frame_hints(Display* display, struct Frame* frame) { //use themes XSizeHints specified; long pre_ICCCM; //pre ICCCM recovered values which are ignored. #ifdef SHOW_FRAME_HINTS printf("BEFORE: width %d, height %d, x %d, y %d, minh %d, minw %d\n", frame->w, frame->h, frame->x, frame->y, frame->min_height, frame->min_width); #endif /* whenever assigning a width, height, min/max width/height anew, always add on the h/v space. */ if(XGetWMNormalHints(display, frame->framed_window, &specified, &pre_ICCCM) != 0) { #ifdef SHOW_FRAME_HINTS printf("Managed to recover size hints\n"); #endif if(specified.flags & PResizeInc) { //Set this first as it might be required for the min hints #ifdef SHOW_FRAME_HINTS printf("got inc hints, w %d, h %d\n", specified.width_inc, specified.height_inc); #endif frame->width_inc = specified.width_inc; frame->height_inc = specified.height_inc; } if((specified.flags & PPosition) || (specified.flags & USPosition)) { #ifdef SHOW_FRAME_HINTS if(specified.flags & PPosition) printf("PPosition specified\n"); else printf("USPosition specified\n"); #endif frame->x = specified.x; frame->y = specified.y; } if((specified.flags & PSize) || (specified.flags & USSize)) { #ifdef SHOW_FRAME_HINTS printf("Size specified\n"); #endif frame->w = specified.width; frame->h = specified.height; frame->w += frame->hspace; frame->h += frame->vspace; } if(specified.flags & PMinSize) { #ifdef SHOW_FRAME_HINTS printf("Minimum size specified\n"); #endif frame->w_inc_offset = specified.min_width % frame->width_inc; frame->h_inc_offset = specified.min_height % frame->height_inc; if(specified.min_width < MINWIDTH) { //decided to override min hints, compensate possible base case for inc_resize if(frame->width_inc > 1) { //inc defaults to 1 so the following might be changing the size in that case needlessly frame->min_width += frame->width_inc - (frame->min_width % frame->width_inc); if(frame->w_inc_offset) { frame->min_width -= frame->w_inc_offset; frame->min_width += frame->width_inc; } } } else { frame->min_width = specified.min_width; frame->min_width += frame->hspace; } if(specified.min_height < MINHEIGHT) { //decided to override min hints, compensate possible base case for inc_resize if(frame->height_inc > 1) { //inc defaults to 1 so the following might be changing the size in that case needlessly frame->min_height += frame->height_inc - (frame->min_height % frame->height_inc); if(frame->h_inc_offset) { frame->min_height -= frame->h_inc_offset; frame->min_height += frame->height_inc; } } } else { frame->min_height = specified.min_height; frame->min_height += frame->vspace; } if(frame->min_width > frame->max_width) frame->max_width = frame->min_width; if(frame->min_height > frame->max_height) frame->max_height = frame->min_height; } if(specified.flags & PMaxSize) { #ifdef SHOW_FRAME_HINTS printf("Maximum size specified\n"); #endif //only update the maximums if they are greater than the minimums! if(specified.max_width >= frame->min_width - frame->hspace) { frame->max_height = specified.max_height; frame->max_height += frame->vspace; } if(specified.max_height >= frame->min_height - frame->vspace) { frame->max_width = specified.max_width; frame->max_width += frame->hspace; } } } // #ifdef SHOW_FRAME_HINTS printf("width %d, height %d, min_width %d, max_width %d, min_height %d, max_height %d, x %d, y %d\n" , frame->w, frame->h, frame->min_width, frame->max_width, frame->min_height, frame->max_height , frame->x, frame->y); #endif }
static void center_x_window (MdmWindow *gw, Window w, Window hintwin) { XSizeHints hints; Status status; long ret; int x, y; Window root; unsigned int width, height, border, depth; gboolean can_resize, can_reposition; trap_push (); status = XGetWMNormalHints (wm_disp, hintwin, &hints, &ret); if ( ! status) { trap_pop (); return; } /* allow resizing when PSize is given, just don't allow centering when * PPosition is goven */ can_resize = ! (hints.flags & USSize); can_reposition = ! (hints.flags & USPosition || hints.flags & PPosition); if (can_reposition && ! gw->center) can_reposition = FALSE; if (gw->ignore_size_hints) { can_resize = TRUE; can_reposition = TRUE; } if ( ! can_resize && ! can_reposition) { trap_pop (); return; } XGetGeometry (wm_disp, w, &root, &x, &y, &width, &height, &border, &depth); /* we replace the x,y and width,height with some new values */ if (can_resize) { if (width > mdm_wm_screen.width) width = mdm_wm_screen.width; if (height > mdm_wm_screen.height) height = mdm_wm_screen.height; } if (can_reposition) { /* we wipe the X with some new values */ x = mdm_wm_screen.x + (mdm_wm_screen.width - width)/2; y = mdm_wm_screen.y + (mdm_wm_screen.height - height)/2; if (x < mdm_wm_screen.x) x = mdm_wm_screen.x; if (y < mdm_wm_screen.y) y = mdm_wm_screen.y; } XMoveResizeWindow (wm_disp, w, x, y, width, height); if (gw->center && ! gw->recenter) { gw->center = FALSE; } trap_pop (); }
static MdmWindow * add_window (Window w, gboolean center, gboolean is_mapped) { MdmWindow *gw; gw = find_window (w, FALSE); if (gw == NULL) { XClassHint hint = { NULL, NULL }; XWMHints *wmhints; int x, y; Window root; unsigned int width, height, border, depth; gw = g_new0 (MdmWindow, 1); gw->win = w; windows = g_list_prepend (windows, gw); trap_push (); /* add "centering" */ gw->ignore_size_hints = FALSE; gw->center = center; gw->recenter = FALSE; gw->takefocus = TRUE; gw->ignore_next_map = 0; gw->ignore_next_unmap = 0; wmhints = XGetWMHints (wm_disp, w); if (wmhints != NULL) { /* NoInput windows */ if ((wmhints->flags & InputHint) && ! wmhints->input) { gw->takefocus = FALSE; } XFree (wmhints); } /* hack, set USpos/size on login window */ if (w == wm_login_window) { long ret; XSizeHints hints; XGetWMNormalHints (wm_disp, w, &hints, &ret); hints.flags |= USPosition | USSize; XSetWMNormalHints (wm_disp, w, &hints); gw->center = FALSE; gw->recenter = FALSE; } else if (XGetClassHint (wm_disp, w, &hint)) { if (is_wm_class (&hint, "mdm", 3)) { gw->ignore_size_hints = TRUE; gw->center = TRUE; gw->recenter = TRUE; } else if (is_wm_class (&hint, "gkrellm", 0)) { /* hack, gkrell is stupid and doesn't set * right hints, such as USPosition and other * such stuff */ gw->center = FALSE; gw->recenter = FALSE; } else if (is_wm_class (&hint, "xscribble", 0)) { /* hack, xscribble mustn't take focus */ gw->takefocus = FALSE; } if (hint.res_name != NULL) XFree (hint.res_name); if (hint.res_class != NULL) XFree (hint.res_class); } XGetGeometry (wm_disp, w, &root, &x, &y, &width, &height, &border, &depth); gw->x = x; gw->y = x; center_x_window (gw, w, w); add_deco (gw, is_mapped); XAddToSaveSet (wm_disp, w); trap_pop (); } return gw; }
client_t *new_client(Window w) { client_t *c; XWindowAttributes attr; XColor exact; long supplied; Atom win_type; c = malloc(sizeof *c); c->next = head; head = c; c->name = get_wm_name(w); c->win = w; c->frame = None; c->size.flags = 0; c->ignore_unmap = 0; #ifdef SHAPE c->shaped = 0; #endif c->shaded = 0; c->zoomed = 0; c->decor = 1; XGetWMNormalHints(dpy, c->win, &c->size, &supplied); XGetTransientForHint(dpy, c->win, &c->trans); XGetWindowAttributes(dpy, c->win, &attr); c->geom.x = attr.x; c->geom.y = attr.y; c->geom.w = attr.width; c->geom.h = attr.height; c->cmap = attr.colormap; c->old_bw = attr.border_width; #ifdef DEBUG dump_name(c, "creating", 'w'); dump_geom(c, "initial"); #endif XAllocNamedColor(dpy, c->cmap, opt_fg, &fg, &exact); XAllocNamedColor(dpy, c->cmap, opt_bg, &bg, &exact); XAllocNamedColor(dpy, c->cmap, opt_bd, &bd, &exact); if (get_atoms(c->win, net_wm_wintype, XA_ATOM, 0, &win_type, 1, NULL)) c->decor = HAS_DECOR(win_type); if (get_atoms(c->win, net_wm_desk, XA_CARDINAL, 0, &c->desk, 1, NULL)) { if (c->desk == -1) c->desk = DESK_ALL; /* FIXME */ if (c->desk >= ndesks && c->desk != DESK_ALL) c->desk = cur_desk; } else { set_atoms(c->win, net_wm_desk, XA_CARDINAL, &cur_desk, 1); c->desk = cur_desk; } #ifdef DEBUG dump_info(c); #endif check_states(c); /* We are not actually keeping the stack one in order. However, every * fancy panel uses it and nothing else, no matter what the spec says. * (I'm not sure why, as rearranging the list every time the stacking * changes would be distracting. GNOME's window list applet doesn't.) */ append_atoms(root, net_client_list, XA_WINDOW, &c->win, 1); append_atoms(root, net_client_stack, XA_WINDOW, &c->win, 1); return c; }
static void ResizeScreen(XtermWidget xw,int min_width,int min_height ) { register TScreen *screen = &xw->screen; #ifndef nothack XSizeHints sizehints; long supp; #endif XtGeometryResult geomreqresult; Dimension reqWidth, reqHeight, repWidth, repHeight; /* * I'm going to try to explain, as I understand it, why we * have to do XGetWMNormalHints and XSetWMNormalHints here, * although I can't guarantee that I've got it right. * * In a correctly written toolkit program, the Shell widget * parses the user supplied geometry argument. However, * because of the way xterm does things, the VT100 widget does * the parsing of the geometry option, not the Shell widget. * The result of this is that the Shell widget doesn't set the * correct window manager hints, and doesn't know that the * user has specified a geometry. * * The XtVaSetValues call below tells the Shell widget to * change its hints. However, since it's confused about the * hints to begin with, it doesn't get them all right when it * does the SetValues -- it undoes some of what the VT100 * widget did when it originally set the hints. * * To fix this, we do the following: * * 1. Get the sizehints directly from the window, going around * the (confused) shell widget. * 2. Call XtVaSetValues to let the shell widget know which * hints have changed. Note that this may not even be * necessary, since we're going to right ahead after that * and set the hints ourselves, but it's good to put it * here anyway, so that when we finally do fix the code so * that the Shell does the right thing with hints, we * already have the XtVaSetValues in place. * 3. We set the sizehints directly, this fixing up whatever * damage was done by the Shell widget during the * XtVaSetValues. * * Gross, huh? * * The correct fix is to redo VTRealize, VTInitialize and * VTSetValues so that font processing happens early enough to * give back responsibility for the size hints to the Shell. * * Someday, we hope to have time to do this. Someday, we hope * to have time to completely rewrite xterm. */ #ifndef nothack /* * NOTE: If you change the way any of the hints are calculated * below, make sure you change the calculation both in the * sizehints assignments and in the XtVaSetValues. */ if (! XGetWMNormalHints(screen->display, XtWindow(XtParent(xw)), &sizehints, &supp)) sizehints.flags = 0; sizehints.base_width = min_width; sizehints.base_height = min_height; sizehints.width_inc = FontWidth(screen); sizehints.height_inc = FontHeight(screen); sizehints.min_width = sizehints.base_width + sizehints.width_inc; sizehints.min_height = sizehints.base_height + sizehints.height_inc; sizehints.flags |= (PBaseSize|PMinSize|PResizeInc); /* These are obsolete, but old clients may use them */ sizehints.width = (screen->max_col + 1) * FontWidth(screen) + min_width; sizehints.height = (screen->max_row + 1) * FontHeight(screen) + min_height; #endif /* * Note: width and height are not set here because they are * obsolete. */ XtVaSetValues(XtParent(xw), XtNbaseWidth, min_width, XtNbaseHeight, min_height, XtNwidthInc, FontWidth(screen), XtNheightInc, FontHeight(screen), XtNminWidth, min_width + FontWidth(screen), XtNminHeight, min_height + FontHeight(screen), NULL); reqWidth = (screen->max_col + 1) * FontWidth(screen) + min_width; reqHeight = FontHeight(screen) * (screen->max_row + 1) + min_height; geomreqresult = XtMakeResizeRequest ((Widget)xw, reqWidth, reqHeight, &repWidth, &repHeight); if (geomreqresult == XtGeometryAlmost) { geomreqresult = XtMakeResizeRequest ((Widget)xw, repWidth, repHeight, NULL, NULL); } #ifndef nothack XSetWMNormalHints(screen->display, XtWindow(XtParent(xw)), &sizehints); #endif }
// Read the sizeHints to size_hints object // Returns true if autoplace should be done. bool ICCCM::size_hints(Frame *f) { long supplied; XSizeHints *size_hints = f->size_hints; if(!XGetWMNormalHints(fl_display, f->window(), size_hints, &supplied)) size_hints->flags = 0; if(size_hints->flags & PResizeInc) { if(size_hints->width_inc < 1) size_hints->width_inc = 1; if(size_hints->height_inc < 1) size_hints->height_inc = 1; } else size_hints->width_inc = size_hints->height_inc = 1; if(!(size_hints->flags & PBaseSize)) { if (size_hints->flags & PMinSize) { size_hints->base_width = size_hints->min_width; size_hints->base_height = size_hints->min_height; } else size_hints->base_width = size_hints->base_height = 0; } if(!(size_hints->flags & PMinSize)) { size_hints->min_width = size_hints->base_width; size_hints->min_height = size_hints->base_height; } if(!(size_hints->flags & PMaxSize)) { size_hints->max_width = 32767; size_hints->max_height = 32767; } if (size_hints->min_height <= 0) size_hints->min_height = 1; if (size_hints->min_width <= 0) size_hints->min_width = 1; if(size_hints->max_width<size_hints->min_width || size_hints->max_width<=0) size_hints->max_width = 32767; if(size_hints->max_height<size_hints->min_height || size_hints->max_height<=0) size_hints->max_height = 32767; if(!(size_hints->flags & PWinGravity)) { size_hints->win_gravity = NorthWestGravity; size_hints->flags |= PWinGravity; } if(size_hints->flags & PAspect) { f->set_frame_flag(KEEP_ASPECT); if((size_hints->min_aspect.y > 0.0) && (size_hints->min_aspect.x > 0.0)) { f->aspect_min = ((double)size_hints->min_aspect.x) / ((double)size_hints->min_aspect.y); } else { f->aspect_min = 0.0; } if((size_hints->max_aspect.y > 0.0) && (size_hints->max_aspect.x > 0.0)) { f->aspect_max = ((double)size_hints->max_aspect.x) / ((double)size_hints->max_aspect.y); } else { f->aspect_max = 32767.0; } } else { f->aspect_min = 0.0; f->aspect_max = 32767.0; } // fix for old gimp, which sets PPosition to 0,0: // if(f->x() <= 0 && f->y() <= 0) size_hints->flags &= ~PPosition; return !(size_hints->flags & (USPosition|PPosition)); }
/** *** MakeButton() *** To position subwindows in a button: icons and swallowed windows. **/ void MakeButton(button_info *b) { /* This is resposible for drawing the contents of a button, placing the icon and/or swallowed item in the correct position inside potential padding or frame. */ int ih,iw,ix,iy; XFontStruct *font; if(!b) { fprintf(stderr,"%s: BUG: DrawButton called with NULL pointer\n",MyName); exit(2); } if(b->flags&b_Container) { fprintf(stderr,"%s: BUG: DrawButton called with container\n",MyName); exit(2); } if(!(b->flags&b_Icon) && (buttonSwallowCount(b)<3)) return; font = buttonFont(b); GetInternalSize(b,&ix,&iy,&iw,&ih); /* At this point iw,ih,ix and iy should be correct. Now all we have to do is place title and iconwin in their proper positions */ /* For now, use the old routine in icons.h for buttons with icons */ if(b->flags&b_Icon) ConfigureIconWindow(b); /* For now, hardcoded window centered, title bottom centered, below window */ else if(buttonSwallowCount(b)==3) { long supplied; if(!b->IconWin) { fprintf(stderr,"%s: BUG: Swallowed window has no IconWin\n",MyName); exit(2); } if(b->flags&b_Title && font && !(buttonJustify(b)&b_Horizontal)) ih -= font->ascent+font->descent; b->icon_w=iw; b->icon_h=ih; if(iw>0 && ih>0) { if(!(buttonSwallow(b)&b_NoHints)) { if(!XGetWMNormalHints(Dpy,b->IconWin,b->hints,&supplied)) b->hints->flags=0; ConstrainSize(b->hints,&b->icon_w,&b->icon_h); } XMoveResizeWindow(Dpy,b->IconWin,ix+(iw-b->icon_w)/2, iy+(ih-b->icon_h)/2,b->icon_w,b->icon_h); } else XMoveWindow(Dpy,b->IconWin,2000,2000); } }
void WmPanelistShow (Widget w) { SwitchData * switch_data; Dimension switch_rc_height; Dimension switch_button_height; Dimension width = XtWidth(panel.shell); Dimension height = XtHeight(panel.shell); Position x = XtX(panel.shell); Position y = XtY(panel.shell); Dimension screen_width; Display * display; CompositeWidget cw; Widget * widget_list; DtWmHints vHints; String shell_geometry = NULL; char geometry_buffer[32]; XSizeHints hints; long supplied; int i; Arg al[20]; int ac; /* Find the switch data for later processing */ switch_data = NULL; for (i = 0; i < panel.box_data_count; i++) { if (panel.box_data[i]->switch_data != NULL) { switch_data = panel.box_data[i]->switch_data; break; } } /* Realize the shell so that it is sized properly for later */ /* positioning and child repositioning. */ XtRealizeWidget (panel.shell); /* See if a geometry has been set. */ ac = 0; XtSetArg (al[ac], XmNgeometry, &shell_geometry); ac++; XtGetValues (panel.shell, al, ac); /* If the shell has no default geometry, construct a default */ /* which will center the panel along the bottom of the display */ width = XtWidth (panel.shell); screen_width = WidthOfScreen (XtScreen (panel.shell)); display = XtDisplay (panel.shell); if (shell_geometry == NULL) { Position x; char geometry_buffer[32]; if (panel.element_values[PANEL_GEOMETRY].string_value != NULL) { shell_geometry = panel.element_values[PANEL_GEOMETRY].parsed_value; } else { x = (screen_width > width) ? (Position)(screen_width - width) / 2 : 0; sprintf (geometry_buffer, "+%d-0", x); shell_geometry = geometry_buffer; } XtSetArg (al[0], XmNgeometry, shell_geometry); XtSetValues (panel.shell, al, 1); } /* Adjust the positions of the buttons within the switch */ /* so that they are spaced nicely. */ if (switch_data != NULL) { UpdateSwitchGeometry (switch_data->box_data); /* Reposition or adjust the front panel if it is either off */ /* the right edge of the screen or larger than the screen */ if (width > screen_width) { Arg al[1]; while (width > screen_width && panel.switch_row_count < switch_data->switch_count) { panel.switch_row_count++; XtSetArg (al[0], XmNnumColumns, panel.switch_row_count); XtSetValues (switch_data->rc, al, 1); width = XtWidth (panel.shell); } } } SetGeometry (panel.shell, shell_geometry, &x, &y); WorkspaceAdjustPanelPosition (x, y, XtWidth (panel.shell), XtHeight (panel.shell)); /* Set hints to avoid interactive placement */ if (XGetWMNormalHints(display, XtWindow(panel.shell), &hints, &supplied) != 0) { hints.flags |= USPosition|USSize; XSetWMNormalHints(display, XtWindow(panel.shell), &hints); } /* Set the shells icon and title for when it is minimized */ if (switch_data != NULL) { int current_workspace = switch_data->active_switch; XtSetArg (al[0], XmNiconName, switch_data->switch_names[current_workspace]); XtSetArg (al[1], XmNtitle, switch_data->switch_names[current_workspace]); XtSetValues (panel.shell, al, 2); } /* Set panel's window manager hints. */ vHints.flags = DtWM_HINTS_BEHAVIORS; vHints.behaviors = DtWM_BEHAVIOR_PANEL; _DtWsmSetDtWmHints (XtDisplay(panel.shell), XtWindow (panel.shell), &vHints); /* Set the subpanel's transientShell to update transientFor and */ /* Set the subpanel hints. */ vHints.behaviors |= DtWM_BEHAVIOR_SUBPANEL; vHints.flags |= DtWM_HINTS_ATTACH_WINDOW; vHints.attachWindow = XtWindow (panel.shell); for (i = 0, widget_list = M_PopupList (panel.shell); i < M_NumPopups (panel.shell); i++) { cw = (CompositeWidget) widget_list[i]; ac = 0; XtSetArg (al[ac], XmNtransientFor, NULL); ac++; XtSetValues ((Widget) cw, al, ac); ac = 0; XtSetArg (al[ac], XmNtransientFor, panel.shell); ac++; XtSetValues ((Widget) cw, al, ac); if (M_NumChildren (cw) > 0) { XtRealizeWidget ((M_Children (cw))[0]); _DtWsmSetDtWmHints (XtDisplay (panel.shell), XtWindow (widget_list[i]), &vHints); } } /* Set the push recall list and count into the window manager's */ /* screen global data. */ PushRecallSetData (); /* Set up the callback ot the workspace management API for */ /* catching changes in workspace configuration. */ DtWsmAddWorkspaceModifiedCallback(panel.shell, WorkspaceModifyCB, (XtPointer)switch_data); /* Get the front panel displayed */ XtSetMappedWhenManaged (panel.shell, True); XtPopup (panel.shell, XtGrabNone); /* Restore the session information */ SessionRestoreData (); /* Set up the window and geometry information for the embedded clients */ for (i = 0; i < panel.embedded_client_count; i++) EmbeddedClientSetGeometry (&(((WmFpEmbeddedClientList) panel.embedded_client_list)[i])); /* Set the embedded client list and count into the window manager's */ /* screen global data. */ EmbeddedClientSetData (); }