void PrintableWindow::xmove(int left1, int top) { const Display& d = *display(); XEvent event; int x = 0, y = 0; static int xoff = 0, yoff = 0; WindowRep& w = *((Window*)this)->rep(); get_position(d.rep()->display_, w.xwindow_, &x, &y); for (int i= 0; (left1 != x || top != y) && i < 10; i++) { XMoveWindow(d.rep()->display_, w.xwindow_, left1+xoff, top+yoff); XPeekIfEvent(d.rep()->display_, &event, WaitForEvent, (char *)ConfigureNotify); get_position(d.rep()->display_, w.xwindow_, &x, &y); if (left1 != x || top != y) { XIfEvent(d.rep()->display_, &event, WaitForEvent, (char *)ConfigureNotify); xoff = left1 - x; yoff = top - y; } printf("x=%d y=%d, left1=%d top=%d xoff = %d yoff = %d\n", x, y, left1, top, xoff, yoff); } }
static Bool LookAhead(Widget w, XEvent *event) { XEvent newEvent; struct EventData eventData; if (QLength(XtDisplay(w)) == 0) return (False); eventData.count = 0; eventData.oldEvent = event; XPeekIfEvent(XtDisplay(w), &newEvent, PeekNotifyEvent, (char*)&eventData); if (CompareEvents(event, &newEvent)) return (True); return (False); }
void init_graphics (char *window_name) { /* Open the toplevel window, get the colors, 2 graphics * * contexts, load a font, and set up the toplevel window * * Calls build_menu to set up the menu. */ char *display_name = NULL; int x, y; /* window position */ unsigned int border_width = 2; /* ignored by OpenWindows */ XTextProperty windowName; /* X Windows' names for my colours. */ char *cnames[NUM_COLOR] = {"white", "black", "grey55", "grey75", "blue", "green", "yellow", "cyan", "red", "RGBi:0.0/0.5/0.0" }; XColor exact_def; Colormap cmap; int i; unsigned long valuemask = 0; /* ignore XGCvalues and use defaults */ XGCValues values; XEvent event; disp_type = SCREEN; /* Graphics go to screen, not ps */ for (i=0;i<=MAX_FONT_SIZE;i++) font_is_loaded[i] = 0; /* No fonts loaded yet. */ /* connect to X server */ /* connect to X server */ if ( (display=XOpenDisplay(display_name)) == NULL ) { fprintf( stderr, "Cannot connect to X server %s\n", XDisplayName(display_name)); exit( -1 ); } /* get screen size from display structure macro */ screen_num = DefaultScreen(display); display_width = DisplayWidth(display, screen_num); display_height = DisplayHeight(display, screen_num); x = y = 0; top_width = 2*display_width/3; top_height = 4*display_height/5; cmap = DefaultColormap(display, screen_num); private_cmap = None; for (i=0;i<NUM_COLOR;i++) { if (!XParseColor(display,cmap,cnames[i],&exact_def)) { fprintf(stderr, "Color name %s not in database", cnames[i]); exit(-1); } if (!XAllocColor(display, cmap, &exact_def)) { fprintf(stderr, "Couldn't allocate color %s.\n",cnames[i]); if (private_cmap == None) { fprintf(stderr, "Will try to allocate a private colourmap.\n"); fprintf(stderr, "Colours will only display correctly when your " "cursor is in the graphics window.\n" "Exit other colour applications and rerun this " "program if you don't like that.\n\n"); private_cmap = XCopyColormapAndFree (display, cmap); cmap = private_cmap; if (!XAllocColor (display, cmap, &exact_def)) { fprintf (stderr, "Couldn't allocate color %s as private.\n", cnames[i]); exit (1); } } else { fprintf (stderr, "Couldn't allocate color %s as private.\n", cnames[i]); exit (1); } } colors[i] = exact_def.pixel; } toplevel = XCreateSimpleWindow(display,RootWindow(display,screen_num), x, y, top_width, top_height, border_width, colors[BLACK], colors[WHITE]); if (private_cmap != None) XSetWindowColormap (display, toplevel, private_cmap); /* hints stuff deleted. */ XSelectInput (display, toplevel, ExposureMask | StructureNotifyMask | ButtonPressMask); /* Create default Graphics Contexts. valuemask = 0 -> use defaults. */ gc = XCreateGC(display, toplevel, valuemask, &values); gc_menus = XCreateGC(display, toplevel, valuemask, &values); /* Create XOR graphics context for Rubber Banding */ values.function = GXxor; values.foreground = colors[BLACK]; gcxor = XCreateGC(display, toplevel, (GCFunction | GCForeground), &values); /* specify font for menus. */ load_font(menu_font_size); font_is_loaded[menu_font_size] = 1; XSetFont(display, gc_menus, font_info[menu_font_size]->fid); /* Set drawing defaults for user-drawable area. Use whatever the * * initial values of the current stuff was set to. */ force_setfontsize(currentfontsize); force_setcolor (currentcolor); force_setlinestyle (currentlinestyle); force_setlinewidth (currentlinewidth); XStringListToTextProperty(&window_name, 1, &windowName); XSetWMName (display, toplevel, &windowName); /* XSetWMIconName (display, toplevel, &windowName); */ /* set line attributes */ /* XSetLineAttributes(display, gc, line_width, line_style, cap_style, join_style); */ /* set dashes */ /* XSetDashes(display, gc, dash_offset, dash_list, list_length); */ XMapWindow (display, toplevel); build_textarea(); build_menu(); /* The following is completely unnecessary if the user is using the * * interactive (event_loop) graphics. It waits for the first Expose * * event before returning so that I can tell the window manager has got * * the top-level window up and running. Thus the user can start drawing * * into this window immediately, and there's no danger of the window not * * being ready and output being lost. */ XPeekIfEvent (display, &event, test_if_exposed, NULL); }
/* * Opens a window. Requires a SFG_Window object created and attached * to the freeglut structure. OpenGL context is created here. */ void fgPlatformOpenWindow( SFG_Window* window, const char* title, GLboolean positionUse, int x, int y, GLboolean sizeUse, int w, int h, GLboolean gameMode, GLboolean isSubWindow ) { XVisualInfo * visualInfo = NULL; XSetWindowAttributes winAttr; XTextProperty textProperty; XSizeHints sizeHints; XWMHints wmHints; XEvent eventReturnBuffer; /* return buffer required for a call */ unsigned long mask; unsigned int current_DisplayMode = fgState.DisplayMode ; XConfigureEvent fakeEvent = {0}; /* Save the display mode if we are creating a menu window */ if( window->IsMenu && ( ! fgStructure.MenuContext ) ) fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB ; #ifdef EGL_VERSION_1_0 #define WINDOW_CONFIG window->Window.pContext.egl.Config #else #define WINDOW_CONFIG window->Window.pContext.FBConfig #endif fghChooseConfig(&WINDOW_CONFIG); if( window->IsMenu && ( ! fgStructure.MenuContext ) ) fgState.DisplayMode = current_DisplayMode ; if( ! WINDOW_CONFIG ) { /* * The "fghChooseConfig" returned a null meaning that the visual * context is not available. * Try a couple of variations to see if they will work. */ #ifndef EGL_VERSION_1_0 if( !( fgState.DisplayMode & GLUT_DOUBLE ) ) { fgState.DisplayMode |= GLUT_DOUBLE ; fghChooseConfig(&WINDOW_CONFIG); fgState.DisplayMode &= ~GLUT_DOUBLE; } #endif if( fgState.DisplayMode & GLUT_MULTISAMPLE ) { fgState.DisplayMode &= ~GLUT_MULTISAMPLE ; fghChooseConfig(&WINDOW_CONFIG); fgState.DisplayMode |= GLUT_MULTISAMPLE; } } FREEGLUT_INTERNAL_ERROR_EXIT( WINDOW_CONFIG != NULL, "FBConfig with necessary capabilities not found", "fgOpenWindow" ); /* Get the X visual. */ #ifdef EGL_VERSION_1_0 EGLint vid = 0; XVisualInfo visualTemplate; int num_visuals; if (!eglGetConfigAttrib(fgDisplay.pDisplay.egl.Display, window->Window.pContext.egl.Config, EGL_NATIVE_VISUAL_ID, &vid)) fgError("eglGetConfigAttrib(EGL_NATIVE_VISUAL_ID) failed"); visualTemplate.visualid = vid; visualInfo = XGetVisualInfo(fgDisplay.pDisplay.Display, VisualIDMask, &visualTemplate, &num_visuals); #else visualInfo = glXGetVisualFromFBConfig( fgDisplay.pDisplay.Display, window->Window.pContext.FBConfig ); #endif FREEGLUT_INTERNAL_ERROR_EXIT( visualInfo != NULL, "visualInfo could not be retrieved from FBConfig", "fgOpenWindow" ); /* * XXX HINT: the masks should be updated when adding/removing callbacks. * XXX This might speed up message processing. Is that true? * XXX * XXX A: Not appreciably, but it WILL make it easier to debug. * XXX Try tracing old GLUT and try tracing freeglut. Old GLUT * XXX turns off events that it doesn't need and is a whole lot * XXX more pleasant to trace. (Think mouse-motion! Tons of * XXX ``bonus'' GUI events stream in.) */ winAttr.event_mask = StructureNotifyMask | SubstructureNotifyMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask | VisibilityChangeMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | ButtonMotionMask; winAttr.background_pixmap = None; winAttr.background_pixel = 0; winAttr.border_pixel = 0; winAttr.colormap = XCreateColormap( fgDisplay.pDisplay.Display, fgDisplay.pDisplay.RootWindow, visualInfo->visual, AllocNone ); mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask; if( window->IsMenu || ( gameMode == GL_TRUE ) ) { winAttr.override_redirect = True; mask |= CWOverrideRedirect; } if( ! positionUse ) x = y = -1; /* default window position */ if( ! sizeUse ) w = h = 300; /* default window size */ window->Window.Handle = XCreateWindow( fgDisplay.pDisplay.Display, window->Parent == NULL ? fgDisplay.pDisplay.RootWindow : window->Parent->Window.Handle, x, y, w, h, 0, visualInfo->depth, InputOutput, visualInfo->visual, mask, &winAttr ); /* Fake configure event to force viewport setup * even with no window manager. */ fakeEvent.type = ConfigureNotify; fakeEvent.display = fgDisplay.pDisplay.Display; fakeEvent.window = window->Window.Handle; fakeEvent.x = x; fakeEvent.y = y; fakeEvent.width = w; fakeEvent.height = h; XPutBackEvent(fgDisplay.pDisplay.Display, (XEvent*)&fakeEvent); /* * The GLX context creation, possibly trying the direct context rendering * or else use the current context if the user has so specified */ if( window->IsMenu ) { /* * If there isn't already an OpenGL rendering context for menu * windows, make one */ if( !fgStructure.MenuContext ) { fgStructure.MenuContext = (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) ); fgStructure.MenuContext->MContext = fghCreateNewContext( window ); } /* window->Window.Context = fgStructure.MenuContext->MContext; */ window->Window.Context = fghCreateNewContext( window ); } else if( fgState.UseCurrentContext ) { #ifdef EGL_VERSION_1_0 window->Window.Context = eglGetCurrentContext( ); #else window->Window.Context = glXGetCurrentContext( ); #endif if( ! window->Window.Context ) window->Window.Context = fghCreateNewContext( window ); } else window->Window.Context = fghCreateNewContext( window ); #if !defined( __FreeBSD__ ) && !defined( __NetBSD__ ) && !defined(EGL_VERSION_1_0) if( !glXIsDirect( fgDisplay.pDisplay.Display, window->Window.Context ) ) { if( fgState.DirectContext == GLUT_FORCE_DIRECT_CONTEXT ) fgError( "Unable to force direct context rendering for window '%s'", title ); } #endif sizeHints.flags = 0; if ( positionUse ) sizeHints.flags |= USPosition; if ( sizeUse ) sizeHints.flags |= USSize; /* * Fill in the size hints values now (the x, y, width and height * settings are obsolete, are there any more WMs that support them?) * Unless the X servers actually stop supporting these, we should * continue to fill them in. It is *not* our place to tell the user * that they should replace a window manager that they like, and which * works, just because *we* think that it's not "modern" enough. */ sizeHints.x = x; sizeHints.y = y; sizeHints.width = w; sizeHints.height = h; wmHints.flags = StateHint; wmHints.initial_state = fgState.ForceIconic ? IconicState : NormalState; /* Prepare the window and iconified window names... */ XStringListToTextProperty( (char **) &title, 1, &textProperty ); XSetWMProperties( fgDisplay.pDisplay.Display, window->Window.Handle, &textProperty, &textProperty, 0, 0, &sizeHints, &wmHints, NULL ); XFree( textProperty.value ); XSetWMProtocols( fgDisplay.pDisplay.Display, window->Window.Handle, &fgDisplay.pDisplay.DeleteWindow, 1 ); #ifdef EGL_VERSION_1_0 fghPlatformOpenWindowEGL(window); #else glXMakeContextCurrent( fgDisplay.pDisplay.Display, window->Window.Handle, window->Window.Handle, window->Window.Context ); #endif #ifdef FREEGLUT_REGAL RegalMakeCurrent(window->Window.Context); #endif /* register extension events _before_ window is mapped */ #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H fgRegisterDevices( fgDisplay.pDisplay.Display, &(window->Window.Handle) ); #endif if (!window->IsMenu) /* Don't show window after creation if its a menu */ { XMapWindow( fgDisplay.pDisplay.Display, window->Window.Handle ); window->State.Visible = GL_TRUE; } XFree(visualInfo); /* wait till window visible */ if( !isSubWindow && !window->IsMenu) XPeekIfEvent( fgDisplay.pDisplay.Display, &eventReturnBuffer, &fghWindowIsVisible, (XPointer)(window->Window.Handle) ); #undef WINDOW_CONFIG }
void DtcmProcessPress( Widget w, XEvent *event, String *params, Cardinal *num_params) { int i, action, cur_item; int *selected_positions, nselected_positions; /* * This action happens when Button1 is pressed and the Selection * and Transfer are integrated on Button1. It is passed two * parameters: the action to call when the event is a selection, * and the action to call when the event is a transfer. */ if (*num_params != 2 || !XmIsList(w)) return; action = SELECTION_ACTION; cur_item = XmListYToPos(w, event->xbutton.y); if (cur_item > 0) { XtVaGetValues(w, XmNselectedPositions, &selected_positions, XmNselectedPositionCount, &nselected_positions, NULL); for (i=0; i<nselected_positions; i++) { if (cur_item == selected_positions[i]) { /* * The determination of whether this is a transfer drag * cannot be made until a Motion event comes in. It is * not a drag as soon as a ButtonUp event happens. */ XEvent new_event; XPeekIfEvent( XtDisplay(w), &new_event, lookForButton, (XPointer)event); switch (new_event.type) { case MotionNotify: action = TRANSFER_ACTION; break; case ButtonRelease: action = SELECTION_ACTION; break; } break; } } } XtCallActionProc(w, params[action], event, params, *num_params); }