void MainLoop() override { bool fullscreen = SConfig::GetInstance().m_LocalCoreStartupParameter.bFullscreen; if (fullscreen) { X11Utils::ToggleFullscreen(dpy, win); #if defined(HAVE_XRANDR) && HAVE_XRANDR XRRConfig->ToggleDisplayMode(True); #endif } // The actual loop while (running) { XEvent event; KeySym key; for (int num_events = XPending(dpy); num_events > 0; num_events--) { XNextEvent(dpy, &event); switch (event.type) { case KeyPress: key = XLookupKeysym((XKeyEvent*)&event, 0); if (key == XK_Escape) { if (Core::GetState() == Core::CORE_RUN) { if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor) XUndefineCursor(dpy, win); Core::SetState(Core::CORE_PAUSE); } else { if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor) XDefineCursor(dpy, win, blankCursor); Core::SetState(Core::CORE_RUN); } } else if ((key == XK_Return) && (event.xkey.state & Mod1Mask)) { fullscreen = !fullscreen; X11Utils::ToggleFullscreen(dpy, win); #if defined(HAVE_XRANDR) && HAVE_XRANDR XRRConfig->ToggleDisplayMode(fullscreen); #endif } else if (key >= XK_F1 && key <= XK_F8) { int slot_number = key - XK_F1 + 1; if (event.xkey.state & ShiftMask) State::Save(slot_number); else State::Load(slot_number); } else if (key == XK_F9) Core::SaveScreenShot(); else if (key == XK_F11) State::LoadLastSaved(); else if (key == XK_F12) { if (event.xkey.state & ShiftMask) State::UndoLoadState(); else State::UndoSaveState(); } break; case FocusIn: rendererHasFocus = true; if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor && Core::GetState() != Core::CORE_PAUSE) XDefineCursor(dpy, win, blankCursor); break; case FocusOut: rendererHasFocus = false; if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor) XUndefineCursor(dpy, win); break; case ClientMessage: if ((unsigned long) event.xclient.data.l[0] == XInternAtom(dpy, "WM_DELETE_WINDOW", False)) running = false; break; } } if (!fullscreen) { Window winDummy; unsigned int borderDummy, depthDummy; XGetGeometry(dpy, win, &winDummy, &SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowXPos, &SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowYPos, (unsigned int *)&SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowWidth, (unsigned int *)&SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowHeight, &borderDummy, &depthDummy); } usleep(100000); } }
GLboolean stubMakeCurrent( WindowInfo *window, ContextInfo *context ) { GLboolean retVal; /* * Get WindowInfo and ContextInfo pointers. */ if (!context || !window) { ContextInfo * currentContext = stubGetCurrentContext(); if (currentContext) currentContext->currentDrawable = NULL; if (context) context->currentDrawable = NULL; stubSetCurrentContext(NULL); return GL_TRUE; /* OK */ } #ifdef CHROMIUM_THREADSAFE stubCheckMultithread(); #endif if (context->type == UNDECIDED) { /* Here's where we really create contexts */ #ifdef CHROMIUM_THREADSAFE crLockMutex(&stub.mutex); #endif if (stubCheckUseChromium(window)) { /* * Create a Chromium context. */ #if defined(GLX) || defined(DARWIN) GLint spuShareCtx = context->share ? context->share->spuContext : 0; #else GLint spuShareCtx = 0; #endif GLint spuConnection = 0; CRASSERT(stub.spu); CRASSERT(stub.spu->dispatch_table.CreateContext); context->type = CHROMIUM; #if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST) if (context->pHgsmi) { spuConnection = stub.spu->dispatch_table.VBoxConCreate(context->pHgsmi); if (!spuConnection) { crWarning("VBoxConCreate failed"); return GL_FALSE; } context->spuConnection = spuConnection; } #endif context->spuContext = stub.spu->dispatch_table.VBoxCreateContext(spuConnection, context->dpyName, context->visBits, spuShareCtx); if (window->spuWindow == -1) { /*crDebug("(1)stubMakeCurrent ctx=%p(%i) window=%p(%i)", context, context->spuContext, window, window->spuWindow);*/ window->spuWindow = stub.spu->dispatch_table.VBoxWindowCreate( spuConnection, window->dpyName, context->visBits ); #ifdef CR_NEWWINTRACK window->u32ClientID = stub.spu->dispatch_table.VBoxPackGetInjectID(spuConnection); #endif } } else { /* * Create a native OpenGL context. */ if (!InstantiateNativeContext(window, context)) { #ifdef CHROMIUM_THREADSAFE crUnlockMutex(&stub.mutex); #endif return 0; /* false */ } context->type = NATIVE; } #ifdef CHROMIUM_THREADSAFE crUnlockMutex(&stub.mutex); #endif } if (context->type == NATIVE) { /* * Native OpenGL MakeCurrent(). */ #ifdef WINDOWS retVal = (GLboolean) stub.wsInterface.wglMakeCurrent( window->drawable, context->hglrc ); #elif defined(Darwin) // XXX \todo We need to differentiate between these two.. retVal = ( stub.wsInterface.CGLSetSurface(context->cglc, window->connection, window->drawable, window->surface) == noErr ); retVal = ( stub.wsInterface.CGLSetCurrentContext(context->cglc) == noErr ); #elif defined(GLX) retVal = (GLboolean) stub.wsInterface.glXMakeCurrent( window->dpy, window->drawable, context->glxContext ); #endif } else { /* * SPU chain MakeCurrent(). */ CRASSERT(context->type == CHROMIUM); CRASSERT(context->spuContext >= 0); /*if (context->currentDrawable && context->currentDrawable != window) crDebug("Rebinding context %p to a different window", context);*/ if (window->type == NATIVE) { crWarning("Can't rebind a chromium context to a native window\n"); retVal = 0; } else { if (window->spuWindow == -1) { /*crDebug("(2)stubMakeCurrent ctx=%p(%i) window=%p(%i)", context, context->spuContext, window, window->spuWindow);*/ window->spuWindow = stub.spu->dispatch_table.VBoxWindowCreate( #if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST) context->spuConnection, #else 0, #endif window->dpyName, context->visBits ); #ifdef CR_NEWWINTRACK window->u32ClientID = stub.spu->dispatch_table.VBoxPackGetInjectID( # if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST) context->spuConnection # else 0 # endif ); #endif if (context->currentDrawable && context->currentDrawable->type==CHROMIUM && context->currentDrawable->pOwner==context) { #ifdef WINDOWS if (context->currentDrawable->hWnd!=WindowFromDC(context->currentDrawable->drawable)) { stubDestroyWindow(CR_CTX_CON(context), (GLint)context->currentDrawable->hWnd); } #else Window root; int x, y; unsigned int border, depth, w, h; XLOCK(context->currentDrawable->dpy); if (!XGetGeometry(context->currentDrawable->dpy, context->currentDrawable->drawable, &root, &x, &y, &w, &h, &border, &depth)) { stubDestroyWindow(CR_CTX_CON(context), (GLint)context->currentDrawable->drawable); } XUNLOCK(context->currentDrawable->dpy); #endif } } if (window->spuWindow != (GLint)window->drawable) stub.spu->dispatch_table.MakeCurrent( window->spuWindow, (GLint) window->drawable, context->spuContext ); else stub.spu->dispatch_table.MakeCurrent( window->spuWindow, 0, /* native window handle */ context->spuContext ); retVal = 1; } } window->type = context->type; window->pOwner = context; context->currentDrawable = window; stubSetCurrentContext(context); if (retVal) { /* Now, if we've transitions from Chromium to native rendering, or * vice versa, we have to change all the OpenGL entrypoint pointers. */ if (context->type == NATIVE) { /* Switch to native API */ /*printf(" Switching to native API\n");*/ stubSetDispatch(&stub.nativeDispatch); } else if (context->type == CHROMIUM) { /* Switch to stub (SPU) API */ /*printf(" Switching to spu API\n");*/ stubSetDispatch(&stub.spuDispatch); } else { /* no API switch needed */ } } if (!window->width && window->type == CHROMIUM) { /* One time window setup */ int x, y; unsigned int winW, winH; stubGetWindowGeometry( window, &x, &y, &winW, &winH ); /* If we're not using GLX/WGL (no app window) we'll always get * a width and height of zero here. In that case, skip the viewport * call since we're probably using a tilesort SPU with fake_window_dims * which the tilesort SPU will use for the viewport. */ window->width = winW; window->height = winH; #if defined(WINDOWS) && defined(VBOX_WITH_WDDM) if (stubIsWindowVisible(window)) #endif { if (stub.trackWindowSize) stub.spuDispatch.WindowSize( window->spuWindow, winW, winH ); if (stub.trackWindowPos) stub.spuDispatch.WindowPosition(window->spuWindow, x, y); if (winW > 0 && winH > 0) stub.spu->dispatch_table.Viewport( 0, 0, winW, winH ); } #ifdef VBOX_WITH_WDDM stub.spu->dispatch_table.WindowVisibleRegion(window->spuWindow, 0, NULL); #endif } /* Update window mapping state. * Basically, this lets us hide render SPU windows which correspond * to unmapped application windows. Without this, "pertly" (for example) * opens *lots* of temporary windows which otherwise clutter the screen. */ if (stub.trackWindowVisibility && window->type == CHROMIUM && window->drawable) { const int mapped = stubIsWindowVisible(window); if (mapped != window->mapped) { crDebug("Dispatched: WindowShow(%i, %i)", window->spuWindow, mapped); stub.spu->dispatch_table.WindowShow(window->spuWindow, mapped); window->mapped = mapped; } } return retVal; }
CoglHandle cogl_texture_pixmap_x11_new (guint32 pixmap, gboolean automatic_updates) { CoglTexturePixmapX11 *tex_pixmap = g_new (CoglTexturePixmapX11, 1); Display *display = _cogl_xlib_get_display (); Window pixmap_root_window; int pixmap_x, pixmap_y; unsigned int pixmap_border_width; CoglTexture *tex = COGL_TEXTURE (tex_pixmap); XWindowAttributes window_attributes; _COGL_GET_CONTEXT (ctxt, COGL_INVALID_HANDLE); _cogl_texture_init (tex, &cogl_texture_pixmap_x11_vtable); tex_pixmap->pixmap = pixmap; tex_pixmap->image = NULL; tex_pixmap->shm_info.shmid = -1; tex_pixmap->tex = COGL_INVALID_HANDLE; tex_pixmap->damage_owned = FALSE; tex_pixmap->damage = 0; if (!XGetGeometry (display, pixmap, &pixmap_root_window, &pixmap_x, &pixmap_y, &tex_pixmap->width, &tex_pixmap->height, &pixmap_border_width, &tex_pixmap->depth)) { g_free (tex_pixmap); g_warning ("Unable to query pixmap size"); return COGL_INVALID_HANDLE; } /* We need a visual to use for shared memory images so we'll query it from the pixmap's root window */ if (!XGetWindowAttributes (display, pixmap_root_window, &window_attributes)) { g_free (tex_pixmap); g_warning ("Unable to query root window attributes"); return COGL_INVALID_HANDLE; } tex_pixmap->visual = window_attributes.visual; /* If automatic updates are requested and the Xlib connection supports damage events then we'll register a damage object on the pixmap */ if (automatic_updates && ctxt->winsys.damage_base >= 0) { Damage damage = XDamageCreate (display, pixmap, XDamageReportBoundingBox); set_damage_object_internal (tex_pixmap, damage, COGL_TEXTURE_PIXMAP_X11_DAMAGE_BOUNDING_BOX); tex_pixmap->damage_owned = TRUE; } /* Assume the entire pixmap is damaged to begin with */ tex_pixmap->damage_rect.x1 = 0; tex_pixmap->damage_rect.x2 = tex_pixmap->width; tex_pixmap->damage_rect.y1 = 0; tex_pixmap->damage_rect.y2 = tex_pixmap->height; #ifdef COGL_HAS_GLX_SUPPORT try_create_glx_pixmap (tex_pixmap, FALSE); tex_pixmap->glx_tex = COGL_INVALID_HANDLE; tex_pixmap->bind_tex_image_queued = TRUE; tex_pixmap->use_glx_texture = FALSE; #endif return _cogl_texture_pixmap_x11_handle_new (tex_pixmap); }
void sizeSelectTypeCb( Widget w, XtPointer client_data, XtPointer call_data) { Widget option_menu = sizeSelectOptionMenu; /* for testing option menu */ int numChildren; Widget button, *children; int xpos, ypos; WlzUInt height, width, borderWidth, depth; Dimension gHeight, thickness; Pixmap pixmap; Window root; Status status; XmFontList fl; XFontStruct *font; /* some code here to pick apart the option menu */ if((button = XtNameToWidget(option_menu, "*xmCascadeButtonGadget"))){ fprintf(stderr, "CascadeButtonGadget found\n"); } if((button = XtNameToWidget(option_menu, "*xmCascadeButton"))){ fprintf(stderr, "CascadeButton found\n"); } XtVaGetValues(option_menu, XmNnumChildren, &numChildren, XmNchildren, &children, XmNmarginHeight, &gHeight, NULL); fprintf(stderr, "option_menu: %d children\n", numChildren); fprintf(stderr, "option_menu: marginHeight: %d\n", gHeight); fprintf(stderr, "child[0]: %s\n", XtName(children[0])); fprintf(stderr, "child[1]: %s\n", XtName(children[1])); fprintf(stderr, "OptionButton is %s\n", XtIsWidget(children[1])? "Widget":"Gadget"); if( XtClass(children[1]) == xmCascadeButtonGadgetClass ){ fprintf(stderr, "CascadeButtonGadget found\n"); } XtVaGetValues(children[1], XmNheight, &gHeight, XmNlabelPixmap, &pixmap, XmNfontList, &fl, XmNshadowThickness, &thickness, NULL); fprintf(stderr, "OptionButton: height: %d\n", gHeight); fprintf(stderr, "OptionButton: cascadePixmap: Ox%x\n", (unsigned int) pixmap); if( fl ){ XmeRenderTableGetDefaultFont(fl, &font); /* _XmFontListGetDefaultFont(fl, &font);*/ fprintf(stderr, "font hieghts: %d, %d\n", font->ascent, font->descent); } fprintf(stderr, "OptionButton: shadowThickness: %d\n", thickness); switch(status = XGetGeometry(globals.dpy, pixmap, &root, &xpos, &ypos, &width, &height, &borderWidth, &depth)){ case BadDrawable: fprintf(stderr, "returns BadDrawable\n"); break; case BadWindow: fprintf(stderr, "returns BadWindow\n"); break; default: fprintf(stderr, "returns %d\n", status); break; } fprintf(stderr, "OptionButton pixmap: %d, %d, %d, %d, %d, %d\n", xpos, ypos, width, height, borderWidth, depth); XtVaSetValues(children[0], XmNheight, 20, NULL); XtVaSetValues(children[1], XmNheight, 20, NULL); XtVaSetValues(option_menu, XmNheight, 26, NULL); return; }
/** * Callback called by crHashTableWalk() below. * Used to create viewer-side windows for all the application windows. */ static void replicatespuReplicateWindow(unsigned long key, void *data1, void *data2) { ThreadInfo *thread = (ThreadInfo *) data2; WindowInfo *winInfo = (WindowInfo *) data1; GLint window = 0; GLint writeback = 1; Window root; int x, y; unsigned int width, height, bw, d; GLboolean unviewable = GL_FALSE; XWindowAttributes winAtt; CRASSERT(NewServerIndex >= 0); /* clear this flag, in case it was still set from an old connection */ winInfo->writeback[NewServerIndex] = 0; /** * Get application window's attributes */ old_xerror_handler = XSetErrorHandler( x11_error_handler ); XSync(replicate_spu.glx_display, 0); XGetGeometry(replicate_spu.glx_display, (Window)winInfo->nativeWindow, &root, &x, &y, &width, &height, &bw, &d ); XGetWindowAttributes(replicate_spu.glx_display, (Window) winInfo->nativeWindow, &winAtt); XSetErrorHandler( old_xerror_handler ); if (!caught_x11_error) { unviewable = (winAtt.map_state == IsUnviewable); } caught_x11_error = 0; /* * Create the server-side window */ if (replicate_spu.swap) crPackWindowCreateSWAP( replicate_spu.dpyName, winInfo->visBits, &window, &writeback); else crPackWindowCreate( replicate_spu.dpyName, winInfo->visBits, &window, &writeback); replicatespuFlushOne(thread, NewServerIndex); /* Get return value */ while (writeback) { crNetRecv(); } if (replicate_spu.swap) window = (GLint) SWAP32(window); /* save the server-side window ID */ winInfo->id[NewServerIndex] = window; crDebug("Replicate SPU: created server-side window %d", window); if (window < 0) { crWarning("Replicate SPU: failed to create server-side window"); return; } XVncChromiumMonitor(replicate_spu.glx_display, window, winInfo->nativeWindow); /* * If the app window is not visible, hide the server-side window too. */ if (unviewable) { if (replicate_spu.swap) crPackWindowShowSWAP( window, GL_FALSE ); else crPackWindowShow( window, GL_FALSE ); replicatespuFlushOne(thread, NewServerIndex); } }
void on_change_systray(void *obj) { if (systray_profile) fprintf(stderr, "[%f] %s:%d\n", profiling_get_time(), __FUNCTION__, __LINE__); if (systray.icons_per_column == 0 || systray.icons_per_row == 0) return; // systray.area.posx/posy are computed by rendering engine. // Based on this we calculate the positions of the tray icons. Panel *panel = systray.area.panel; int posx, posy; int start = panel->area.bg->border.width + panel->area.paddingy + systray.area.bg->border.width + systray.area.paddingy + systray.margin / 2; if (panel_horizontal) { posy = start; posx = systray.area.posx + systray.area.bg->border.width + systray.area.paddingxlr; } else { posx = start; posy = systray.area.posy + systray.area.bg->border.width + systray.area.paddingxlr; } TrayWindow *traywin; GSList *l; int i; for (i = 1, l = systray.list_icons; l; i++, l = l->next) { traywin = (TrayWindow *)l->data; traywin->y = posy; traywin->x = posx; if (systray_profile) fprintf(stderr, "%s:%d win = %lu (%s), parent = %lu, x = %d, y = %d\n", __FUNCTION__, __LINE__, traywin->win, traywin->name, traywin->parent, posx, posy); traywin->width = systray.icon_size; traywin->height = systray.icon_size; if (panel_horizontal) { if (i % systray.icons_per_column) { posy += systray.icon_size + systray.area.paddingx; } else { posy = start; posx += (systray.icon_size + systray.area.paddingx); } } else { if (i % systray.icons_per_row) { posx += systray.icon_size + systray.area.paddingx; } else { posx = start; posy += (systray.icon_size + systray.area.paddingx); } } // position and size the icon window unsigned int border_width; int xpos, ypos; unsigned int width, height, depth; Window root; if (!XGetGeometry(server.display, traywin->parent, &root, &xpos, &ypos, &width, &height, &border_width, &depth)) { fprintf(stderr, RED "Couldn't get geometry of window!" RESET "\n"); } if (width != traywin->width || height != traywin->height || xpos != traywin->x || ypos != traywin->y) { if (systray_profile) fprintf(stderr, "XMoveResizeWindow(server.display, traywin->parent = %ld, traywin->x = %d, traywin->y = %d, " "traywin->width = %d, traywin->height = %d)\n", traywin->parent, traywin->x, traywin->y, traywin->width, traywin->height); XMoveResizeWindow(server.display, traywin->parent, traywin->x, traywin->y, traywin->width, traywin->height); } if (!traywin->reparented) reparent_icon(traywin); } refresh_systray = TRUE; }
/** * gdk_gl_pixmap_new: * @glconfig: a #GdkGLConfig. * @pixmap: the #GdkPixmap to be used as the rendering area. * @attrib_list: this must be set to NULL or empty (first attribute of None). * * Creates an off-screen rendering area. * attrib_list is currently unused. This must be set to NULL or empty * (first attribute of None). See GLX 1.3 spec. * * Return value: the new #GdkGLPixmap. **/ GdkGLPixmap * gdk_gl_pixmap_new (GdkGLConfig *glconfig, GdkPixmap *pixmap, const int *attrib_list) { GdkGLPixmap *glpixmap; GdkGLPixmapImplX11 *impl; Display *xdisplay; XVisualInfo *xvinfo; Pixmap xpixmap; GLXPixmap glxpixmap; Window root_return; int x_return, y_return; unsigned int width_return, height_return; unsigned int border_width_return; unsigned int depth_return; GdkGL_GLX_MESA_pixmap_colormap *mesa_ext; GDK_GL_NOTE_FUNC (); g_return_val_if_fail (GDK_IS_GL_CONFIG_IMPL_X11 (glconfig), NULL); g_return_val_if_fail (GDK_IS_PIXMAP (pixmap), NULL); xdisplay = GDK_GL_CONFIG_XDISPLAY (glconfig); xvinfo = GDK_GL_CONFIG_XVINFO (glconfig); /* * Get X Pixmap. */ xpixmap = GDK_DRAWABLE_XID (GDK_DRAWABLE (pixmap)); /* * Check depth of the X pixmap. */ if (!XGetGeometry (xdisplay, xpixmap, &root_return, &x_return, &y_return, &width_return, &height_return, &border_width_return, &depth_return)) return NULL; if (depth_return != (unsigned int) xvinfo->depth) return NULL; /* * Create GLXPixmap. */ mesa_ext = gdk_gl_get_GLX_MESA_pixmap_colormap (glconfig); if (mesa_ext) { /* If GLX_MESA_pixmap_colormap is supported. */ GDK_GL_NOTE_FUNC_IMPL ("glXCreateGLXPixmapMESA"); glxpixmap = mesa_ext->glXCreateGLXPixmapMESA (xdisplay, xvinfo, xpixmap, GDK_GL_CONFIG_XCOLORMAP (glconfig)); } else { GDK_GL_NOTE_FUNC_IMPL ("glXCreateGLXPixmap"); glxpixmap = glXCreateGLXPixmap (xdisplay, xvinfo, xpixmap); } if (glxpixmap == None) return NULL; /* * Instantiate the GdkGLPixmapImplX11 object. */ glpixmap = g_object_new (GDK_TYPE_GL_PIXMAP_IMPL_X11, NULL); impl = GDK_GL_PIXMAP_IMPL_X11 (glpixmap); glpixmap->drawable = GDK_DRAWABLE (pixmap); g_object_add_weak_pointer (G_OBJECT (glpixmap->drawable), (gpointer *) &(glpixmap->drawable)); impl->glxpixmap = glxpixmap; impl->glconfig = glconfig; g_object_ref (G_OBJECT (impl->glconfig)); impl->is_destroyed = FALSE; return glpixmap; }
void xopenw ( char win_name[], int win_index, float xsize, float ysize, int *ixsize, int *iysize, int *iret ) /************************************************************************ * xopenw * * * * This subroutine opens one xw window and sets the initial * * graphics context along with basic window attributes. * * * * xopenw ( win_name, win_index, xsize, ysize, ixsize, iysize, iret ) * * * * Input parameters: * * win_name[] char window name * * win_index int window index * * xsize float Right edge of window * * ysize float Bottom edge of window * * * * Output parameters: * * *ixsize int Right edge of window * * *iysize int Bottom edge of window * * *iret int Return code * * G_NORMAL = normal return * ** * * Log: * * A. Hardy/GSC 2/01 Copied from the XW driver and * * removed size limitations * ***********************************************************************/ { int dhght, dwdth, gemscreen, xpos, ypos, ier; unsigned int xwdth, xhght, xbord, xdpth; char gemname [WNAME_LEN]; Cursor curs; Window gwin; GC gemgc; XGCValues values; XSizeHints gemhint; XSetWindowAttributes gemxswa; XColor cred; Window_str *cwin; winloop_t *cloop; /*---------------------------------------------------------------------*/ *iret = G_NORMAL; current_window = win_index; cwin = &(gemwindow[current_window]); cloop = &(cwin->loop[cwin->curr_loop]); strcpy(cwin->name, win_name); strcpy(gemname, win_name); gemscreen = DefaultScreen( (XtPointer)gemdisplay ); /* * Determine window height and width. */ dwdth = DisplayWidth( (XtPointer)gemdisplay, gemscreen ); dhght = DisplayHeight( (XtPointer)gemdisplay, gemscreen ); if ( G_ABS ( xsize - RMISSD ) < RDIFFD ) gemhint.width = 0.7 * (float) dwdth ; else if ( ( xsize > 0.0 ) && ( xsize <= 1.0 ) ) gemhint.width = (float) dwdth * xsize ; else if ( xsize < 100.0 ) gemhint.width = 100 ; else gemhint.width = (int) xsize ; if ( G_ABS ( ysize - RMISSD ) < RDIFFD ) gemhint.height = 0.7 * (float) dhght ; else if ( ( ysize > 0.0 ) && ( ysize <= 1.0 ) ) gemhint.height = (float) dhght * ysize ; else if ( ysize < 100.0 ) gemhint.height = 100 ; else gemhint.height = (int) ysize ; if ( gemhint.width < 100 ) gemhint.width = 100 ; if ( gemhint.height < 100 ) gemhint.height = 100 ; /* * Determine window location. */ gemhint.x = dwdth - ( gemhint.width ) - ( current_window * 30 ) - 20; if ( gemhint.x < 0 ) gemhint.x = 0; gemhint.y = ( current_window * 30 ); gemhint.flags = USPosition | USSize; /* * Create the window and set standard properties and attributes. */ gwin = XCreateSimpleWindow( gemdisplay, root, gemhint.x, gemhint.y, gemhint.width, gemhint.height, 5, WhitePixel ( (XtPointer)gemdisplay, gemscreen ), BlackPixel ( (XtPointer)gemdisplay, gemscreen ) ); cwin->window = gwin; XSetStandardProperties( gemdisplay, gwin, gemname, gemname, None, NULL, 0, &gemhint ); gemxswa.bit_gravity = CenterGravity; XChangeWindowAttributes (gemdisplay, gwin, (CWBitGravity), &gemxswa ); /* * Get the geometry and window size information. */ XGetGeometry( gemdisplay, gwin, &root, &xpos, &ypos, &xwdth, &xhght, &xbord, &xdpth ); cwin->width = xwdth; cwin->height = xhght; cwin->depth = xdpth; /* * Create graphics contexts. */ gemgc = XCreateGC( gemdisplay, gwin, 0, 0 ); /* * Turn of NoExpose and GraphicsExpose events. They * don't seem to be needed and were causing many events * to seen in xxevent(). */ values.graphics_exposures = False; XChangeGC( gemdisplay, gemgc, GCGraphicsExposures, &values); cwin->gc = gemgc; /* * Set backgound colors. */ XSetBackground( gemdisplay, gemgc, BlackPixel ( (XtPointer)gemdisplay, gemscreen ) ) ; /* * Set fill rule. */ XSetFillRule ( gemdisplay, gemgc, EvenOddRule ); /* * Create one pixmap. */ cwin->pxms[cwin->curr_loop][0] = XCreatePixmap(gemdisplay, root, xwdth, xhght, xdpth); cwin->curpxm[cwin->curr_loop] = 0; cloop->pxm_wdth = xwdth; cloop->pxm_hght = xhght; cloop->roamflg = 0; cloop->xoffset = 0; cloop->yoffset = 0; cloop->pxm_x = 0; cloop->pxm_y = 0; cwin->area_w = xwdth; cwin->area_h = xhght; cwin->win_x = 0; cwin->win_y = 0; /* * return device size */ *ixsize = xwdth; *iysize = xhght; /* * clear the pixmap, */ xclrpxm(&(cwin->curpxm[cwin->curr_loop]), &ier); /* * Select the events to be processed. */ XSelectInput ( gemdisplay, gwin, ExposureMask ); /* * Set the cursor to be the customary red arrow. */ curs = XCreateFontCursor ( gemdisplay, XC_top_left_arrow ); XDefineCursor ( gemdisplay, gwin, curs ); cred.red = 65535; cred.blue = 0; cred.green = 0; cred.flags = DoRed | DoBlue | DoGreen; XRecolorCursor ( gemdisplay, curs, &cred, &cred ); }
void systray_render_icon(void *t) { TrayWindow *traywin = t; if (systray_profile) fprintf(stderr, "[%f] %s:%d win = %lu (%s)\n", profiling_get_time(), __FUNCTION__, __LINE__, traywin->win, traywin->name); if (!traywin->reparented || !traywin->embedded) { if (systray_profile) fprintf(stderr, YELLOW "[%f] %s:%d win = %lu (%s) delaying rendering" RESET "\n", profiling_get_time(), __FUNCTION__, __LINE__, traywin->win, traywin->name); stop_timeout(traywin->render_timeout); traywin->render_timeout = add_timeout(min_refresh_period, 0, systray_render_icon, traywin, &traywin->render_timeout); return; } if (systray_composited) { XSync(server.display, False); error = FALSE; XErrorHandler old = XSetErrorHandler(window_error_handler); unsigned int border_width; int xpos, ypos; unsigned int width, height, depth; Window root; if (!XGetGeometry(server.display, traywin->win, &root, &xpos, &ypos, &width, &height, &border_width, &depth)) { stop_timeout(traywin->render_timeout); if (!traywin->resize_timeout) traywin->render_timeout = add_timeout(min_refresh_period, 0, systray_render_icon, traywin, &traywin->render_timeout); systray_render_icon_from_image(traywin); XSetErrorHandler(old); return; } else { if (xpos != 0 || ypos != 0 || width != traywin->width || height != traywin->height) { stop_timeout(traywin->render_timeout); if (!traywin->resize_timeout) traywin->render_timeout = add_timeout(min_refresh_period, 0, systray_render_icon, traywin, &traywin->render_timeout); systray_render_icon_from_image(traywin); if (systray_profile) fprintf(stderr, YELLOW "[%f] %s:%d win = %lu (%s) delaying rendering" RESET "\n", profiling_get_time(), __FUNCTION__, __LINE__, traywin->win, traywin->name); XSetErrorHandler(old); return; } } XSetErrorHandler(old); } if (systray_profile) fprintf(stderr, "rendering tray icon\n"); if (systray_composited) { systray_render_icon_composited(traywin); } else { // Trigger window repaint if (systray_profile) fprintf(stderr, "XClearArea(server.display, traywin->parent = %ld, 0, 0, traywin->width, traywin->height, True)\n", traywin->parent); XClearArea(server.display, traywin->parent, 0, 0, 0, 0, True); if (systray_profile) fprintf(stderr, "XClearArea(server.display, traywin->win = %ld, 0, 0, traywin->width, traywin->height, True)\n", traywin->win); XClearArea(server.display, traywin->win, 0, 0, 0, 0, True); } }
/* Doesn't handle HIPPO_WINDOW_STATE_ACTIVE - see comment below */ static HippoWindowState get_window_state(Display *display, Window window) { HippoWindowState result = HIPPO_WINDOW_STATE_HIDDEN; XWindowAttributes window_attributes; GdkRectangle rect; GdkRegion *visible_region = NULL; Window child = None; Window root; Window parent; Window *children = NULL; guint n_children; gdk_error_trap_push(); /* First check if the window and all ancestors are mapped */ if (!XGetWindowAttributes(display, window, &window_attributes)) { g_debug("XGetWindowAttributes failed\n"); goto out; } if (window_attributes.map_state != IsViewable) goto out; /* Get the area of the window in parent coordinates */ rect.x = window_attributes.x; rect.y = window_attributes.y; rect.width = window_attributes.width; rect.height = window_attributes.height; visible_region = gdk_region_rectangle(&rect); if (!XQueryTree(display, window, &root, &parent, &children, &n_children)) { g_debug("XQueryTree failed\n"); goto out; } XFree(children); children = NULL; child = window; window = parent; /* Walk up the hierarchy, clipping to parents, and subtracting * overlayed siblings (yuck!) */ while (TRUE) { GdkRegion *parent_region; gboolean seen_child = FALSE; int x, y; unsigned int width, height, border, depth; unsigned int i; gdk_region_get_clipbox(visible_region, &rect); /* Clip to parent */ if (!XGetGeometry(display, window, &root, &x, &y, &width, &height, &border, &depth)) { g_debug("XGetGeometry failed\n"); goto out; } rect.x = 0; rect.y = 0; rect.width = width; rect.height= height; parent_region = gdk_region_rectangle(&rect); gdk_region_intersect(visible_region, parent_region); gdk_region_destroy(parent_region); if (gdk_region_empty(visible_region)) goto out; if (!XQueryTree(display, window, &root, &parent, &children, &n_children)) { g_debug("XQueryTree failed\n"); goto out; } for (i = 0; i < n_children; i++) { if (seen_child) { /* A sibling above */ GdkRegion *child_region; XWindowAttributes child_attributes; if (!XGetWindowAttributes(display, children[i], &child_attributes)) { g_debug("XGetWindowAttributes failed for child\n"); goto out; } if (child_attributes.map_state == IsViewable) { rect.x = child_attributes.x - child_attributes.border_width; rect.y = child_attributes.y - child_attributes.border_width; rect.width = child_attributes.width + 2 * child_attributes.border_width; rect.height = child_attributes.height + 2 * child_attributes.border_width; child_region = gdk_region_rectangle(&rect); gdk_region_subtract(visible_region, child_region); gdk_region_destroy(child_region); if (gdk_region_empty(visible_region)) goto out; } } else if (children[i] == child) { seen_child = TRUE; } } XFree(children); children = NULL; if (window == root) break; child = window; window = parent; /* Translate to parent coordinates */ gdk_region_offset(visible_region, x, y); } if (!gdk_region_empty(visible_region)) result = HIPPO_WINDOW_STATE_ONSCREEN; out: gdk_error_trap_pop(); if (children) XFree(children); if (visible_region) gdk_region_destroy(visible_region); return result; }
QVariant QXcbMime::mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a, const QByteArray &data, const QString &format, QVariant::Type requestedType, const QByteArray &encoding) { QString atomName = mimeAtomToString(connection, a); // qDebug() << "mimeConvertDataToFormat" << format << atomName << data; if (!encoding.isEmpty() && atomName == format + QLatin1String(";charset=") + QString::fromLatin1(encoding)) { #ifndef QT_NO_TEXTCODEC if (requestedType == QVariant::String) { QTextCodec *codec = QTextCodec::codecForName(encoding); if (codec) return codec->toUnicode(data); } #endif return data; } // special cases for string types if (format == QLatin1String("text/plain")) { if (a == connection->atom(QXcbAtom::UTF8_STRING)) return QString::fromUtf8(data); if (a == XCB_ATOM_STRING || a == connection->atom(QXcbAtom::TEXT)) return QString::fromLatin1(data); } // special case for uri types if (format == QLatin1String("text/uri-list")) { if (atomName == QLatin1String("text/x-moz-url")) { // we expect this as utf16 <url><space><title> // the first part is a url that should only contain ascci char // so it should be safe to check that the second char is 0 // to verify that it is utf16 if (data.size() > 1 && data.at(1) == 0) return QString::fromRawData((const QChar *)data.constData(), data.size() / 2).split(QLatin1Char('\n')).first().toLatin1(); } } if (atomName == format) return data; #if 0 // ### // special case for images if (format == QLatin1String("image/ppm")) { if (a == XCB_ATOM_PIXMAP && data.size() == sizeof(Pixmap)) { Pixmap xpm = *((Pixmap*)data.data()); if (!xpm) return QByteArray(); Window root; int x; int y; uint width; uint height; uint border_width; uint depth; XGetGeometry(display, xpm, &root, &x, &y, &width, &height, &border_width, &depth); XImage *ximg = XGetImage(display,xpm,x,y,width,height,AllPlanes,depth==1 ? XYPixmap : ZPixmap); QImage qimg = QXlibStatic::qimageFromXImage(ximg); XDestroyImage(ximg); QImageWriter imageWriter; imageWriter.setFormat("PPMRAW"); QBuffer buf; buf.open(QIODevice::WriteOnly); imageWriter.setDevice(&buf); imageWriter.write(qimg); return buf.buffer(); } } #endif return QVariant(); }
int save_image (FILE *file) { int x_loc,y_loc; #ifdef X11WM Window canvas_root_win, child_win; XImage *ximage; #else void *ximage = NULL; #endif char r[MAX_COLORS],g[MAX_COLORS],b[MAX_COLORS]; unsigned int x_width,y_height,border_width,depth; int width, height; #ifdef X11WM int screen = DefaultScreen(connect_id.display); int scrn_width=DisplayWidth(connect_id.display,screen); int scrn_height=DisplayHeight(connect_id.display,screen); #else int screen; int scrn_width; int scrn_height; #endif int x1,y1; /* * Get allocated memory for the XImage structure and copy the * canvas window to it. */ /* Get the application window's position */ #ifdef X11WM XRaiseWindow(connect_id.display,connect_id.drawable); if ( XGetGeometry( connect_id.display,connect_id.drawable, &canvas_root_win, &x_loc, &y_loc, &x_width, &y_height, &border_width, &depth) == 0 || XTranslateCoordinates(connect_id.display,connect_id.drawable, canvas_root_win,0,0,&x1,&y1,&child_win) == False) { err_warn(1,fperr,"Error - getting raster image.\n"); return 0; } width = x_width; height = y_height; /* Find the new x location and the width, if necessary. */ if ((-x1 > width) || (x1 > scrn_width)) { err_warn(1,fperr,"Error - X for getting raster image.\n"); return 0; } if (x1 < 0) { width=width+x1; x1=0; } else if (x1+width > scrn_width) { width=scrn_width-x1; } if ((-y1 > height) || (y1 > scrn_height)) { err_warn(1,fperr,"Error - Y for getting raster image.\n"); return 0; } if (y1 < 0) { height=height+y1; y1=0; } else if (y1+height > scrn_height) { height=scrn_height-y1; } /* This way is good because the root window will create partially obscure windows. * But this method doesn't work for the Mac which has a rootless window. * ximage = XGetImage(cptr->connect_id.display, RootWindowOfScreen(DefaultScreenOfDisplay(cptr->connect_id.display)), x1, y1, width, height, XAllPlanes(), ZPixmap); */ ximage = XGetImage(connect_id.display, connect_id.drawable, 0, 0, width, height, XAllPlanes(), ZPixmap); #elif defined QTWM vcs_Qt_window_get_image_by_id(connect_id.wkst_id,&ximage); #else fprintf(stderr,"insert here your WM to get image\n"); #endif if (ximage == NULL) { err_warn(1,fperr,"Error - getting raster image.\n"); return 0; } /* If display has 8 bit color */ #ifdef X11WM if (ximage->depth == 8) { /* Convert X colors to u_char arrays */ convert_gks_color(r, g, b); /* Save the image and its colormap in a Sun Raster file */ ras_write_ximage(file, ximage, r, g, b, MAX_COLORS); } else { /* Save the image with no colormap in a Sun Raster file */ ras_write_ximage(file, ximage, NULL, NULL, NULL, 0); } #elif defined QTWM ras_write_ximage(file, ximage, NULL, NULL, NULL, 0); #else fprintf(stderr,"insert here your write to ras func\n"); #endif /* Print out image information print_image_info(x_loc, y_loc, ximage, MAX_COLORS); */ /* Remove the image from memory */ #ifdef X11WM XDestroyImage(ximage); #elif defined QTWM free(ximage); #else fprintf(stderr,"insert here your destroy ximage func\n"); #endif return 1; }
int render_pdf_page(int pdf, int pg, Window win, bool fixed) { if (pg >= _pdf[pdf].npage) return 1; cairo_t *ctx; cairo_surface_t *s, *img; double pdfw, pdfh, scx, scy; int ig; unsigned int uig, ww, wh; /* get page size and scale to window */ PopplerPage *page = poppler_document_get_page(_pdf[pdf].doc, pg); poppler_page_get_size(page, &pdfw, &pdfh); XGetGeometry(dpy, win, (Window *) &ig, &ig, &ig, &ww, &wh, &uig, &uig); scx = ww / pdfw; scy = wh / pdfh; //if (pdf == 0) { _ww = ww; _wh = wh; } if (fixed) { /* adjust window size for fixed aspect ratio */ scx = (scx < scy ? (scy=scx) : scy); ww = scx * pdfw + 0.5; wh = scy * pdfh + 0.5; XResizeWindow(dpy, win, ww, wh); } /* create background pixmap and render page to it */ Pixmap pix = XCreatePixmap(dpy, win, ww, wh, DefaultDepth(dpy,scr)); s = cairo_xlib_surface_create(dpy, pix, DefaultVisual(dpy,scr), ww, wh); ctx = cairo_create(s); cairo_surface_destroy(s); cairo_scale(ctx, scx, scy); cairo_set_source_rgb(ctx, 1, 1, 1); cairo_paint(ctx); poppler_page_render(page, ctx); cairo_destroy(ctx); /* if this is the fader window, fade in */ if (win == _fade_win) { /* hide cursor for fade transitions */ #ifdef module_cursor bool pre = cursor_visible(query); cursor_visible(false); #endif /* get image, set up context, and render page */ img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, ww, wh); ctx = cairo_create(img); cairo_scale(ctx, scx, scy); cairo_set_source_rgb(ctx, 1, 1, 1); cairo_paint(ctx); poppler_page_render(page, ctx); cairo_destroy(ctx); /* get window surface, reset context to draw img to window */ s = cairo_xlib_surface_create(dpy, win, DefaultVisual(dpy,scr), ww, wh); ctx = cairo_create(s); cairo_surface_destroy(s); cairo_set_source_surface(ctx, img, 0, 0); // memory leak?! /* fade in */ for (ig = _fade_steps; ig; --ig) { cairo_paint_with_alpha(ctx, 1 / (float) ig); // memory leak?! //XFlush(dpy); usleep(200); } /* clean up */ cairo_destroy(ctx); cairo_surface_destroy(img); #ifdef module_cursor cursor_visible(pre); #endif } g_object_unref(page); /* set the pixmap to be the window background */ XSetWindowBackgroundPixmap(dpy, win, pix); XFreePixmap(dpy, pix); XClearWindow(dpy, win); #ifdef module_cursor if (pdf == 0) cursor_draw(-1, -1); #endif return 0; }
/* ARGSUSED */ static void Initialize ( Widget greq, Widget gnew, ArgList args, Cardinal *num_args) { LoginWidget w = (LoginWidget)gnew; XtGCMask valuemask, xvaluemask; XGCValues myXGCV; Arg position[2]; Position x, y; #ifdef USE_XINERAMA XineramaScreenInfo *screens; int s_num; #endif #ifdef XPM myXGCV.foreground = w->login.hipixel; myXGCV.background = w->core.background_pixel; valuemask = GCForeground | GCBackground; w->login.hiGC = XtGetGC(gnew, valuemask, &myXGCV); myXGCV.foreground = w->login.shdpixel; myXGCV.background = w->core.background_pixel; valuemask = GCForeground | GCBackground; w->login.shdGC = XtGetGC(gnew, valuemask, &myXGCV); #endif /* XPM */ myXGCV.foreground = w->login.textpixel; myXGCV.background = w->core.background_pixel; valuemask = GCForeground | GCBackground; if (w->login.font) { myXGCV.font = w->login.font->fid; valuemask |= GCFont; } w->login.textGC = XtGetGC(gnew, valuemask, &myXGCV); myXGCV.foreground = w->core.background_pixel; w->login.bgGC = XtGetGC(gnew, valuemask, &myXGCV); myXGCV.foreground = w->login.textpixel ^ w->core.background_pixel; myXGCV.function = GXxor; xvaluemask = valuemask | GCFunction; w->login.xorGC = XtGetGC (gnew, xvaluemask, &myXGCV); /* * Note that the second argument is a GCid -- QueryFont accepts a GCid and * returns the curently contained font. */ if (w->login.font == NULL) w->login.font = XQueryFont (XtDisplay (w), XGContextFromGC (XDefaultGCOfScreen (XtScreen (w)))); xvaluemask = valuemask; if (w->login.promptFont == NULL) w->login.promptFont = w->login.font; else xvaluemask |= GCFont; myXGCV.foreground = w->login.promptpixel; myXGCV.font = w->login.promptFont->fid; w->login.promptGC = XtGetGC (gnew, xvaluemask, &myXGCV); xvaluemask = valuemask; if (w->login.greetFont == NULL) w->login.greetFont = w->login.font; else xvaluemask |= GCFont; myXGCV.foreground = w->login.greetpixel; myXGCV.font = w->login.greetFont->fid; w->login.greetGC = XtGetGC (gnew, xvaluemask, &myXGCV); xvaluemask = valuemask; if (w->login.failFont == NULL) w->login.failFont = w->login.font; else xvaluemask |= GCFont; myXGCV.foreground = w->login.failpixel; myXGCV.font = w->login.failFont->fid; w->login.failGC = XtGetGC (gnew, xvaluemask, &myXGCV); #ifdef XPM w->login.logoValid = False; if (NULL != w->login.logoFileName) { XpmAttributes myAttributes = { 0 }; Window tmpWindow = { 0 }; struct stat myBuffer = { 0 }; unsigned int myPixmapDepth = 0; if (0 != stat(w->login.logoFileName, &myBuffer)) { LogError("Unable to stat() pixmap file %s\n", w->login.logoFileName); w->login.logoValid = False; goto SkipXpmLoad; } myAttributes.valuemask |= XpmReturnPixels; myAttributes.valuemask |= XpmReturnExtensions; XpmReadFileToPixmap(XtDisplay(w), /* display */ RootWindowOfScreen(XtScreen(w)), /* window */ w->login.logoFileName, /* XPM filename */ &(w->login.logoPixmap), /* pixmap */ &(w->login.logoMask), /* pixmap mask */ &myAttributes); /* XPM attributes */ w->login.logoValid = True; XGetGeometry(XtDisplay(w), w->login.logoPixmap, &tmpWindow, &(w->login.logoX), &(w->login.logoY), &(w->login.logoWidth), &(w->login.logoHeight), &(w->login.logoBorderWidth), &myPixmapDepth); } else { w->login.logoX = 0; w->login.logoY = 0; w->login.logoWidth = 0; w->login.logoHeight = 0; w->login.logoBorderWidth = 0; } SkipXpmLoad: #endif /* XPM */ w->login.data.name[0] = '\0'; w->login.data.passwd[0] = '\0'; w->login.state = GET_NAME; w->login.cursor = 0; w->login.failUp = 0; if (w->core.width == 0) w->core.width = max (GREET_W(w), FAIL_W(w)) + PAD_X(w); if (w->core.height == 0) { int fy = FAIL_Y(w); int pady = PAD_Y(w); #ifndef XPM w->core.height = fy + pady; /* for stupid compilers */ #else /* w->core.height = fy + pady; * for stupid compilers */ w->core.height = max(fy + pady, (w->login.logoHeight + (2*w->login.logoPadding)) + pady); #endif /* XPM */ } #ifdef USE_XINERAMA if ( XineramaIsActive(XtDisplay(w)) && (screens = XineramaQueryScreens(XtDisplay(w), &s_num)) != NULL ) { if ((x = w->core.x) == -1) x = screens[0].x_org + (int)(screens[0].width - w->core.width) / 2; if ((y = w->core.y) == -1) y = screens[0].y_org + (int)(screens[0].height - w->core.height) / 3; XFree(screens); } else #endif { if ((x = w->core.x) == -1) x = (int)(XWidthOfScreen (XtScreen (w)) - w->core.width) / 2; if ((y = w->core.y) == -1) y = (int)(XHeightOfScreen (XtScreen (w)) - w->core.height) / 3; } XtSetArg (position[0], XtNx, x); XtSetArg (position[1], XtNy, y); XtSetValues (XtParent (w), position, (Cardinal) 2); }