void NewUnit(int selectedunit) { struct UnitNode *unit; ULONG id, modeselected; struct ModeNode *mode; unit = (struct UnitNode *) GetNode(selectedunit, UnitList); state.UnitSelected = selectedunit; id = unit->prefs.ahiup_AudioMode; FreeVec(Modes); FreeList(ModeList); ModeList = GetModes( &unit->prefs); Modes = List2Array((struct List *) ModeList); modeselected = 0; mode = (struct ModeNode *) ModeList->lh_Head; while(mode->node.ln_Succ) { if(id == mode->ID) break; modeselected++; mode = (struct ModeNode *) mode->node.ln_Succ; } if(mode->node.ln_Succ == NULL) { modeselected = ~0; } NewMode(modeselected); }
u8 Architecture::GetModeByName(std::string const& rModeName) const { auto const& rModes = GetModes(); for (auto itMode = std::begin(rModes), itEnd = std::end(rModes); itMode != itEnd; ++itMode) if (rModeName == std::get<0>(*itMode)) return std::get<1>(*itMode); return 0; }
/*ARGSUSED*/ static void ChangeScreenCallback(Widget w, XtPointer call_data, XtPointer client_data) { Arg args[1]; screenno = (long)call_data; if (screenno > computer.num_vidmodes || screenno < 0 || vidtune == computer.vidmodes[screenno]) return; XF86VidModeLockModeSwitch(XtDisplay(toplevel), vidtune->screen, False); vidtune = computer.vidmodes[screenno]; XF86VidModeLockModeSwitch(XtDisplay(toplevel), vidtune->screen, True); UpdateCallback(w, call_data, client_data); GetModes(); XtSetArg(args[0], XtNlabel, XtName(w)); XtSetValues(screenb, args, 1); SetLabelAndModeline(); }
int MFDisplay_CreateDisplay(int width, int height, int bpp, int rate, bool vsync, bool triplebuffer, bool wide, bool progressive) { MFCALLSTACK; MFZeroMemory(gXKeys, sizeof(gXKeys)); MFZeroMemory(&gXMouse, sizeof(gXMouse)); gXMouse.x = -1; gDisplay.fullscreenWidth = gDisplay.width = width; gDisplay.fullscreenHeight = gDisplay.height = height; gDisplay.refreshRate = 0; gDisplay.colourDepth = 0; /* Use default. Chances are, it's something sane */ gDisplay.windowed = true; gDisplay.wide = false; gDisplay.progressive = true; if(!(xdisplay = XOpenDisplay(NULL))) { MFDebug_Error("Unable to open display"); MFDisplay_DestroyDisplay(); return 1; } screen = DefaultScreen(xdisplay); rootWindow = RootWindow(xdisplay, screen); // build our internal list of available video modes GetModes(&modes, !gDisplay.windowed); while(!FindMode(modes, width, height)) { if(!gDisplay.windowed) { // no fullscreen mode, try windowed mode instead MFDebug_Warn(1, "No suitable modes for fullscreen mode, trying windowed mode"); gDisplay.windowed = true; FreeModes(); GetModes(&modes, false); } else { // default is some sort of custom mode that doesn't appear in the windowed mode list // HACK: we'll add it to the end.. modes[numModes].width = width; modes[numModes].height = height; currentMode = numModes; ++numModes; break; } } DebugMenu_AddItem("Resolution", "Display Options", &resSelect, ChangeResCallback); DebugMenu_AddItem("Apply", "Display Options", &applyDisplayMode, ApplyDisplayModeCallback); // Set full screen mode, if necessary if(!gDisplay.windowed && numModes > 1) { if(!XF86VidModeSwitchToMode(xdisplay, screen, vidModes[currentMode])) { MFDebug_Error("Unable to switch screenmodes, defaulting to windowed mode"); MFDisplay_DestroyDisplay(); return 1; } } XVisualInfo *MFRenderer_GetVisualInfo(); XVisualInfo *visualInfo = MFRenderer_GetVisualInfo(); if(!visualInfo) return 1; if(!(colorMap = XCreateColormap(xdisplay, rootWindow, visualInfo->visual, AllocNone))) { MFDebug_Error("Unable to create colourmap"); XFree(visualInfo); MFDisplay_DestroyDisplay(); return 1; } XSetWindowAttributes windowAttrs; windowAttrs.colormap = colorMap; windowAttrs.cursor = None; windowAttrs.event_mask = StructureNotifyMask; windowAttrs.border_pixel = BlackPixel(xdisplay, screen); windowAttrs.background_pixel = BlackPixel(xdisplay, screen); if(!(window = XCreateWindow(xdisplay, rootWindow, 0, 0, width, height, 0, visualInfo->depth, InputOutput, visualInfo->visual, CWBackPixel | CWBorderPixel | CWCursor | CWColormap | CWEventMask, &windowAttrs))) { MFDebug_Error("Unable to create X Window"); XFree(visualInfo); MFDisplay_DestroyDisplay(); return 1; } // Tell the window manager not to allow our window to be resized. But some window managers can ignore me and do it anyway. Typical X-Windows. if((sizeHints = XAllocSizeHints()) == NULL) { MFDebug_Error("Unable to alloc XSizeHints structure, out of memory?"); XFree(visualInfo); MFDisplay_DestroyDisplay(); return 1; } sizeHints->flags = PSize | PMinSize | PMaxSize; sizeHints->min_width = sizeHints->max_width = sizeHints->base_width = width; sizeHints->min_height = sizeHints->max_height = sizeHints->base_height = height; XSetWMNormalHints(xdisplay, window, sizeHints); // Window title XStoreName(xdisplay, window, gDefaults.display.pWindowTitle); XWMHints *wmHints; if((wmHints = XAllocWMHints()) == NULL) { MFDebug_Error("Unable to alloc XWMHints structure, out of memory?"); XFree(visualInfo); MFDisplay_DestroyDisplay(); return 1; } wmHints->flags = InputHint | StateHint; wmHints->input = true; wmHints->initial_state = NormalState; if(!XSetWMHints(xdisplay, window, wmHints)) { MFDebug_Error("Unable to set WM hints for window"); XFree(visualInfo); MFDisplay_DestroyDisplay(); return 1; } XFree(wmHints); XFree(visualInfo); // Tell the window manager that I want to be notified if the window's closed wm_delete_window = XInternAtom(xdisplay, "WM_DELETE_WINDOW", false); if(!XSetWMProtocols(xdisplay, window, &wm_delete_window, 1)) { MFDebug_Error("Unable to set Window Manager protocols"); MFDisplay_DestroyDisplay(); return 1; } XSelectInput(xdisplay, window, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask | ExposureMask); if(!XMapRaised(xdisplay, window)) { MFDebug_Error("Unable to map new window"); MFDisplay_DestroyDisplay(); return 1; } // Wait for the window to be mapped, etc. The documentation doesn't indicate that this is necessary, but every GLX program I've ever seen does it, so I assume it is. XEvent event; XIfEvent(xdisplay, &event, WaitForNotify, (char *)window); MFRenderer_CreateDisplay(); if(!gDisplay.windowed && numModes > 1) { if(!XF86VidModeSwitchToMode(xdisplay, screen, vidModes[currentMode])) { MFDebug_Error("Unable to set screen mode"); MFDisplay_DestroyDisplay(); return 1; } XGrabPointer(xdisplay, window, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, window, None, CurrentTime); XFlush(xdisplay); // A little trick to make sure the entire window is on the screen XWarpPointer(xdisplay, None, window, 0, 0, 0, 0, width - 1, height - 1); XWarpPointer(xdisplay, None, window, 0, 0, 0, 0, 0, 0); XFlush(xdisplay); } return 0; }
void VideoModeConfigureStart(void) { vidtune = computer.vidmodes[screenno]; XtSetSensitive(vtune, vidtune != NULL); if (!XtIsManaged(vtune)) XtManageChild(vtune); else XtMapWidget(vtune); if (vidtune != NULL) { Arg args[1]; Boolean state; XF86ConfMonitorPtr mon; static char menuName[16]; static int menuN; XtErrorFunc = XSetErrorHandler(VidmodeError); XF86VidModeLockModeSwitch(XtDisplay(toplevel), vidtune->screen, True); GetModeLine(True); GetModes(); SetLabels(); XtSetArg(args[0], XtNstate, &state); XtGetValues(automatic, args, 1); XtSetSensitive(apply, !state); autoflag = state; if (monitor) XtDestroyWidget(monitor); XmuSnprintf(menuName, sizeof(menuName), "menuP%d", menuN); menuN = !menuN; monitor = XtCreatePopupShell(menuName, simpleMenuWidgetClass, vtune, NULL, 0); XtVaSetValues(monitorb, XtNmenuName, menuName, NULL, 0); mon = XF86Config->conf_monitor_lst; while (mon != NULL) { Widget sme = XtCreateManagedWidget(mon->mon_identifier, smeBSBObjectClass, monitor, NULL, 0); XtAddCallback(sme, XtNcallback, SelectMonitorCallback, (XtPointer)mon); /* guess the monitor at a given screen and/or * updates configuration if a monitor was removed from the * configuration. */ if (XF86Config->conf_layout_lst) { XF86ConfAdjacencyPtr adj = XF86Config->conf_layout_lst-> lay_adjacency_lst; while (adj != NULL) { if (adj->adj_screen != NULL) { if (adj->adj_screen->scrn_monitor == mon && adj->adj_scrnum >= 0 && adj->adj_scrnum < ScreenCount(XtDisplay(toplevel))) { if (computer.vidmodes[adj->adj_scrnum]->monitor == NULL || computer.vidmodes[adj->adj_scrnum]-> monitor == adj->adj_screen->scrn_monitor) { computer.vidmodes[adj->adj_scrnum]->monitor = adj->adj_screen->scrn_monitor; break; } else computer.vidmodes[adj->adj_scrnum]->monitor = NULL; } } adj = (XF86ConfAdjacencyPtr)(adj->list.next); } } mon = (XF86ConfMonitorPtr)(mon->list.next); } SetLabelAndModeline(); } }
/*ARGSUSED*/ static void AddVesaModeCallback(Widget w, XtPointer call_data, XtPointer client_data) { xf86cfgVesaModeInfo *vesa = (xf86cfgVesaModeInfo*)call_data; XF86VidModeModeInfo mode; int num_infos = vidtune->num_infos; memcpy(&mode, &vesa->info, sizeof(XF86VidModeModeInfo)); if (XF86VidModeAddModeLine(XtDisplay(toplevel), vidtune->screen, &vesa->info, &mode)) { XSync(XtDisplay(toplevel), False); GetModes(); } else { XBell(XtDisplayOfObject(w), 80); return; } if (vidtune && num_infos == vidtune->num_infos) { /* XF86VidModeAddModeLine returned True, but no modeline was added */ XBell(XtDisplayOfObject(w), 80); if (vidtune->monitor && AddMode()) { XF86ConfModeLinePtr mode; char label[256], *ptr, *str; XmuSnprintf(label, sizeof(label), "%s", vesa->ident); /* format mode name to not have spaces */ ptr = strchr(label, ')'); if (ptr) *++ptr = '\0'; ptr = str = label; while (*ptr) { if (*ptr != ' ') *str++ = *ptr; ++ptr; } *str = '\0'; if (xf86findModeLine(label, vidtune->monitor->mon_modeline_lst) != NULL && !ForceAddMode()) return; mode = (XF86ConfModeLinePtr)XtCalloc(1, sizeof(XF86ConfModeLineRec)); mode->ml_identifier = XtNewString(label); mode->ml_clock = vesa->info.dotclock; mode->ml_hdisplay = vesa->info.hdisplay; mode->ml_hsyncstart = vesa->info.hsyncstart; mode->ml_hsyncend = vesa->info.hsyncend; mode->ml_htotal = vesa->info.htotal; mode->ml_vdisplay = vesa->info.vdisplay; mode->ml_vsyncstart = vesa->info.vsyncstart; mode->ml_vsyncend = vesa->info.vsyncend; mode->ml_vtotal = vesa->info.vtotal; /* mode->ml_vscan = ???;*/ mode->ml_flags = vesa->info.flags; mode->ml_hskew = vesa->info.hskew; vidtune->monitor->mon_modeline_lst = xf86addModeLine(vidtune->monitor->mon_modeline_lst, mode); } } }