📄 nativegui.c
字号:
sprintf(buf, "%d", err->request_code); XGetErrorDatabaseText(disp, "XRequest", buf, "Unknown", msg, sizeof(msg)); fprintf(stderr, "Major opcode %d (%s)\n", err->request_code, msg); if (err->request_code > 128) { fprintf(stderr, "Minor opcode %d\n", err->minor_code); } return 0;}static intlocalXIOErrorHandler(Display *disp){ fprintf(stderr, "X I/O Error\n"); return 0;}static Pixmap pixmap = None;static XpmAttributes case_attributes; static Pixmap getBackgroundPixmap() { Window rootWindow = RootWindowOfScreen(screen); int status; case_attributes.valuemask = XpmVisual | XpmDepth | XpmReturnPixels | XpmCloseness | XpmSize | XpmColormap; case_attributes.closeness = 40000; case_attributes.visual = visual; case_attributes.depth = visualDepth; case_attributes.colormap = colormap; status = XpmCreatePixmapFromData(display, rootWindow, phone_xpm, &pixmap, NULL, &case_attributes); if (status >= 0) { XFillRectangle(display, pixmap, gcErase, X_SCREEN, y_screen - topBarHeight, DISPLAY_WIDTH, DISPLAY_HEIGHT); } else { pixmap = (Pixmap)NULL; } return pixmap;}static intsetupColormap(int usePrivateColormap){ int bg = 0; if (usePrivateColormap) { Colormap cmap = XCreateColormap(display, RootWindowOfScreen(screen), visual, AllocNone); if (cmap == None) { fprintf(stderr, "Couldn't create colormap"); exit(-99); } colormap = cmap; } if (numColors < 256) { int i; /* * these numbers are gamma corrected so that * a monitor with gamma = 2.5 displays them as * linear percentages of gray. */ for (i = 0; i < numColors; ++i) { float factor = pow(((float)i/((float)numColors - 1.0)), 0.4); grayTable[i].red = (int) (lightPixel.red * factor); grayTable[i].green = (int) (lightPixel.green * factor); grayTable[i].blue = (int) (lightPixel.blue * factor); grayTable[i].flags = DoRed | DoGreen | DoBlue; if (!XAllocColor(display, colormap, grayTable + i)) { if (usePrivateColormap) { fprintf(stderr, "Could not allocate gray pixels\n"); exit(1); } else { return setupColormap(KNI_TRUE); } } } bg = grayTable[numColors - 1].pixel; if (usePrivateColormap) { /* include some colors that make it possible to show pixmap */ int r, g, b; XColor tmp; tmp.flags = DoRed | DoGreen | DoBlue; for (r = 0; r < 256; r += 51) { for (g = 0; g < 256; g += 51) { for (b = 0; b < 256; b += 51) { tmp.red = (r << 8) | r; tmp.green = (g << 8) | g; tmp.blue = (b << 8) | b; XAllocColor(display, colormap, &tmp); } } } } } else if (numColors == 256) { int r, g, b, i; i = 0; for (r = 0; r <= 0xffff; r += 0xffff / 7) { if (r == 0xfffe) ++r; /* rounding error */ for (g = 0; g <= 0xffff; g += 0xffff / 7) { if (g == 0xfffe) ++g; /* rounding error */ for (b = 0; b <= 0xffff; b += 0xffff / 3) { rgbTable[i].red = r; rgbTable[i].green = g; rgbTable[i].blue = b; rgbTable[i].flags = DoRed | DoGreen | DoBlue; if (!XAllocColor(display, colormap, rgbTable + i)) { if (usePrivateColormap) { fprintf(stderr, "Could not allocate pixels\n"); exit(1); } else { return setupColormap(KNI_TRUE); } } ++i; } } } bg = rgbTable[numColors - 1].pixel; } lightPixel.pixel = bg; return bg;}static intcountBits(int mask){ int count = 0; while (mask != 0) { /* clear the lowest bit that is set */ mask &= (mask - 1); ++count; } return count;}/* * Create the Emulator Window and associated resources. */static XVisualInfo *visualInfo = NULL;static voidcreateEmulatorWindow() { static char *argv[] = {"lcdui"}; Widget shellWidget; applicationData appData; char *s; int argc = 1; int fg, bg; int status; XGCValues vals; int GCbase = GCFunction | GCForeground | GCBackground | GCGraphicsExposures; XSetWindowAttributes attributes; int valuemask; XVisualInfo vi; Pixmap greenLEDPixmap = None; Pixmap grayLEDPixmap = None; XpmAttributes LEDAttributes; Pixmap backLightPixmap = None; Pixmap backLightOffPixmap = None; XpmAttributes BackLightAttributes; Pixmap trustediconPixmap = None; XpmAttributes trustediconAttributes; int n = 0, mask = VisualClassMask | VisualScreenMask; long outerEvtMask = ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | StructureNotifyMask | FocusChangeMask | KeyPressMask | KeyReleaseMask; if (initialized) { return; } else { initialized = 1; } #ifdef INCLUDE_I18N lcWin = getLcWinMethods(getLocaleName());#endif XSetErrorHandler(localXErrorHandler); XSetIOErrorHandler(localXIOErrorHandler); shellWidget = XtOpenApplication(&appContext, "lcdui", NULL, 0, &argc, argv, NULL, applicationShellWidgetClass, NULL, 0); display = XtDisplay(shellWidget); screen = DefaultScreenOfDisplay(display); colormap = DefaultColormapOfScreen(screen); visual = DefaultVisualOfScreen(screen); XtGetApplicationResources(shellWidget, &appData, resources, XtNumber(resources), NULL, 0); if ((s = getInternalProp("system.display.double_buffered")) != NULL) { doubleBuffer = !strcasecmp(s, "true"); } /* use environment variable if present */ if ((s = getInternalProp("system.display.screen_depth")) != NULL) { if (!strcmp(s, "1")) { numColors = 2; } else if (!strcmp(s, "2")) { numColors = 4; } else if (!strcmp(s, "4")) { numColors = 16; } else if (!strcmp(s, "8")) { numColors = 256; } } else if (appData.depth == 2) { numColors = 4; } else if (appData.depth == 4) { numColors = 16; } else if (appData.depth == 8) { numColors = 256; } else if (appData.depth != 1) { numColors = 2; fprintf(stderr, "Warning: unsupported depth. Using monochrome\n"); } s = getInternalProp("system.display.visual_type"); vi.screen = DefaultScreen(display); if (s == NULL) { if ((numColors == 256) && (visual->class == PseudoColor)) { /* try to get StaticColor */ vi.class = StaticColor; vi.colormap_size = 256; mask |= VisualColormapSizeMask; } else { mask = VisualIDMask | VisualScreenMask; vi.visualid = visual->visualid; } } else if (!strcmp(s, "StaticGray")) { vi.class = StaticGray; } else if (!strcmp(s, "GrayScale")) { vi.class = GrayScale; } else if (!strcmp(s, "StaticColor")) { vi.class = StaticColor; vi.colormap_size = 256; mask |= VisualColormapSizeMask; } else if (!strcmp(s, "PseudoColor")) { vi.class = PseudoColor; vi.colormap_size = 256; mask |= VisualColormapSizeMask; } else if (!strcmp(s, "TrueColor")) { vi.class = TrueColor; } else if (!strcmp(s, "DirectColor")) { vi.class = DirectColor; } else { fprintf(stderr, "Unrecognized visual type %s\n", s); } if ((visualInfo = XGetVisualInfo(display, mask, &vi, &n)) == NULL) { mask = VisualIDMask | VisualScreenMask; vi.visualid = visual->visualid; visualInfo = XGetVisualInfo(display, mask, &vi, &n); } if ( (numColors == 256) && ((visual->visualid == StaticColor) && (s == NULL)) ) { /* we forced StaticColor, to try to avoid flashing. */ /* see if we really have a 3:3:2 structure! */ if ( (countBits(visualInfo->red_mask) != 3) || (countBits(visualInfo->green_mask) != 3) || (countBits(visualInfo->blue_mask) != 2) ) { mask = VisualIDMask | VisualScreenMask; vi.visualid = visual->visualid; visualInfo = XGetVisualInfo(display, mask, &vi, &n); } } if (visualInfo == NULL) { fprintf(stderr, "XGetVisualInfo failed\n"); exit(-8); } else if (n > 1) { /* find the one with the best depth */ XVisualInfo *best = visualInfo; int i; for (i = 1; i < n; ++i) { if ( (visualInfo[i].depth > best->depth) || (visualInfo[i].colormap_size > best->colormap_size)) { best = visualInfo + i; } } visual = best->visual; visualDepth = best->depth; } else { visual = visualInfo->visual; visualDepth = visualInfo->depth; } if (getInternalProp("system.display.debug_screen")) { XSynchronize(display, 1); }#if 0 /* Create the "outer" window */ outerWindow = XCreateSimpleWindow(display, RootWindowOfScreen(screen), appData.x, appData.y, EMULATOR_WIDTH, EMULATOR_HEIGHT, 0, appData.background, appData.foreground);#endif if (visual != DefaultVisualOfScreen(screen)) { fprintf(stderr, "visual id 0x%02x, depth %d\n", visual->visualid, visualDepth); } bg = setupColormap(visual != DefaultVisualOfScreen(screen)); valuemask = 0; valuemask |= CWBackPixel; attributes.background_pixel = bg; valuemask |= CWBorderPixel; attributes.border_pixel = bg; valuemask |= CWColormap; attributes.colormap = colormap; outerWindow = XCreateWindow(display, RootWindowOfScreen(screen), appData.x, appData.y, EMULATOR_WIDTH, EMULATOR_HEIGHT, 0, visualDepth, InputOutput, visual, valuemask, &attributes); XSelectInput(display, outerWindow, outerEvtMask); fg = (numColors == 256) ? rgbTable[0].pixel : grayTable[0].pixel; bg = getPixel(0xaf, 0xaf, 0xaf, 0xaf); vals.foreground = fg; vals.background = bg; vals.function = GXcopy; vals.graphics_exposures = KNI_FALSE; gcNormal = XCreateGC(display, outerWindow, GCbase, &vals); vals.foreground = bg; gcErase = XCreateGC(display, outerWindow, GCbase, &vals); casePixmap = getBackgroundPixmap(); XSetWindowBackgroundPixmap(display, outerWindow, casePixmap); XDefineCursor(display, outerWindow, handCursor = XCreateFontCursor(display, XC_hand2)); /* Create a "background" window to display the status bar and the command labels */ valuemask = 0; backgroundWindow = XCreateWindow(display, outerWindow, X_SCREEN, Y_SCREEN_OFFSET, PAINT_WIDTH, DISPLAY_HEIGHT, 0, visualDepth, InputOutput, visual, valuemask, &attributes); gc = XCreateGC(display, backgroundWindow, GCbase, &vals); XSelectInput(display, backgroundWindow, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | KeyPressMask | KeyReleaseMask); XDefineCursor(display, backgroundWindow, stylusCursor = XCreateFontCursor(display, XC_pencil)); /* * We need a separate bitmap to serve as the drawable for the status bar * and the command labels. We write to the bitmap, and let it serve * as the background for the window. */ backgroundDrawable = XCreatePixmap(display, backgroundWindow, PAINT_WIDTH, DISPLAY_HEIGHT, visualDepth); XFillRectangle(display, backgroundDrawable, gcErase, 0, 0, PAINT_WIDTH, DISPLAY_HEIGHT); XSetWindowBackgroundPixmap(display, backgroundWindow, backgroundDrawable); /* Create the "paint" window */#if 0 paintWindow = XCreateSimpleWindow(display, outerWindow, X_SCREEN, y_screen, PAINT_WIDTH, paintHeight, 0, appData.background, appData.foreground);#endif valuemask = 0; paintWindow = XCreateWindow(display, outerWindow, X_SCREEN, Y_SCREEN_OFFSET, PAINT_WIDTH, DISPLAY_HEIGHT, 0, visualDepth, InputOutput, visual, valuemask, &attributes); gc = XCreateGC(display, paintWindow, GCbase, &vals); XSelectInput(display, paintWindow, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | KeyPressMask | KeyReleaseMask); XDefineCursor(display, paintWindow, stylusCursor = XCreateFontCursor(display, XC_pencil)); /* * We need a separate bitmap to serve as the drawable for the screen area */ paintDrawable = XCreatePixmap(display, paintWindow, PAINT_WIDTH, DISPLAY_HEIGHT, visualDepth); XFillRectangle(display, paintDrawable, gcErase, 0, 0, PAINT_WIDTH, DISPLAY_HEIGHT);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -