int main(int argc, char *argv[]) { Display *display = XOpenDisplay(NULL); printf("dddd\n"); if (display == NULL) { printf("Unable to open display\n"); return 1; } font_info = XLoadQueryFont(display, font_name); if (!font_info) { fprintf(stderr, "XLoadQueryFont: failed loading font '%s'\n", font_name); } XClassHint class_hint; XSizeHints *size_hints; size_hints = XAllocSizeHints(); XWMHints *wm_hints; wm_hints = XAllocWMHints(); int black_color = BlackPixel(display, DefaultScreen(display)); int white_color = WhitePixel(display, DefaultScreen(display)); Window window = XCreateSimpleWindow( display , DefaultRootWindow(display) , 0 , 0 , 400 , 300 , black_color , 35 , white_color ); XStoreName(display, window, WIN_TITLE); gc = XCreateGC(display, window, 0, &values); XSetFont(display, gc, font_info->fid); XSetForeground(display, gc, black_color); class_hint.res_name = WIN_NAME; class_hint.res_class = WIN_CLASS; XSetClassHint(display, window, &class_hint); size_hints->flags = PPosition | PSize | PMinSize; size_hints->min_width = 400; size_hints->min_height = 300; XSetWMNormalHints(display, window, size_hints); XSelectInput(display, window, ExposureMask); XMapWindow(display, window); XFlush(display); while(1) { static char *text = "Hello, Ryan"; static int txt_length; static int font_height; static int txt_x_pos,txt_y_pos; XNextEvent(display, &report); switch ( report.type ) { case Expose: if ( report.xexpose.count != 0 ) break; txt_length = XTextWidth(font_info, text, strlen(text)); XDrawString(display, window, gc, 100, 100, "hello ryan", strlen("hello ryan")); break; } } return 0; }
int main(int argc, char *argv[]) { program_info programInfo = GetProgramInfoFromArgs(argc, argv); int winWidth = programInfo.winWidth; int winHeight = programInfo.winHeight; int bytesPerPixel = 4; // We allocate the image buffer SetupGraphicsBuffer(&gBuffer, winWidth, winHeight, bytesPerPixel); xBuffer.width = winWidth; xBuffer.height = winHeight; xBuffer.data = malloc(winWidth * winHeight * bytesPerPixel); // We start the image thread pthread_t thread; programInfo.buffer = &gBuffer; int result = pthread_create(&thread, 0, ImageThreadFunction, (void *)(&programInfo)); if (result) { fprintf(stderr, "Error with pthread_create. Code: %d\n", result); exit(EXIT_FAILURE); } // We open the display Display *display = XOpenDisplay(0); Window window = XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0, winWidth, winHeight, 0, 0xFFFFFFFF, 0); GC gc = XCreateGC(display, window, 0, 0); XMapWindow(display, window); int screen = DefaultScreen(display); Visual *visual = DefaultVisual(display, screen); int depth = DefaultDepth(display, screen); XImage *image = XCreateImage(display, visual, depth, ZPixmap, 0, (char *)xBuffer.data, winWidth, winHeight, 32, 0); XInitImage(image); int xMasks = ExposureMask | KeyPressMask; XSelectInput(display, window, xMasks); // Nasty hack Atom wmDeleteMessage = XInternAtom(display, "WM_DELETE_WINDOW", False); /* XSetWMProtocols(display, window, &wmDeleteMessage, 1); */ int loopRunning = 1; while(loopRunning) { XEvent event; /* XNextEvent(display, &event); */ // We flush the events queue while (XCheckMaskEvent(display, xMasks, &event)) { switch (event.type) { case Expose: TransferBuffer(&gBuffer, &xBuffer); XPutImage(display, window, gc, image, 0, 0, 0, 0, winWidth, winHeight); XFlush(display); break; // Hack for the window close eventExposureMask // TODO(Cristian): See how to do this correctly case ClientMessage: if (event.xclient.data.l[0] == wmDeleteMessage) { loopRunning = 0; } break; } } // We sleep for a while usleep(100 * 1000); TransferBuffer(&gBuffer, &xBuffer); XPutImage(display, window, gc, image, 0, 0, 0, 0, winWidth, winHeight); XFlush(display); } }
DockWnd::DockWnd(DockPlugin *plugin, const char *icon, const char *text) : QWidget(NULL, "dock", WType_TopLevel | WStyle_Customize | WStyle_NoBorder | WStyle_StaysOnTop), EventReceiver(LowPriority) { #ifndef WIN32 #ifndef QT_MACOSX_VERSION wharfIcon = NULL; #endif #endif m_plugin = plugin; setMouseTracking(true); bNoToggle = false; bBlink = false; m_state = icon; blinkTimer = new QTimer(this); connect(blinkTimer, SIGNAL(timeout()), this, SLOT(blink())); #ifdef WIN32 hShell = NULL; setIcon(icon); QWidget::hide(); gDock = this; if (IsWindowUnicode(winId())){ (HMODULE&)hShell = LoadLibraryA("shell32.dll"); if (hShell) (DWORD&)_Shell_NotifyIconW = (DWORD)GetProcAddress((HMODULE)hShell, "Shell_NotifyIconW"); } if (IsWindowUnicode(winId()) && _Shell_NotifyIconW){ oldDockProc = (WNDPROC)SetWindowLongW(winId(), GWL_WNDPROC, (LONG)DockWindowProc); NOTIFYICONDATAW notifyIconData; notifyIconData.cbSize = sizeof(notifyIconData); notifyIconData.hIcon = topData()->winIcon; notifyIconData.hWnd = winId(); notifyIconData.szTip[0] = 0; notifyIconData.uCallbackMessage = WM_DOCK; notifyIconData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; notifyIconData.uID = 0; _Shell_NotifyIconW(NIM_ADD, ¬ifyIconData); }else{ oldDockProc = (WNDPROC)SetWindowLongA(winId(), GWL_WNDPROC, (LONG)DockWindowProc); NOTIFYICONDATAA notifyIconData; notifyIconData.cbSize = sizeof(notifyIconData); notifyIconData.hIcon = topData()->winIcon; notifyIconData.hWnd = winId(); notifyIconData.szTip[0] = 0; notifyIconData.uCallbackMessage = WM_DOCK; notifyIconData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; notifyIconData.uID = 0; Shell_NotifyIconA(NIM_ADD, ¬ifyIconData); } #else setMinimumSize(22, 22); resize(22, 22); #ifndef QT_MACOSX_VERSION bInit = false; inTray = false; inNetTray = false; Display *dsp = x11Display(); WId win = winId(); bool bEnlightenment = false; QWidget tmp; Atom enlightenment_desktop = XInternAtom(dsp, "ENLIGHTENMENT_DESKTOP", false); WId w = tmp.winId(); Window p, r; Window *c; unsigned int nc; while (XQueryTree(dsp, w, &r, &p, &c, &nc)){ if (c && nc > 0) XFree(c); if (! p) { log(L_WARN, "No parent"); break; } unsigned char *data_ret = NULL; Atom type_ret; int i_unused; unsigned long l_unused; if ((XGetWindowProperty(dsp, p, enlightenment_desktop, 0, 1, False, XA_CARDINAL, &type_ret, &i_unused, &l_unused, &l_unused, &data_ret) == Success) && (type_ret == XA_CARDINAL)) { if (data_ret) XFree(data_ret); bEnlightenment = true; log(L_DEBUG, "Detect Enlightenment"); break; } if (p == r) break; w = p; } if (bEnlightenment){ bInit = true; resize(48, 48); setFocusPolicy(NoFocus); move(m_plugin->getDockX(), m_plugin->getDockY()); MWMHints mwm; mwm.flags = MWM_HINTS_DECORATIONS; mwm.functions = 0; mwm.decorations = 0; mwm.inputMode = 0; mwm.status = 0; Atom a = XInternAtom(dsp, "_MOTIF_WM_HINTS", False); XChangeProperty(dsp, win, a, a, 32, PropModeReplace, (unsigned char *)&mwm, sizeof(MWMHints) / 4); XStoreName(dsp, win, "SIM"); XClassHint *xch = XAllocClassHint(); xch->res_name = (char*)"SIM"; xch->res_class = (char*)"Epplet"; XSetClassHint(dsp, win, xch); XFree(xch); XSetIconName(dsp, win, "SIM"); unsigned long val = (1 << 0) /* | (1 << 9) */ ; a = XInternAtom(dsp, "_WIN_STATE", False); XChangeProperty(dsp, win, a, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&val, 1); val = 2; a = XInternAtom(dsp, "_WIN_LAYER", False); XChangeProperty(dsp, win, a, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&val, 1); val = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 5); a = XInternAtom(dsp, "_WIN_HINTS", False); XChangeProperty(dsp, win, a, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&val, 1); win_name = "SIM"; win_version = VERSION; win_info = ""; while (!comms_win) { ECommsSetup(dsp); sleep(1); } char s[256]; snprintf(s, sizeof(s), "set clientname %s", win_name); ECommsSend(s); snprintf(s, sizeof(s), "set version %s", win_version); ECommsSend(s); snprintf(s, sizeof(s), "set info %s", win_info); ECommsSend(s); ESYNC; set_background_properties(this); setIcon(icon); show(); return; } wharfIcon = new WharfIcon(this); #endif setBackgroundMode(X11ParentRelative); setIcon(icon); #ifndef QT_MACOSX_VERSION XClassHint classhint; classhint.res_name = (char*)"sim"; classhint.res_class = (char*)"Wharf"; XSetClassHint(dsp, win, &classhint); Screen *screen = XDefaultScreenOfDisplay(dsp); int screen_id = XScreenNumberOfScreen(screen); char buf[32]; snprintf(buf, sizeof(buf), "_NET_SYSTEM_TRAY_S%d", screen_id); Atom selection_atom = XInternAtom(dsp, buf, false); XGrabServer(dsp); Window manager_window = XGetSelectionOwner(dsp, selection_atom); if (manager_window != None) XSelectInput(dsp, manager_window, StructureNotifyMask); XUngrabServer(dsp); XFlush(dsp); if (manager_window != None){ inNetTray = true; if (!send_message(dsp, manager_window, SYSTEM_TRAY_REQUEST_DOCK, win, 0, 0)){ inNetTray = false; } } Atom kde_net_system_tray_window_for_atom = XInternAtom(dsp, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false); long data[1]; data[0] = 0; XChangeProperty(dsp, win, kde_net_system_tray_window_for_atom, XA_WINDOW, 32, PropModeReplace, (unsigned char*)data, 1); XWMHints *hints; hints = XGetWMHints(dsp, win); hints->initial_state = WithdrawnState; hints->icon_x = 0; hints->icon_y = 0; hints->icon_window = wharfIcon->winId(); hints->window_group = win; hints->flags = WindowGroupHint | IconWindowHint | IconPositionHint | StateHint; XSetWMHints(dsp, win, hints); XFree( hints ); Event eArgc(EventArgc); int argc = (int)eArgc.process(); Event eArgv(EventArgv); char **argv = (char**)eArgv.process(); XSetCommand(dsp, win, argv, argc); if (!inNetTray){ move(-21, -21); resize(22, 22); } #endif show(); #endif setTip(text); reset(); }
/* =============== GLX_Init =============== */ int GLX_Init(glimpParms_t a) { int attrib[] = { GLX_RGBA, // 0 GLX_RED_SIZE, 8, // 1, 2 GLX_GREEN_SIZE, 8, // 3, 4 GLX_BLUE_SIZE, 8, // 5, 6 GLX_DOUBLEBUFFER, // 7 GLX_DEPTH_SIZE, 24, // 8, 9 GLX_STENCIL_SIZE, 8, // 10, 11 GLX_ALPHA_SIZE, 8, // 12, 13 None }; // these match in the array #define ATTR_RED_IDX 2 #define ATTR_GREEN_IDX 4 #define ATTR_BLUE_IDX 6 #define ATTR_DEPTH_IDX 9 #define ATTR_STENCIL_IDX 11 #define ATTR_ALPHA_IDX 13 Window root; XVisualInfo *visinfo; XSetWindowAttributes attr; XSizeHints sizehints; unsigned long mask; int colorbits, depthbits, stencilbits; int tcolorbits, tdepthbits, tstencilbits; int actualWidth, actualHeight; int i; const char *glstring; if ( !GLimp_OpenDisplay() ) { return false; } common->Printf( "Initializing OpenGL display\n" ); root = RootWindow( dpy, scrnum ); actualWidth = glConfig.vidWidth; actualHeight = glConfig.vidHeight; // Get video mode list if ( !XF86VidModeQueryVersion( dpy, &vidmode_MajorVersion, &vidmode_MinorVersion ) ) { vidmode_ext = false; common->Printf("XFree86-VidModeExtension not available\n"); } else { vidmode_ext = true; common->Printf("Using XFree86-VidModeExtension Version %d.%d\n", vidmode_MajorVersion, vidmode_MinorVersion); } GLX_TestDGA(); if ( vidmode_ext ) { int best_fit, best_dist, dist, x, y; XF86VidModeGetAllModeLines( dpy, scrnum, &num_vidmodes, &vidmodes ); // Are we going fullscreen? If so, let's change video mode if ( a.fullScreen ) { best_dist = 9999999; best_fit = -1; for (i = 0; i < num_vidmodes; i++) { if (a.width > vidmodes[i]->hdisplay || a.height > vidmodes[i]->vdisplay) continue; x = a.width - vidmodes[i]->hdisplay; y = a.height - vidmodes[i]->vdisplay; dist = (x * x) + (y * y); if (dist < best_dist) { best_dist = dist; best_fit = i; } } if (best_fit != -1) { actualWidth = vidmodes[best_fit]->hdisplay; actualHeight = vidmodes[best_fit]->vdisplay; // change to the mode XF86VidModeSwitchToMode(dpy, scrnum, vidmodes[best_fit]); vidmode_active = true; // Move the viewport to top left // FIXME: center? XF86VidModeSetViewPort(dpy, scrnum, 0, 0); common->Printf( "Free86-VidModeExtension Activated at %dx%d\n", actualWidth, actualHeight ); } else { a.fullScreen = false; common->Printf( "Free86-VidModeExtension: No acceptable modes found\n" ); } } else { common->Printf( "XFree86-VidModeExtension: not fullscreen, ignored\n" ); } } // color, depth and stencil colorbits = 24; depthbits = 24; stencilbits = 8; for (i = 0; i < 16; i++) { // 0 - default // 1 - minus colorbits // 2 - minus depthbits // 3 - minus stencil if ((i % 4) == 0 && i) { // one pass, reduce switch (i / 4) { case 2: if (colorbits == 24) colorbits = 16; break; case 1: if (depthbits == 24) depthbits = 16; else if (depthbits == 16) depthbits = 8; case 3: if (stencilbits == 24) stencilbits = 16; else if (stencilbits == 16) stencilbits = 8; } } tcolorbits = colorbits; tdepthbits = depthbits; tstencilbits = stencilbits; if ((i % 4) == 3) { // reduce colorbits if (tcolorbits == 24) tcolorbits = 16; } if ((i % 4) == 2) { // reduce depthbits if (tdepthbits == 24) tdepthbits = 16; else if (tdepthbits == 16) tdepthbits = 8; } if ((i % 4) == 1) { // reduce stencilbits if (tstencilbits == 24) tstencilbits = 16; else if (tstencilbits == 16) tstencilbits = 8; else tstencilbits = 0; } if (tcolorbits == 24) { attrib[ATTR_RED_IDX] = 8; attrib[ATTR_GREEN_IDX] = 8; attrib[ATTR_BLUE_IDX] = 8; } else { // must be 16 bit attrib[ATTR_RED_IDX] = 4; attrib[ATTR_GREEN_IDX] = 4; attrib[ATTR_BLUE_IDX] = 4; } attrib[ATTR_DEPTH_IDX] = tdepthbits; // default to 24 depth attrib[ATTR_STENCIL_IDX] = tstencilbits; visinfo = qglXChooseVisual(dpy, scrnum, attrib); if (!visinfo) { continue; } common->Printf( "Using %d/%d/%d Color bits, %d Alpha bits, %d depth, %d stencil display.\n", attrib[ATTR_RED_IDX], attrib[ATTR_GREEN_IDX], attrib[ATTR_BLUE_IDX], attrib[ATTR_ALPHA_IDX], attrib[ATTR_DEPTH_IDX], attrib[ATTR_STENCIL_IDX]); glConfig.colorBits = tcolorbits; glConfig.depthBits = tdepthbits; glConfig.stencilBits = tstencilbits; break; } if (!visinfo) { common->Printf("Couldn't get a visual\n"); return false; } // window attributes attr.background_pixel = BlackPixel(dpy, scrnum); attr.border_pixel = 0; attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); attr.event_mask = X_MASK; if (vidmode_active) { mask = CWBackPixel | CWColormap | CWSaveUnder | CWBackingStore | CWEventMask | CWOverrideRedirect; attr.override_redirect = True; attr.backing_store = NotUseful; attr.save_under = False; } else { mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; } win = XCreateWindow(dpy, root, 0, 0, actualWidth, actualHeight, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr); XStoreName(dpy, win, GAME_NAME); // don't let the window be resized // FIXME: allow resize (win32 does) sizehints.flags = PMinSize | PMaxSize; sizehints.min_width = sizehints.max_width = actualWidth; sizehints.min_height = sizehints.max_height = actualHeight; XSetWMNormalHints(dpy, win, &sizehints); XMapWindow( dpy, win ); if ( vidmode_active ) { XMoveWindow( dpy, win, 0, 0 ); } XFlush(dpy); XSync(dpy, False); ctx = qglXCreateContext(dpy, visinfo, NULL, True); XSync(dpy, False); // Free the visinfo after we're done with it XFree(visinfo); qglXMakeCurrent(dpy, win, ctx); glstring = (const char *) qglGetString(GL_RENDERER); common->Printf("GL_RENDERER: %s\n", glstring); glstring = (const char *) qglGetString(GL_EXTENSIONS); common->Printf("GL_EXTENSIONS: %s\n", glstring); // FIXME: here, software GL test glConfig.isFullscreen = a.fullScreen; if ( glConfig.isFullscreen ) { Sys_GrabMouseCursor( true ); } return true; }
void desktop_set_background (GtkWidget *desktop, gchar *wallpaper, FmWallpaperMode wallpaper_mode, GdkColor *color_background) { GdkPixbuf *pixbuf; GdkWindow *root = gdk_screen_get_root_window (gtk_widget_get_screen (desktop)); GdkWindow *window = gtk_widget_get_window (desktop); if (wallpaper_mode == FM_WP_COLOR || !wallpaper || !*wallpaper || !(pixbuf = gdk_pixbuf_new_from_file (wallpaper, NULL))) { //GdkColor bg = color_background; //gdk_rgb_find_color (gdk_drawable_get_colormap (window), &bg); //gdk_window_set_back_pixmap (window, NULL, FALSE); gdk_window_set_background (window, color_background); //gdk_window_set_back_pixmap (root, NULL, FALSE); gdk_window_set_background (root, color_background); //gdk_window_clear (root); //gdk_window_clear (window); gdk_window_invalidate_rect (window, NULL, TRUE); return; } // #if 0 int src_w = gdk_pixbuf_get_width (pixbuf); int src_h = gdk_pixbuf_get_height (pixbuf); cairo_surface_t *surface; int dest_w; int dest_h; if (wallpaper_mode == FM_WP_TILE) { dest_w = src_w; dest_h = src_h; //pixmap = gdk_pixmap_new (window, dest_w, dest_h, -1); surface = gdk_window_create_similar_surface (window, CAIRO_CONTENT_COLOR, dest_w, dest_h); } else { GdkScreen *screen = gtk_widget_get_screen (desktop); dest_w = gdk_screen_get_width (screen); dest_h = gdk_screen_get_height (screen); //pixmap = gdk_pixmap_new (window, dest_w, dest_h, -1); surface = gdk_window_create_similar_surface (window, CAIRO_CONTENT_COLOR, dest_w, dest_h); } //~ if (gdk_pixbuf_get_has_alpha (pixbuf) //~ || wallpaper_mode == FM_WP_CENTER //~ || wallpaper_mode == FM_WP_FIT) //~ { //~ gdk_gc_set_rgb_fg_color (desktop->gc, &color_background); //~ gdk_draw_rectangle (pixmap, desktop->gc, TRUE, 0, 0, dest_w, dest_h); //~ } // GdkPixbuf *scaled; cairo_t *cr; switch (wallpaper_mode) { case FM_WP_COLOR: break; case FM_WP_TILE: //gdk_draw_pixbuf (pixmap, desktop->gc, pixbuf, 0, 0, 0, 0, dest_w, dest_h, GDK_RGB_DITHER_NORMAL, 0, 0); cr = cairo_create (surface); gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0); cairo_paint (cr); cairo_destroy (cr); break; case FM_WP_STRETCH: //~ if (dest_w == src_w && dest_h == src_h) //~ scaled = (GdkPixbuf*) g_object_ref (pixbuf); //~ else //~ scaled = gdk_pixbuf_scale_simple (pixbuf, dest_w, dest_h, GDK_INTERP_BILINEAR); //~ //~ gdk_draw_pixbuf (pixmap, desktop->gc, scaled, 0, 0, 0, 0, dest_w, dest_h, GDK_RGB_DITHER_NORMAL, 0, 0); //~ //~ g_object_unref (scaled); break; case FM_WP_FIT: //~ if (dest_w != src_w || dest_h != src_h) //~ { //~ gdouble w_ratio = (float) dest_w / src_w; //~ gdouble h_ratio = (float) dest_h / src_h; //~ gdouble ratio = MIN (w_ratio, h_ratio); //~ //~ if (ratio != 1.0) //~ { //~ src_w *= ratio; //~ src_h *= ratio; //~ //~ scaled = gdk_pixbuf_scale_simple (pixbuf, src_w, src_h, GDK_INTERP_BILINEAR); //~ //~ g_object_unref (pixbuf); //~ pixbuf = scaled; //~ } //~ } case FM_WP_CENTER: { //~ int x; //~ int y; //~ x = (dest_w - src_w) / 2; //~ y = (dest_h - src_h) / 2; //~ //~ gdk_draw_pixbuf (pixmap, desktop->gc, pixbuf, 0, 0, x, y, -1, -1, GDK_RGB_DITHER_NORMAL, 0, 0); } break; } Display *xdisplay; Pixmap xpixmap = 0; Window xroot; cairo_pattern_t *pattern = cairo_pattern_create_for_surface (surface); //gdk_window_set_back_pixmap (root, pixmap, FALSE); gdk_window_set_background_pattern (root, pattern); //gdk_window_set_back_pixmap (window, NULL, TRUE); gdk_window_set_background_pattern (window, pattern); cairo_pattern_destroy (pattern); Pixmap pixmap_id = cairo_xlib_surface_get_drawable (surface); XChangeProperty (GDK_WINDOW_XDISPLAY (root), GDK_WINDOW_XID (root), gdk_x11_get_xatom_by_name ("_XROOTPMAP_ID"), //XA_XROOTMAP_ID, XA_PIXMAP, 32, PropModeReplace, (guchar*) &pixmap_id, 1); // Set root map here... xdisplay = GDK_WINDOW_XDISPLAY (root); xroot = GDK_WINDOW_XID (root); XGrabServer (xdisplay); if (surface) { xpixmap = cairo_xlib_surface_get_drawable (surface); XChangeProperty (xdisplay, xroot, gdk_x11_get_xatom_by_name ("_XROOTPMAP_ID"), XA_PIXMAP, 32, PropModeReplace, (guchar *) &xpixmap, 1); XSetWindowBackgroundPixmap (xdisplay, xroot, xpixmap); } else { // Anyone knows how to handle this correctly ? } XClearWindow (xdisplay, xroot); XUngrabServer (xdisplay); XFlush (xdisplay); cairo_surface_destroy (surface); if (pixbuf) g_object_unref (pixbuf); // gdk_window_clear (root); // gdk_window_clear (window); gdk_window_invalidate_rect (window, NULL, TRUE); // #endif }
void list_windows() { int th, ypos, x; th = TextHeight(fontstruct); ypos = 0 + th - fontstruct->max_bounds.descent; Window WINDOW_LIST_WINDOW = None; char *tmp; char title[256]; int number = 0; int max_title = 0; XWindowAttributes winattr; Window root_return; int char_width = TextWidth(fontstruct, " "); for (x = 0; x< max_windows; x++) { if(windows_container[x] != None) { if(!XGetWindowAttributes(display, windows_container[x], &winattr) || winattr.override_redirect || XGetTransientForHint(display, windows_container[x], &root_return)) continue; if(winattr.map_state == IsViewable) { if(XFetchName(display, windows_container[x], &tmp)) { number++; if(windows_container[x] == selected) { sprintf(title, "%d - %s", get_position(windows_container[x]), tmp); } else { sprintf(title, "%d - %s", get_position(windows_container[x]), tmp); } if(strlen(title) > max_title) max_title = strlen(title); title[0] = 0; } } } } if(number > 0) { int win_width = (max_title * char_width) + (WLISTPADDING * 2); int win_height = number * th; int win_x, win_y; switch(WLISTPOS) { case 0: win_x = PADDING_WEST; win_y = PADDING_NORTH; break; case 1: win_x = SCREEN_WIDTH - PADDING_EAST - win_width - (BORDER * 2); win_y = PADDING_NORTH; break; case 2: win_x = 0 + SCREEN_WIDTH - PADDING_EAST - win_width; win_y = 0 + SCREEN_HEIGHT - PADDING_SOUTH - win_height; break; case 3: win_x = PADDING_WEST; win_y = 0 + SCREEN_HEIGHT - PADDING_SOUTH - win_height; break; case 4: win_x = (SCREEN_WIDTH / 2) - (win_width / 2); win_y = (SCREEN_HEIGHT / 2) - (win_height / 2); break; default: win_x = PADDING_WEST; win_y = PADDING_NORTH; break; } WINDOW_LIST_WINDOW = XCreateSimpleWindow(display, root, win_x, win_y, win_width, win_height, BORDER, name2color(FGCOLOR), name2color(BGCOLOR)); XSetWindowBorderWidth(display, WINDOW_LIST_WINDOW, BORDER); XSetWindowBorder(display, WINDOW_LIST_WINDOW, name2color(SELBGCOLOR)); XMapRaised(display, WINDOW_LIST_WINDOW); for (x = 0; x< max_windows; x++) { if(windows_container[x] != None) { if(!XGetWindowAttributes(display, windows_container[x], &winattr) || winattr.override_redirect || XGetTransientForHint(display, windows_container[x], &root_return)) continue; if(winattr.map_state == IsViewable) { if(XFetchName(display, windows_container[x], &tmp)) { if(windows_container[x] == selected) { sprintf(title, "%d - %s", get_position(windows_container[x]), tmp); XFillRectangle(display, WINDOW_LIST_WINDOW, BARE_SELECTEDBG_GC, 0, ypos - th + fontstruct->max_bounds.descent, win_width, th); XDrawString(display, WINDOW_LIST_WINDOW, BARE_SELECTEDFG_GC, WLISTPADDING, ypos, title, strlen(title)); ypos+=th; } else { sprintf(title, "%d - %s", get_position(windows_container[x]), tmp); XDrawString(display, WINDOW_LIST_WINDOW, BARE_GC, WLISTPADDING, ypos, title, strlen(title)); ypos+=th; } title[0] = 0; } } } } XFlush(display); sleep(TIMEOUT); XFlush(display); if(WINDOW_LIST_WINDOW) { XDestroyWindow(display, WINDOW_LIST_WINDOW); } } else { message("No windows to list!"); } }
void UIMachineView::prepareFrameBuffer() { /* Prepare frame-buffer depending on render-mode: */ switch (vboxGlobal().vmRenderMode()) { #ifdef VBOX_GUI_USE_QIMAGE case VBoxDefs::QImageMode: # ifdef VBOX_WITH_VIDEOHWACCEL if (m_fAccelerate2DVideo) { UIFrameBuffer* pFramebuffer = uisession()->frameBuffer(screenId()); if (pFramebuffer) pFramebuffer->setView(this); else { /* these two additional template args is a workaround to this [VBox|UI] duplication * @todo: they are to be removed once VBox stuff is gone */ pFramebuffer = new VBoxOverlayFrameBuffer<UIFrameBufferQImage, UIMachineView, UIResizeEvent>(this, &machineWindowWrapper()->session(), (uint32_t)screenId()); uisession()->setFrameBuffer(screenId(), pFramebuffer); } m_pFrameBuffer = pFramebuffer; } else m_pFrameBuffer = new UIFrameBufferQImage(this); # else /* VBOX_WITH_VIDEOHWACCEL */ m_pFrameBuffer = new UIFrameBufferQImage(this); # endif /* !VBOX_WITH_VIDEOHWACCEL */ break; #endif /* VBOX_GUI_USE_QIMAGE */ #ifdef VBOX_GUI_USE_QGLFB case VBoxDefs::QGLMode: m_pFrameBuffer = new UIFrameBufferQGL(this); break; // case VBoxDefs::QGLOverlayMode: // m_pFrameBuffer = new UIQGLOverlayFrameBuffer(this); // break; #endif /* VBOX_GUI_USE_QGLFB */ #ifdef VBOX_GUI_USE_SDL case VBoxDefs::SDLMode: /* Indicate that we are doing all drawing stuff ourself: */ // TODO_NEW_CORE viewport()->setAttribute(Qt::WA_PaintOnScreen); # ifdef Q_WS_X11 /* This is somehow necessary to prevent strange X11 warnings on i386 and segfaults on x86_64: */ XFlush(QX11Info::display()); # endif /* Q_WS_X11 */ # if defined(VBOX_WITH_VIDEOHWACCEL) && defined(DEBUG_misha) /* not tested yet */ if (m_fAccelerate2DVideo) { class UIFrameBuffer* pFramebuffer = uisession()->frameBuffer(screenId()); if (pFramebuffer) pFramebuffer->setView(this); else { /* these two additional template args is a workaround to this [VBox|UI] duplication * @todo: they are to be removed once VBox stuff is gone */ pFramebuffer = new VBoxOverlayFrameBuffer<UIFrameBufferSDL, UIMachineView, UIResizeEvent>(this, &machineWindowWrapper()->session(), (uint32_t)screenId()); uisession()->setFrameBuffer(screenId(), pFramebuffer); } m_pFrameBuffer = pFramebuffer; } else m_pFrameBuffer = new UIFrameBufferSDL(this); # else m_pFrameBuffer = new UIFrameBufferSDL(this); # endif /* Disable scrollbars because we cannot correctly draw in a scrolled window using SDL: */ horizontalScrollBar()->setEnabled(false); verticalScrollBar()->setEnabled(false); break; #endif /* VBOX_GUI_USE_SDL */ #if 0 // TODO: Enable DDraw frame buffer! #ifdef VBOX_GUI_USE_DDRAW case VBoxDefs::DDRAWMode: m_pFrameBuffer = new UIDDRAWFrameBuffer(this); if (!m_pFrameBuffer || m_pFrameBuffer->address() == NULL) { if (m_pFrameBuffer) delete m_pFrameBuffer; m_mode = VBoxDefs::QImageMode; m_pFrameBuffer = new UIFrameBufferQImage(this); } break; #endif /* VBOX_GUI_USE_DDRAW */ #endif #ifdef VBOX_GUI_USE_QUARTZ2D case VBoxDefs::Quartz2DMode: /* Indicate that we are doing all drawing stuff ourself: */ viewport()->setAttribute(Qt::WA_PaintOnScreen); # ifdef VBOX_WITH_VIDEOHWACCEL if (m_fAccelerate2DVideo) { UIFrameBuffer* pFramebuffer = uisession()->frameBuffer(screenId()); if (pFramebuffer) pFramebuffer->setView(this); else { /* these two additional template args is a workaround to this [VBox|UI] duplication * @todo: they are to be removed once VBox stuff is gone */ pFramebuffer = new VBoxOverlayFrameBuffer<UIFrameBufferQuartz2D, UIMachineView, UIResizeEvent>(this, &machineWindowWrapper()->session(), (uint32_t)screenId()); uisession()->setFrameBuffer(screenId(), pFramebuffer); } m_pFrameBuffer = pFramebuffer; } else m_pFrameBuffer = new UIFrameBufferQuartz2D(this); # else /* VBOX_WITH_VIDEOHWACCEL */ m_pFrameBuffer = new UIFrameBufferQuartz2D(this); # endif /* !VBOX_WITH_VIDEOHWACCEL */ break; #endif /* VBOX_GUI_USE_QUARTZ2D */ default: AssertReleaseMsgFailed(("Render mode must be valid: %d\n", vboxGlobal().vmRenderMode())); LogRel(("Invalid render mode: %d\n", vboxGlobal().vmRenderMode())); qApp->exit(1); break; } /* If frame-buffer was prepared: */ if (m_pFrameBuffer) { /* Prepare display: */ CDisplay display = session().GetConsole().GetDisplay(); Assert(!display.isNull()); #ifdef VBOX_WITH_VIDEOHWACCEL CFramebuffer fb(NULL); if (m_fAccelerate2DVideo) { LONG XOrigin, YOrigin; /* Check if the framebuffer is already assigned; * in this case we do not need to re-assign it neither do we need to AddRef. */ display.GetFramebuffer(m_uScreenId, fb, XOrigin, YOrigin); } if (fb.raw() != m_pFrameBuffer) /* <-this will evaluate to true iff m_fAccelerate2DVideo is disabled or iff no framebuffer is yet assigned */ #endif /* VBOX_WITH_VIDEOHWACCEL */ { m_pFrameBuffer->AddRef(); } /* Always perform SetFramebuffer to ensure 3D gets notified: */ display.SetFramebuffer(m_uScreenId, CFramebuffer(m_pFrameBuffer)); } QSize size; #ifdef Q_WS_X11 /* Processing pseudo resize-event to synchronize frame-buffer with stored * framebuffer size. On X11 this will be additional done when the machine * state was 'saved'. */ if (session().GetMachine().GetState() == KMachineState_Saved) size = guestSizeHint(); #endif /* Q_WS_X11 */ /* If there is a preview image saved, we will resize the framebuffer to the * size of that image. */ ULONG buffer = 0, width = 0, height = 0; CMachine machine = session().GetMachine(); machine.QuerySavedScreenshotPNGSize(0, buffer, width, height); if (buffer > 0) { /* Init with the screenshot size */ size = QSize(width, height); /* Try to get the real guest dimensions from the save state */ ULONG guestWidth = 0, guestHeight = 0; machine.QuerySavedGuestSize(0, guestWidth, guestHeight); if ( guestWidth > 0 && guestHeight > 0) size = QSize(guestWidth, guestHeight); } /* If we have a valid size, resize the framebuffer. */ if ( size.width() > 0 && size.height() > 0) { UIResizeEvent event(FramebufferPixelFormat_Opaque, NULL, 0, 0, size.width(), size.height()); frameBuffer()->resizeEvent(&event); } }
static void m_process_absolute_motion_event(struct input_event* ev) { int value = ev->value; if (ev->code > ABS_MAX) return; if (ev->code == ABS_MT_SLOT) { m_slot = value; m_x = -1; m_y = -1; } if (ev->code == ABS_MT_POSITION_X) m_x = value; if (ev->code == ABS_MT_POSITION_Y) m_y = value; if (ev->code == ABS_MT_TRACKING_ID) { if (value >= 0) m_num_fingers++; else { m_num_fingers--; m_x = -1; m_y = -1; } } if (m_x == -1 || m_y == -1) return; if (m_num_fingers == 2) m_two_fingers = true; if (m_num_fingers == 4) { m_four_fingers = true; m_two_fingers = false; } MTGR::point_t point; point.x = m_x; point.y = m_y; MTGR::sample_t sample; sample.slot = m_slot; sample.point = point; m_samples.push_back(sample); // FIXME: 手指头还没有离开触摸板的时候,就可以实时判断手势咯 // 但是,会触发太多次zoom in/out事件,在类似TouchEgg应用的时候, // 就会一下子就放大到太大,或一下子就缩小到太小,在实际应用的时候, // 还有很多细节要处理。 MTGR::GestureRecognition gr; switch (gr.predict(m_samples)) { case 5: if (m_two_fingers && !m_zoom_times && m_dpy) { XTestFakeKeyEvent(m_dpy, CTRL_KEYCODE, True, 0); XTestFakeKeyEvent(m_dpy, MINUS_KEYCODE, True, 0); XTestFakeKeyEvent(m_dpy, MINUS_KEYCODE, False, 0); XTestFakeKeyEvent(m_dpy, CTRL_KEYCODE, False, 0); XFlush(m_dpy); m_zoom_times = ZOOM_TIMES; } else { m_zoom_times--; } break; case 6: if (m_two_fingers && !m_zoom_times && m_dpy) { XTestFakeKeyEvent(m_dpy, CTRL_KEYCODE, True, 0); XTestFakeKeyEvent(m_dpy, PLUS_KEYCODE, True, 0); XTestFakeKeyEvent(m_dpy, PLUS_KEYCODE, False, 0); XTestFakeKeyEvent(m_dpy, CTRL_KEYCODE, False, 0); XFlush(m_dpy); m_zoom_times = ZOOM_TIMES; } else { m_zoom_times--; } break; } printf("DEBUG: slot[%d] (x, y) = (%d, %d) num_fingers %d\n", m_slot, m_x, m_y, m_num_fingers); m_sample_file << m_slot << " " << m_x << " " << m_y << "\n"; m_sample_file.flush(); }
void DisplayPoly( Display *dpy, Window win, GC gc, WlzPolygonDomain *poly) { WlzIVertex2 *ivtxs; WlzFVertex2 *fvtxs; WlzDVertex2 *dvtxs; int i, j; /* check the polygon */ if( poly == NULL ){ return; } /* copy to an X line list */ switch( poly->type ){ case WLZ_POLYGON_INT: ivtxs = poly->vtx; for(i=0, j=0; i < poly->nvertices; i++, j++, ivtxs++){ xpoints[j].x = ivtxs->vtX; xpoints[j].y = ivtxs->vtY; if( j == (MAXXPOINTS - 1) ){ XDrawLines(dpy, win, gc, xpoints, j+1, CoordModeOrigin); j=0; xpoints[j].x = ivtxs->vtX; xpoints[j].y = ivtxs->vtY; } } break; case WLZ_POLYGON_FLOAT: fvtxs = (WlzFVertex2 *) poly->vtx; for(i=0, j=0; i < poly->nvertices; i++, j++, fvtxs++){ xpoints[j].x = WLZ_NINT(fvtxs->vtX); xpoints[j].y = WLZ_NINT(fvtxs->vtY); if( j == (MAXXPOINTS - 1) ){ XDrawLines(dpy, win, gc, xpoints, j+1, CoordModeOrigin); j=0; xpoints[j].x = WLZ_NINT(fvtxs->vtX); xpoints[j].y = WLZ_NINT(fvtxs->vtY); } } break; case WLZ_POLYGON_DOUBLE: dvtxs = (WlzDVertex2 *) poly->vtx; for(i=0, j=0; i < poly->nvertices; i++, j++, dvtxs++){ xpoints[j].x = WLZ_NINT(dvtxs->vtX); xpoints[j].y = WLZ_NINT(dvtxs->vtY); if( j == (MAXXPOINTS - 1) ){ XDrawLines(dpy, win, gc, xpoints, j+1, CoordModeOrigin); j=0; xpoints[j].x = WLZ_NINT(dvtxs->vtX); xpoints[j].y = WLZ_NINT(dvtxs->vtY); } } break; default: return; } /* display the polyline */ XDrawLines(dpy, win, gc, xpoints, j, CoordModeOrigin); XFlush( dpy ); return; }
int main (void) { int screen; // which screen /* open connection with the server */ display = XOpenDisplay(NULL); if(display == NULL) { fprintf(stderr, "cannot open display\n"); return 0; } screen = DefaultScreen(display); /* set window position */ int x = 0; int y = 0; /* border width in pixels */ int border_width = 0; /* create window */ window = XCreateSimpleWindow(display, RootWindow(display, screen), x, y, width, height, border_width, BlackPixel(display, screen), WhitePixel(display, screen)); /* create graph */ XGCValues values; long valuemask = 0; gc = XCreateGC(display, window, valuemask, &values); //XSetBackground (display, gc, WhitePixel (display, screen)); XSetForeground (display, gc, BlackPixel (display, screen)); XSetBackground(display, gc, 0X0000FF00); XSetLineAttributes (display, gc, 1, LineSolid, CapRound, JoinRound); /* map(show) the window */ XMapWindow(display, window); XSync(display, 0); pthread_t threads[width]; pthread_attr_t attr; /* 1. Initialize mutex variable objects. */ pthread_mutex_init(&mutex, NULL); pthread_mutex_init(&ptr_mutex, NULL); /* For portability, explicitly create threads in a joinable state. */ struct timespec t1, t2; clock_gettime(CLOCK_REALTIME, &t1); int i, j; long t; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); for (t=0; t<40; t++) pthread_create(&threads[t], &attr, draw_mandelbrot, (void *) t); /* Wait for all threads to complete. */ for (i=0; i<40; i++) pthread_join(threads[i], NULL); /* Clean up and exit. */ pthread_attr_destroy(&attr); pthread_mutex_destroy(&mutex); pthread_mutex_destroy(&ptr_mutex); /* end of record */ clock_gettime(CLOCK_REALTIME, &t2); double timedif = 1000000*(t2.tv_sec-t1.tv_sec)+(t2.tv_nsec-t1.tv_nsec)/1000; printf("It took %.5lf seconds to finish dynamic pthread calculation.\n", timedif/1000000); printf("Going into sleep...\n"); XFlush(display); sleep(3); return 0; }
static void m_process_event(struct input_event *ev) { MTGR::GestureRecognition gr; switch (ev->type) { case EV_SYN: switch (ev->code) { case SYN_REPORT: if (m_num_fingers == 0) { switch (gr.predict(m_samples)) { case 0: printf("DEBUG: predict NULL\n"); break; case 1: printf("DEBUG: predict rightward\n"); if (m_four_fingers && m_dpy) { XTestFakeKeyEvent(m_dpy, CTRL_KEYCODE, True, 0); XTestFakeKeyEvent(m_dpy, ALTR_KEYCODE, True, 0); XTestFakeKeyEvent(m_dpy, RIGHT_KEYCODE, True, 0); XTestFakeKeyEvent(m_dpy, RIGHT_KEYCODE, False, 0); XTestFakeKeyEvent(m_dpy, ALTR_KEYCODE, False, 0); XTestFakeKeyEvent(m_dpy, CTRL_KEYCODE, False, 0); XFlush(m_dpy); } break; case 2: printf("DEBUG: predict leftward\n"); if (m_four_fingers && m_dpy) { XTestFakeKeyEvent(m_dpy, CTRL_KEYCODE, True, 0); XTestFakeKeyEvent(m_dpy, ALTR_KEYCODE, True, 0); XTestFakeKeyEvent(m_dpy, LEFT_KEYCODE, True, 0); XTestFakeKeyEvent(m_dpy, LEFT_KEYCODE, False, 0); XTestFakeKeyEvent(m_dpy, ALTR_KEYCODE, False, 0); XTestFakeKeyEvent(m_dpy, CTRL_KEYCODE, False, 0); XFlush(m_dpy); } break; case 3: printf("DEBUG: predict upward\n"); if (m_four_fingers && m_dpy) { XTestFakeKeyEvent(m_dpy, CTRL_KEYCODE, True, 0); XTestFakeKeyEvent(m_dpy, ALTR_KEYCODE, True, 0); XTestFakeKeyEvent(m_dpy, UP_KEYCODE, True, 0); XTestFakeKeyEvent(m_dpy, UP_KEYCODE, False, 0); XTestFakeKeyEvent(m_dpy, ALTR_KEYCODE, False, 0); XTestFakeKeyEvent(m_dpy, CTRL_KEYCODE, False, 0); XFlush(m_dpy); } break; case 4: printf("DEBUG: predict downward\n"); if (m_four_fingers && m_dpy) { XTestFakeKeyEvent(m_dpy, CTRL_KEYCODE, True, 0); XTestFakeKeyEvent(m_dpy, ALTR_KEYCODE, True, 0); XTestFakeKeyEvent(m_dpy, DOWN_KEYCODE, True, 0); XTestFakeKeyEvent(m_dpy, DOWN_KEYCODE, False, 0); XTestFakeKeyEvent(m_dpy, ALTR_KEYCODE, False, 0); XTestFakeKeyEvent(m_dpy, CTRL_KEYCODE, False, 0); XFlush(m_dpy); } break; case 5: printf("DEBUG: predict zoom in\n"); if (m_four_fingers && m_dpy) { XTestFakeKeyEvent(m_dpy, WIN_KEYCODE, True, 0); XTestFakeKeyEvent(m_dpy, WIN_KEYCODE, False, 0); XFlush(m_dpy); } break; case 6: printf("DEBUG: predict zoom out\n"); if (m_two_fingers && m_dpy) { XTestFakeKeyEvent(m_dpy, CTRL_KEYCODE, True, 0); XTestFakeKeyEvent(m_dpy, PLUS_KEYCODE, True, 0); XTestFakeKeyEvent(m_dpy, PLUS_KEYCODE, False, 0); XTestFakeKeyEvent(m_dpy, CTRL_KEYCODE, False, 0); XFlush(m_dpy); } break; case 7: printf("DEBUG: predict rotate clockwise\n"); break; case 8: printf("DEBUG: predict rotate anti-clockwise\n"); break; } m_samples.clear(); m_four_fingers = false; } printf("DEBUG: [SYN_REPORT]\n"); printf("DEBUG: num_fingers %d\n", m_num_fingers); break; } break; case EV_ABS: m_process_absolute_motion_event(ev); break; } }
/** * Flashes one entire screen. This is done by making a window the size of the * whole screen (or reusing the old one, if it's still around), mapping it, * painting it white and then black, and then unmapping it. We set saveunder so * that all the windows behind it come back immediately. * * Unlike frame flashes, we don't do fullscreen flashes with a timeout; rather, * we do them in one go, because we don't have to rely on the theme code * redrawing the frame for us in order to do the flash. * * \param display The display which owns the screen (rather redundant) * \param screen The screen to flash * * \bug The way I read it, this appears not to do the flash * the first time we flash a particular display. Am I wrong? * * \bug This appears to destroy our current XSync status. */ static void bell_flash_screen (MetaDisplay *display, MetaScreen *screen) { Window root = screen->xroot; int width = screen->rect.width; int height = screen->rect.height; if (screen->flash_window == None) { Visual *visual = (Visual *)CopyFromParent; XSetWindowAttributes xswa; int depth = CopyFromParent; xswa.save_under = True; xswa.override_redirect = True; /* * TODO: use XGetVisualInfo and determine which is an * overlay, if one is present, and use the Overlay visual * for this window (for performance reasons). * Not sure how to tell this yet... */ screen->flash_window = XCreateWindow (display->xdisplay, root, 0, 0, width, height, 0, depth, InputOutput, visual, /* note: XSun doesn't like SaveUnder here */ CWSaveUnder | CWOverrideRedirect, &xswa); XSelectInput (display->xdisplay, screen->flash_window, ExposureMask); XMapWindow (display->xdisplay, screen->flash_window); XSync (display->xdisplay, False); XFlush (display->xdisplay); XUnmapWindow (display->xdisplay, screen->flash_window); } else { /* just draw something in the window */ GC gc = XCreateGC (display->xdisplay, screen->flash_window, 0, NULL); XMapWindow (display->xdisplay, screen->flash_window); XSetForeground (display->xdisplay, gc, WhitePixel (display->xdisplay, XScreenNumberOfScreen (screen->xscreen))); XFillRectangle (display->xdisplay, screen->flash_window, gc, 0, 0, width, height); XSetForeground (display->xdisplay, gc, BlackPixel (display->xdisplay, XScreenNumberOfScreen (screen->xscreen))); XFillRectangle (display->xdisplay, screen->flash_window, gc, 0, 0, width, height); XFlush (display->xdisplay); XSync (display->xdisplay, False); XUnmapWindow (display->xdisplay, screen->flash_window); XFreeGC (display->xdisplay, gc); } if (meta_prefs_get_focus_mode () != G_DESKTOP_FOCUS_MODE_CLICK && !display->mouse_mode) meta_display_increment_focus_sentinel (display); XFlush (display->xdisplay); }
// Fill in the red region and identify its center of gravity void track_red (IplImage *frame, Display *dpy) { int xmin, xmax, ymin, ymax; // the boundaries of the red region int top = HEIGHT, bottom = -1, left = WIDTH, right = -1; // if we didn't see any red in the last frame, look everywhere if (searchx == -1 || searchy == -1) { xmin = 0; ymin = 0; xmax = WIDTH; ymax = HEIGHT; } // otherwise only look around the region where we last saw it else { xmin = MAX (0, searchx - SEARCHRANGE); xmax = MIN (WIDTH, searchx + SEARCHRANGE); ymin = MAX (0, searchy - SEARCHRANGE); ymax = MIN (HEIGHT, searchy + SEARCHRANGE); } // search for red pixels RgbImage image (frame); int redxt = 0, redyt = 0; int count = 0; for (int i = ymin; i < ymax; i++) { for (int j = xmin; j < xmax; j++) { int r = image[i][j].r; int g = image[i][j].g; int b = image[i][j].b; if (g < 0x20 && b < 0x20 && r > 0x80) { image[i][j].r=0xFF; image[i][j].g=0x00; image[i][j].b=0x00; redyt += i; redxt += j; count++; top = MIN (top, i); bottom = MAX (bottom, i); left = MIN (left, j); right = MAX (right, j); } }} // if we found enough to make it worth our while, deal with the mouse if (count) { searchx = redxt / count; searchy = redyt / count; float redx = (float) redxt / count / WIDTH; float redy = (float) redyt / count / HEIGHT; int screenx = (int)(redx * 1480.0 - 100); int screeny = (int)(redy * 1000.0 - 100); // move the mouse to the red region's center of gravity XTestFakeMotionEvent (dpy, DefaultScreen (dpy), screenx, screeny, 0); topleft = cvPoint (left, top); bottomright = cvPoint (right, bottom); int thish = bottom - top; int thisw = right - left; // detect whether the user is opening or closing his fist if (shapechange && abs(lasth - thish) < lasth * 1 - CHANGEFACTOR) { int oldstate = state; if (shapechange == CHANGE_GROWING) state = STATE_UP; else state = STATE_DOWN; // only fire events if we're transitioning between // states if(oldstate == STATE_UP && state == STATE_DOWN) { XTestFakeButtonEvent (dpy, 1, 1, 0); } else if(oldstate == STATE_DOWN && state == STATE_UP) { XTestFakeButtonEvent (dpy, 1, 0, 0); } } if (thish < lasth * CHANGEFACTOR) shapechange = CHANGE_SHRINKING; else if (thish * CHANGEFACTOR > lasth) shapechange = CHANGE_GROWING; else shapechange = CHANGE_NONE; lasth = thish; lastw = thisw; XFlush (dpy); } else { searchx = -1; searchy = -1; } }
/** openX disp_image(WSGraph gd, int lc, int hc, int cflg) グラフィックデータ gdをディスプレイ上に表示する. @param gd 表示するグラフィックデータ. @param lc コントラスト調整.これより小さい輝度値は表示しない.0より小さい(-1以下の)場合は自動調整する. @param hc コントラスト調整.これより大きい輝度値は表示しない.0以下の場合は自動調整する. @param cflg 表示モード @b MONOC: グレースケール表示.@b COLOR: カラー表示 (未サポート) @return 表示したウィンドウの識別子. @attention 正しく表示されない場合は,openX.h の COLOR_DEPTH を変更する. @bug カラーデプスが8bitでは正しく表示されない. 表示モードの COLORは完全にサポートされていないので表示がおかしくなる. */ openX disp_image(WSGraph gd, int lc, int hc, int cflg) { int i, j, sl, sh; char *image; int nc = COLOR_NUM; int width, height, dpth, dpb; int tmp, col; unsigned short int* pnt; sWord *imagewk; XImage *ximg; Visual *visl; Pixmap pmap; openX xid; width = gd.xs; height = gd.ys; imagewk = gd.gp; xid = displayOpen(gd.xs, gd.ys, cflg); sl = sh = 1; if (hc<=0) sh = -1; if (lc<0) { sl = -1; lc = SINTMAX; } if (sl<0 || sh<0) { for(i=0; i<width*height; i++){ tmp = *(imagewk + i); if (sl<0) lc = Min(lc, tmp); if (sh<0) hc = Max(hc, tmp); } } hc = Max(hc, lc+2); visl = DefaultVisual(xid.display, xid.screen); dpth = DefaultDepth (xid.display, xid.screen); dpb = dpth/8; if (dpb==3 && COLOR_DEPTH>=32) dpb = 4; image = (char*)malloc(width*height*dpb); for(i=0; i<width*height; i++){ tmp = *(imagewk + i); if (tmp>hc) tmp = hc; if (tmp<lc) tmp = lc; if (cflg==MONOC) tmp = (int)((float)(tmp-lc)*(nc-1)/(hc-lc)); else tmp = (int)(nc-(float)(tmp-lc)*(nc-1)/(hc-lc)-1); col = xid.color_index[tmp]; if (dpb>=3) { for (j=0; j<dpb; j++) image[dpb*i+j] = col; // 24,32bit } else { // 16bit pnt = (unsigned short int*)&(image[dpb*i]); *pnt = col; } } pmap = XCreatePixmap(xid.display, xid.window, width, height, dpth); ximg = XCreateImage(xid.display,visl,dpth,ZPixmap,0,(char*)image,width,height,8,0); XPutImage(xid.display, pmap, xid.gc, ximg, 0, 0, 0, 0, width, height); XSetWindowBackgroundPixmap(xid.display, xid.window, pmap); XMapWindow (xid.display, xid.window); XClearWindow(xid.display, xid.window); XFlush(xid.display); xid.id = 1; return xid; }
//////////////////////////////////////////////////////////// /// /see sfWindowImpl::SetPosition //////////////////////////////////////////////////////////// void WindowImplX11::SetPosition(int Left, int Top) { XMoveWindow(ourDisplay, myWindow, Left, Top); XFlush(ourDisplay); }
// only used internally void makeNativeWindow() { #ifdef __FOR_XORG__ __x_display = XOpenDisplay(NULL); // open the standard display (the primary screen) if (__x_display == NULL) { printf("cannot connect to X server\n"); } Window root = DefaultRootWindow(__x_display); // get the root window (usually the whole screen) XSetWindowAttributes swa; swa.event_mask = ExposureMask | PointerMotionMask | KeyPressMask | KeyReleaseMask; __display_width=1024; __display_height=768; // xorg hard coded for now int s = DefaultScreen(__x_display); __win = XCreateSimpleWindow(__x_display, root, 10, 10, __display_width, __display_height, 1, BlackPixel(__x_display, s), WhitePixel(__x_display, s)); XSelectInput(__x_display, __win, ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask); XSetWindowAttributes xattr; Atom atom; int one = 1; xattr.override_redirect = False; XChangeWindowAttributes(__x_display, __win, CWOverrideRedirect, &xattr); /* atom = XInternAtom(__x_display, "_NET_WM_STATE_FULLSCREEN", True); XChangeProperty(__x_display, win, XInternAtom(__x_display, "_NET_WM_STATE", True), XA_ATOM, 32, PropModeReplace, (unsigned char *)&atom, 1); */ XWMHints hints; hints.input = True; hints.flags = InputHint; XSetWMHints(__x_display, __win, &hints); XMapWindow(__x_display, __win); // make the window visible on the screen XStoreName(__x_display, __win, "GLES2.0 framework"); // give the window a name // NB - RPi needs to use EGL_DEFAULT_DISPLAY that some X configs dont seem to like __egl_display = eglGetDisplay((EGLNativeDisplayType) __x_display); if (__egl_display == EGL_NO_DISPLAY) { printf("Got no EGL display.\n"); } __eventWin = __win; Cursor invisibleCursor; Pixmap bitmapNoData; XColor black; static char noData[] = { 0,0,0,0,0,0,0,0 }; black.red = black.green = black.blue = 0; bitmapNoData = XCreateBitmapFromData(__x_display, __win, noData, 8, 8); invisibleCursor = XCreatePixmapCursor(__x_display, bitmapNoData, bitmapNoData, &black, &black, 0, 0); XDefineCursor(__x_display,__win, invisibleCursor); XFreeCursor(__x_display, invisibleCursor); #endif //__FOR_XORG__ #ifdef __FOR_RPi__ bcm_host_init(); int32_t success = 0; // create an EGL window surface, passing context width/height success = graphics_get_display_size(0 /* LCD */ , &__display_width, &__display_height); if (success < 0) { printf("unable to get display size\n"); //return EGL_FALSE; } __x_display = XOpenDisplay(NULL); // open the standard display (the primary screen) if (__x_display == NULL) { printf("cannot connect to X server\n"); } Window root = DefaultRootWindow(__x_display); // get the root window (usually the whole screen) XSetWindowAttributes swa; swa.event_mask = ExposureMask | PointerMotionMask | KeyPressMask | KeyReleaseMask; int s = DefaultScreen(__x_display); __eventWin = XCreateSimpleWindow(__x_display, root, 0, 0, __display_width, __display_height, 1, BlackPixel(__x_display, s), WhitePixel(__x_display, s)); XSelectInput(__x_display, __eventWin, ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask); XSetWindowAttributes xattr; Atom atom; int one = 1; xattr.override_redirect = False; XChangeWindowAttributes(__x_display, __eventWin, CWOverrideRedirect, &xattr); XWMHints hints; hints.input = True; hints.flags = InputHint; XSetWMHints(__x_display, __eventWin, &hints); XMapWindow(__x_display, __eventWin); // make the window visible on the screen XStoreName(__x_display, __eventWin, "Event trap"); // give the window a name // we have to be full screen to capture all mouse events // TODO consider using warp mouse to report relative motions // instead of absolute... XFlush(__x_display); // you have to flush or bcm seems to prevent window coming up? Atom wmState = XInternAtom(__x_display, "_NET_WM_STATE", False); Atom fullScreen = XInternAtom(__x_display, "_NET_WM_STATE_FULLSCREEN", False); XEvent xev; xev.xclient.type = ClientMessage; xev.xclient.serial = 0; xev.xclient.send_event = True; xev.xclient.window = __eventWin; xev.xclient.message_type = wmState; xev.xclient.format = 32; xev.xclient.data.l[0] = 1; //_NET_WM_STATE_ADD xev.xclient.data.l[1] = fullScreen; xev.xclient.data.l[2] = 0; XSendEvent(__x_display, root, False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); XFlush(__x_display); // you have to flush or bcm seems to prevent window coming up? static EGL_DISPMANX_WINDOW_T nativewindow; DISPMANX_ELEMENT_HANDLE_T dispman_element; DISPMANX_DISPLAY_HANDLE_T dispman_display; DISPMANX_UPDATE_HANDLE_T dispman_update; VC_RECT_T dst_rect; VC_RECT_T src_rect; // printf("display size %i,%i\n",__display_width,__display_height); dst_rect.x = 0; dst_rect.y = 0; dst_rect.width = __display_width; dst_rect.height = __display_height; src_rect.x = 0; src_rect.y = 0; src_rect.width = __display_width << 16; src_rect.height = __display_height << 16; dispman_display = vc_dispmanx_display_open(0 /* LCD */ ); dispman_update = vc_dispmanx_update_start(0); //VC_DISPMANX_ALPHA_T alpha = { DISPMANX_FLAGS_ALPHA_FROM_SOURCE | DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS,255,0 }; VC_DISPMANX_ALPHA_T alpha = { DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS,255,0 }; dispman_element = vc_dispmanx_element_add(dispman_update, dispman_display, 0 /*layer */ , &dst_rect, 0 /*src */ , &src_rect, DISPMANX_PROTECTION_NONE, &alpha /*alpha */ , 0 /*clamp */ , 0 /*transform */ ); nativewindow.element = dispman_element; nativewindow.width = __display_width; nativewindow.height = __display_height; vc_dispmanx_update_submit_sync(dispman_update); __win = &nativewindow; __egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); #endif //__FOR_RPi__ #ifdef __FOR_RPi_noX__ bcm_host_init(); int32_t success = 0; success = graphics_get_display_size(0 /* LCD */ , &__display_width, &__display_height); if (success < 0) { printf("unable to get display size\n"); //return EGL_FALSE; } static EGL_DISPMANX_WINDOW_T nativewindow; DISPMANX_ELEMENT_HANDLE_T dispman_element; DISPMANX_DISPLAY_HANDLE_T dispman_display; DISPMANX_UPDATE_HANDLE_T dispman_update; VC_RECT_T dst_rect; VC_RECT_T src_rect; dst_rect.x = 0; dst_rect.y = 0; dst_rect.width = __display_width; dst_rect.height = __display_height; src_rect.x = 0; src_rect.y = 0; src_rect.width = __display_width << 16; src_rect.height = __display_height << 16; dispman_display = vc_dispmanx_display_open(0 /* LCD */ ); dispman_update = vc_dispmanx_update_start(0); VC_DISPMANX_ALPHA_T alpha = { DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS,255,0 }; dispman_element = vc_dispmanx_element_add(dispman_update, dispman_display, 0 /*layer */ , &dst_rect, 0 /*src */ , &src_rect, DISPMANX_PROTECTION_NONE, &alpha /*alpha */ , 0 /*clamp */ , 0 /*transform */ ); nativewindow.element = dispman_element; nativewindow.width = __display_width; nativewindow.height = __display_height; vc_dispmanx_update_submit_sync(dispman_update); __win = &nativewindow; __egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (__egl_display == EGL_NO_DISPLAY) { printf("Got no EGL display.\n"); } #endif //__FOR_RPi_noX__ }
//////////////////////////////////////////////////////////// /// /see WindowImpl::SetSize //////////////////////////////////////////////////////////// void WindowImplX11::SetSize(unsigned int Width, unsigned int Height) { XResizeWindow(ourDisplay, myWindow, Width, Height); XFlush(ourDisplay); }
void draw_screen(xdisplay * d) { switch (d->image[0]->bits_per_pixel) { case 16:{ unsigned short *de; unsigned char *s; unsigned char *e; for (s = (unsigned char *) d->vbuffs[d->current], e = (unsigned char *) d->vbuffs[d->current] + (d->linewidth * d->height), de = (unsigned short *) d->data[d->current]; s < e; s += 8, de += 8) *de = d->pixels[*s], *(de + 1) = d->pixels[*(s + 1)], *(de + 2) = d->pixels[*(s + 2)], *(de + 3) = d->pixels[*(s + 3)], *(de + 4) = d->pixels[*(s + 4)], *(de + 5) = d->pixels[*(s + 5)], *(de + 6) = d->pixels[*(s + 6)], *(de + 7) = d->pixels[*(s + 7)]; s -= 8; de -= 8; for (; s < e; s++, de++) *de = d->pixels[*s]; break; } case 32:{ unsigned long *de; unsigned char *s; unsigned char *e; for (s = (unsigned char *) d->vbuffs[d->current], e = (unsigned char *) d->vbuffs[d->current] + (d->linewidth * d->height), de = (unsigned long *) d->data[d->current]; s < e; s += 8, de += 8) *de = d->pixels[*s], *(de + 1) = d->pixels[*(s + 1)], *(de + 2) = d->pixels[*(s + 2)], *(de + 3) = d->pixels[*(s + 3)], *(de + 4) = d->pixels[*(s + 4)], *(de + 5) = d->pixels[*(s + 5)], *(de + 6) = d->pixels[*(s + 6)], *(de + 7) = d->pixels[*(s + 7)]; s -= 8; de -= 8; for (; s < e; s++, de++) *de = d->pixels[*s]; break; } } #ifdef MITSHM if (d->SharedMemFlag) { XShmPutImage(d->display, d->window, d->gc, d->image[d->current], 0, 0, 0, 0, d->width, d->height, True); XFlush(d->display); } else #endif { XPutImage(d->display, d->window, d->gc, d->image[d->current], 0, 0, 0, 0, d->width, d->height); XFlush(d->display); } d->screen_changed = 0; }
void _resize_frame(Display* display, struct Frame* frame, const struct Workarea *workarea, struct Themes *themes, Bool enlarge_background_frames) { /*Do not move or resize fullscreen windows */ if(frame->state == fullscreen) return; XMoveResizeWindow(display, frame->widgets[frame_parent].widget, frame->x, frame->y, frame->w, frame->h); XMoveResizeWindow(display, frame->framed_window, 0, 0, frame->w - frame->hspace, frame->h - frame->vspace); if((frame->w - frame->hspace) % frame->width_inc) { #ifdef SHOW_FRAME_INC printf("Width remainder %d of inc %d, offset %d \n", (frame->w - frame->hspace) % frame->width_inc , frame->width_inc, frame->w_inc_offset); #endif } if((frame->h - frame->vspace) % frame->height_inc) { #ifdef SHOW_FRAME_INC printf("Height remainder %d of inc %d, offset %d \n", (frame->h - frame->vspace) % frame->height_inc , frame->height_inc, frame->h_inc_offset); #endif } /* Bit of a hack to make the title menu use only the minimum space required */ int title_menu_text_diff = 0; int title_menu_rhs_w = 0; int mode_menu_text_diff = 0; if(themes->window_type[frame->theme_type][title_menu_rhs].exists) title_menu_rhs_w = themes->window_type[frame->theme_type][title_menu_rhs].w; for(int i = 0; i < frame_parent; i++) { int x = themes->window_type[frame->theme_type][i].x; int y = themes->window_type[frame->theme_type][i].y; int w = themes->window_type[frame->theme_type][i].w; int h = themes->window_type[frame->theme_type][i].h; if(!themes->window_type[frame->theme_type][i].exists) continue; //the exists variable is -1 for hotspots if(x < 0 || y < 0 || w <= 0 || h <= 0) { //only resize those which are dependent on the width if(x < 0) x += frame->w; if(y < 0) y += frame->h; if(w <= 0) w += frame->w; if(h <= 0) h += frame->h; /* Bit of a hack to make the title menu use only the minimum space required */ if(i == title_menu_text && (frame->menu.width + title_menu_rhs_w) < w) { title_menu_text_diff = w - (frame->menu.width + title_menu_rhs_w); int mode_menu_extra_space = w - (frame->menu.width + title_menu_rhs_w); //mode_menu_extra_space this is the amount "given up" by reducing the title menu width w = frame->menu.width; if(mode_menu_extra_space > themes->mode_pulldown_width) { mode_menu_text_diff = themes->mode_pulldown_width; } else mode_menu_text_diff = mode_menu_extra_space; if(mode_menu_text_diff < 0) mode_menu_text_diff = 0; } /* title_menu_text is processed before */ else if(i == title_menu_rhs && title_menu_text_diff) x -= title_menu_text_diff; else if(i == title_menu_hotspot && title_menu_text_diff) w -= title_menu_text_diff; if(i == mode_dropdown_lhs) { x -= mode_menu_text_diff; } else if(i == mode_dropdown_text || i == mode_dropdown_hotspot) { x -= mode_menu_text_diff; w += mode_menu_text_diff; } XMoveResizeWindow(display, frame->widgets[i].widget, x, y, w, h); // These windows aren't resized normally, but will need to be when the screen resolution has changed // Othwerwise there will be black borders around a window if(enlarge_background_frames && i != window) { //don't create state windows for the framed window if(themes->window_type[frame->theme_type][i].w <= 0) w = workarea->screen_width; if(themes->window_type[frame->theme_type][i].h <= 0) h = workarea->screen_height; for(int j = 0; j <= inactive; j++) { XResizeWindow(display, frame->widgets[i].state[j], w, h); } } } } XFlush(display); }
BOOL xf_sw_end_paint(rdpContext* context) { int i; INT32 x, y; UINT32 w, h; int ninvalid; HGDI_RGN cinvalid; xfContext* xfc = (xfContext*) context; rdpGdi* gdi = context->gdi; x = gdi->primary->hdc->hwnd->invalid->x; y = gdi->primary->hdc->hwnd->invalid->y; w = gdi->primary->hdc->hwnd->invalid->w; h = gdi->primary->hdc->hwnd->invalid->h; ninvalid = gdi->primary->hdc->hwnd->ninvalid; cinvalid = gdi->primary->hdc->hwnd->cinvalid; if (!xfc->remote_app) { if (!xfc->complex_regions) { if (gdi->primary->hdc->hwnd->invalid->null) return TRUE; xf_lock_x11(xfc, FALSE); XPutImage(xfc->display, xfc->primary, xfc->gc, xfc->image, x, y, x, y, w, h); xf_draw_screen(xfc, x, y, w, h); xf_unlock_x11(xfc, FALSE); } else { if (gdi->primary->hdc->hwnd->ninvalid < 1) return TRUE; xf_lock_x11(xfc, FALSE); for (i = 0; i < ninvalid; i++) { x = cinvalid[i].x; y = cinvalid[i].y; w = cinvalid[i].w; h = cinvalid[i].h; XPutImage(xfc->display, xfc->primary, xfc->gc, xfc->image, x, y, x, y, w, h); xf_draw_screen(xfc, x, y, w, h); } XFlush(xfc->display); xf_unlock_x11(xfc, FALSE); } } else { if (gdi->primary->hdc->hwnd->invalid->null) return TRUE; xf_lock_x11(xfc, FALSE); xf_rail_paint(xfc, x, y, x + w - 1, y + h - 1); xf_unlock_x11(xfc, FALSE); } return TRUE; }
//-------------------------------------------------------------------------------------------------// void GLXWindow::create(const String& name, uint width, uint height, bool fullScreen, const NameValuePairList *miscParams) { Display *xDisplay = mGLSupport->getXDisplay(); String title = name; uint samples = 0; short frequency = 0; bool vsync = false; unsigned int vsyncInterval = 1; int gamma = 0; ::GLXContext glxContext = 0; ::GLXDrawable glxDrawable = 0; Window externalWindow = 0; Window parentWindow = DefaultRootWindow(xDisplay); int left = DisplayWidth(xDisplay, DefaultScreen(xDisplay))/2 - width/2; int top = DisplayHeight(xDisplay, DefaultScreen(xDisplay))/2 - height/2; mIsFullScreen = fullScreen; if(miscParams) { NameValuePairList::const_iterator opt; NameValuePairList::const_iterator end = miscParams->end(); // NB: Do not try to implement the externalGLContext option. // // Accepting a non-current context would expose us to the // risk of segfaults when we made it current. Since the // application programmers would be responsible for these // segfaults, they are better discovering them in their code. if ((opt = miscParams->find("currentGLContext")) != end && StringConverter::parseBool(opt->second)) { if (! glXGetCurrentContext()) { OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "currentGLContext was specified with no current GL context", "GLXWindow::create"); } glxContext = glXGetCurrentContext(); glxDrawable = glXGetCurrentDrawable(); } // Note: Some platforms support AA inside ordinary windows if((opt = miscParams->find("FSAA")) != end) samples = StringConverter::parseUnsignedInt(opt->second); if((opt = miscParams->find("displayFrequency")) != end) frequency = (short)StringConverter::parseInt(opt->second); if((opt = miscParams->find("vsync")) != end) vsync = StringConverter::parseBool(opt->second); if((opt = miscParams->find("vsyncInterval")) != end) vsyncInterval = StringConverter::parseUnsignedInt(opt->second); if ((opt = miscParams->find("gamma")) != end) gamma = StringConverter::parseBool(opt->second); if((opt = miscParams->find("left")) != end) left = StringConverter::parseInt(opt->second); if((opt = miscParams->find("top")) != end) top = StringConverter::parseInt(opt->second); if((opt = miscParams->find("title")) != end) title = opt->second; if ((opt = miscParams->find("externalGLControl")) != end) mIsExternalGLControl = StringConverter::parseBool(opt->second); if((opt = miscParams->find("parentWindowHandle")) != end) { vector<String>::type tokens = StringUtil::split(opt->second, " :"); if (tokens.size() == 3) { // deprecated display:screen:xid format parentWindow = StringConverter::parseUnsignedLong(tokens[2]); } else { // xid format parentWindow = StringConverter::parseUnsignedLong(tokens[0]); } } else if((opt = miscParams->find("externalWindowHandle")) != end) { vector<String>::type tokens = StringUtil::split(opt->second, " :"); LogManager::getSingleton().logMessage( "GLXWindow::create: The externalWindowHandle parameter is deprecated.\n" "Use the parentWindowHandle or currentGLContext parameter instead."); if (tokens.size() == 3) { // Old display:screen:xid format // The old GLX code always created a "parent" window in this case: parentWindow = StringConverter::parseUnsignedLong(tokens[2]); } else if (tokens.size() == 4) { // Old display:screen:xid:visualinfo format externalWindow = StringConverter::parseUnsignedLong(tokens[2]); } else { // xid format externalWindow = StringConverter::parseUnsignedLong(tokens[0]); } } } // Ignore fatal XErrorEvents during parameter validation: oldXErrorHandler = XSetErrorHandler(safeXErrorHandler); // Validate parentWindowHandle if (parentWindow != DefaultRootWindow(xDisplay)) { XWindowAttributes windowAttrib; if (! XGetWindowAttributes(xDisplay, parentWindow, &windowAttrib) || windowAttrib.root != DefaultRootWindow(xDisplay)) { OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Invalid parentWindowHandle (wrong server or screen)", "GLXWindow::create"); } } // Validate externalWindowHandle if (externalWindow != 0) { XWindowAttributes windowAttrib; if (! XGetWindowAttributes(xDisplay, externalWindow, &windowAttrib) || windowAttrib.root != DefaultRootWindow(xDisplay)) { OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Invalid externalWindowHandle (wrong server or screen)", "GLXWindow::create"); } glxDrawable = externalWindow; } // Derive fbConfig ::GLXFBConfig fbConfig = 0; if (glxDrawable) { fbConfig = mGLSupport->getFBConfigFromDrawable (glxDrawable, &width, &height); } if (! fbConfig && glxContext) { fbConfig = mGLSupport->getFBConfigFromContext (glxContext); } mIsExternal = (glxDrawable != 0); XSetErrorHandler(oldXErrorHandler); if (! fbConfig) { int minAttribs[] = { GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_RED_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_GREEN_SIZE, 1, None }; int maxAttribs[] = { GLX_SAMPLES, samples, GLX_DOUBLEBUFFER, 1, GLX_STENCIL_SIZE, INT_MAX, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, 1, None }; fbConfig = mGLSupport->selectFBConfig(minAttribs, maxAttribs); if (gamma != 0) { mGLSupport->getFBConfigAttrib(fbConfig, GL_FRAMEBUFFER_SRGB_CAPABLE_EXT, &gamma); } mHwGamma = (gamma != 0); } if (! fbConfig) { // This should never happen. OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Unexpected failure to determine a GLXFBConfig","GLXWindow::create"); } mIsTopLevel = (! mIsExternal && parentWindow == DefaultRootWindow(xDisplay)); if (! mIsTopLevel) { mIsFullScreen = false; left = top = 0; } if (mIsFullScreen) { mGLSupport->switchMode (width, height, frequency); } if (! mIsExternal) { XSetWindowAttributes attr; ulong mask; XVisualInfo *visualInfo = mGLSupport->getVisualFromFBConfig (fbConfig); attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap(xDisplay, DefaultRootWindow(xDisplay), visualInfo->visual, AllocNone); attr.event_mask = StructureNotifyMask | VisibilityChangeMask | FocusChangeMask; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; if(mIsFullScreen && mGLSupport->mAtomFullScreen == None) { LogManager::getSingleton().logMessage("GLXWindow::switchFullScreen: Your WM has no fullscreen support"); // A second best approach for outdated window managers attr.backing_store = NotUseful; attr.save_under = False; attr.override_redirect = True; mask |= CWSaveUnder | CWBackingStore | CWOverrideRedirect; left = top = 0; } // Create window on server mWindow = XCreateWindow(xDisplay, parentWindow, left, top, width, height, 0, visualInfo->depth, InputOutput, visualInfo->visual, mask, &attr); XFree(visualInfo); if(!mWindow) { OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Unable to create an X Window", "GLXWindow::create"); } if (mIsTopLevel) { XWMHints *wmHints; XSizeHints *sizeHints; if ((wmHints = XAllocWMHints()) != NULL) { wmHints->initial_state = NormalState; wmHints->input = True; wmHints->flags = StateHint | InputHint; int depth = DisplayPlanes(xDisplay, DefaultScreen(xDisplay)); // Check if we can give it an icon if(depth == 24 || depth == 32) { if(mGLSupport->loadIcon("GLX_icon.png", &wmHints->icon_pixmap, &wmHints->icon_mask)) { wmHints->flags |= IconPixmapHint | IconMaskHint; } } } // Is this really necessary ? Which broken WM might need it? if ((sizeHints = XAllocSizeHints()) != NULL) { sizeHints->flags = USPosition; } XTextProperty titleprop; char *lst = (char*)title.c_str(); XStringListToTextProperty((char **)&lst, 1, &titleprop); XSetWMProperties(xDisplay, mWindow, &titleprop, NULL, NULL, 0, sizeHints, wmHints, NULL); XFree(titleprop.value); XFree(wmHints); XFree(sizeHints); XSetWMProtocols(xDisplay, mWindow, &mGLSupport->mAtomDeleteWindow, 1); XWindowAttributes windowAttrib; XGetWindowAttributes(xDisplay, mWindow, &windowAttrib); left = windowAttrib.x; top = windowAttrib.y; width = windowAttrib.width; height = windowAttrib.height; } glxDrawable = mWindow; XMapWindow(xDisplay, mWindow); if (mIsFullScreen) { switchFullScreen (true); } XFlush(xDisplay); WindowEventUtilities::_addRenderWindow(this); } mContext = new GLXContext(mGLSupport, fbConfig, glxDrawable, glxContext); ::GLXDrawable oldDrawable = glXGetCurrentDrawable(); ::GLXContext oldContext = glXGetCurrentContext(); mContext->setCurrent(); if (! mIsExternalGLControl && GLXEW_SGI_swap_control) { glXSwapIntervalSGI (vsync ? vsyncInterval : 0); } mContext->endCurrent(); glXMakeCurrent (mGLSupport->getGLDisplay(), oldDrawable, oldContext); int fbConfigID; mGLSupport->getFBConfigAttrib(fbConfig, GLX_FBCONFIG_ID, &fbConfigID); LogManager::getSingleton().logMessage("GLXWindow::create used FBConfigID = " + StringConverter::toString(fbConfigID)); mName = name; mWidth = width; mHeight = height; mLeft = left; mTop = top; mActive = true; mClosed = false; }
BOOL xf_hw_end_paint(rdpContext* context) { INT32 x, y; UINT32 w, h; xfContext* xfc = (xfContext*) context; if (!xfc->remote_app) { if (!xfc->complex_regions) { if (xfc->hdc->hwnd->invalid->null) return TRUE; x = xfc->hdc->hwnd->invalid->x; y = xfc->hdc->hwnd->invalid->y; w = xfc->hdc->hwnd->invalid->w; h = xfc->hdc->hwnd->invalid->h; xf_lock_x11(xfc, FALSE); xf_draw_screen(xfc, x, y, w, h); xf_unlock_x11(xfc, FALSE); } else { int i; int ninvalid; HGDI_RGN cinvalid; if (xfc->hdc->hwnd->ninvalid < 1) return TRUE; ninvalid = xfc->hdc->hwnd->ninvalid; cinvalid = xfc->hdc->hwnd->cinvalid; xf_lock_x11(xfc, FALSE); for (i = 0; i < ninvalid; i++) { x = cinvalid[i].x; y = cinvalid[i].y; w = cinvalid[i].w; h = cinvalid[i].h; xf_draw_screen(xfc, x, y, w, h); } XFlush(xfc->display); xf_unlock_x11(xfc, FALSE); } } else { if (xfc->hdc->hwnd->invalid->null) return TRUE; x = xfc->hdc->hwnd->invalid->x; y = xfc->hdc->hwnd->invalid->y; w = xfc->hdc->hwnd->invalid->w; h = xfc->hdc->hwnd->invalid->h; xf_lock_x11(xfc, FALSE); xf_rail_paint(xfc, x, y, x + w - 1, y + h - 1); xf_unlock_x11(xfc, FALSE); } return TRUE; }
/*---------------------------- HandleEvent --------------------------*/ int HandleEvent(XEvent *event) { int i; if(theEvent.xany.window==mainW) { switch (event->type) { case Expose: { XExposeEvent *exp_event = (XExposeEvent *) event; if (exp_event->window==mainW) { DrawWindow(exp_event->x,exp_event->y, exp_event->width, exp_event->height); } } break; case EnterNotify: { if (Selected_Visual_Class==DirectColor) XStoreColors(theDisp,NewCmap,newC,ColorMapSize); if (Selected_Visual_Class!=TrueColor) XInstallColormap(theDisp,NewCmap); } break; case LeaveNotify: { if (Selected_Visual_Class==DirectColor) XStoreColors(theDisp,NewCmap,rootC,ColorMapSize); } break; case KeyPress: { /* allow a quit from the image window */ Handle_KeyPress(event); } break; case MotionNotify: { Handle_Motion(event); } break; case ConfigureNotify: { XConfigureEvent *conf_event = (XConfigureEvent *) event; if (conf_event->window == cmdW && (conf_event->width != cmd_width || conf_event->height != cmd_height)) XResizeWindow(theDisp,cmdW,cmd_width,cmd_height); if (conf_event->window == mainW && (conf_event->width != zWidth+(color_bar?color_bar_width:0) || conf_event->height != zHeight+info_height)) Resize(conf_event->width-(color_bar?color_bar_width:0), conf_event->height-info_height); } break; case ButtonPress: { if (theEvent.xbutton.button==Button1) { if (selzoom_active) { Selective_Zoom((caddr_t)&one); break; } XDefineCursor(theDisp,mainW,roiCursor); XFlush(theDisp); if (roi_present) draw_roi(roi_x1, roi_y1, roi_x2, roi_y2); roi_active = 1; roi_x1 = theEvent.xmotion.x < zWidth ? (theEvent.xmotion.x>0 ? theEvent.xmotion.x : 0) : zWidth-1; roi_y1 = theEvent.xmotion.y < zHeight ? (theEvent.xmotion.y>0 ? theEvent.xmotion.y : 0) : zHeight-1; roi_x2 = roi_x1; roi_y2 = roi_y1; draw_roi(roi_x1, roi_y1, roi_x2, roi_y2); break; } if (theEvent.xbutton.button==Button2) { XDefineCursor(theDisp,mainW,wlCursor); XClearArea(theDisp,mainW,0,zHeight, zWidth,zHeight+info_height,False); XDrawImageString(theDisp,mainW,theMGC, zWidth-XTextWidth(ol_text_finfo, wl_msg,strlen(wl_msg))-4, zHeight+info_height-4,wl_msg,strlen(wl_msg)); XDrawImageString(theDisp,mainW,theMGC,4, zHeight+info_height-4,loc_msg,strlen(loc_msg)); XFlush(theDisp); break; } if (theEvent.xbutton.button==Button3) { /* note: not really 'iconic' anymore, simply map or unmap */ if (cmdW_State==NormalState) { XUnmapWindow(theDisp,cmdW); cmdW_State = IconicState; } else { XMapWindow(theDisp,cmdW); cmdW_State = NormalState; } break; } } break; case ButtonRelease: { int xa, xb, ya, yb; if (theEvent.xbutton.button==Button1 && roi_active) { roi_active = 0; xa = roi_x1*(Width-1)/(zWidth-1); xb = roi_x2*(Width-1)/(zWidth-1); ya = roi_y1*(Height-1)/(zHeight-1); yb = roi_y2*(Height-1)/(zHeight-1); roi_stats(xa, ya, xb, yb, 0); XDefineCursor(theDisp,mainW,mainCursor); XFlush(theDisp); } if (theEvent.xbutton.button==Button2) { XDefineCursor(theDisp,mainW,mainCursor); XFlush(theDisp); if (Scale_Data && (oUpper != Upper || oLower != Lower)) { Rescale(); Window_Level(Lower,Upper); oLower=Lower; oUpper=Upper; } XClearArea(theDisp,mainW,0,zHeight, zWidth,zHeight+info_height,False); if (wl_display) XDrawImageString(theDisp,mainW,theMGC, zWidth-XTextWidth(ol_text_finfo,wl_msg,strlen(wl_msg))-4, zHeight+info_height-4,wl_msg,strlen(wl_msg)); XDrawImageString(theDisp,mainW,theMGC,4, zHeight+info_height-4,loc_msg,strlen(loc_msg)); update_sliders(); update_msgs(); } } break; case UnmapNotify: { if (bitmap_pad==8) { if (Interpolation_Type==BILINEAR) { bilinear_byte_to_byte(byte_Image, Width, Height, icon_byte_image, ICON_WIDTH, ICON_HEIGHT); } else { nneighbour_byte_to_byte(byte_Image, Width, Height, icon_byte_image, ICON_WIDTH, ICON_HEIGHT); } } else { if (Interpolation_Type==BILINEAR) { bilinear_rgbp_to_rgbp(byte_Image, Width, Height, icon_byte_image, ICON_WIDTH, ICON_HEIGHT); } else { nneighbour_rgbp_to_rgbp(byte_Image, Width, Height, icon_byte_image, ICON_WIDTH, ICON_HEIGHT); } } XPutImage(theDisp,iconW,theMGC,iconImage,0,0,0,0, ICON_WIDTH, ICON_HEIGHT); } break; case CirculateNotify: case MapNotify: case DestroyNotify: case GravityNotify: case ReparentNotify: default: break; } /* end of switch */ } /* other command Window events */ if(theEvent.xany.window==cmdW) { switch (event->type) { case Expose: { update_msgs(); } break; case EnterNotify: { if (Selected_Visual_Class==DirectColor) XStoreColors(theDisp,NewCmap,newC,ColorMapSize); if (Selected_Visual_Class!=TrueColor) XInstallColormap(theDisp,NewCmap); } break; case LeaveNotify: { if (Selected_Visual_Class==DirectColor) XStoreColors(theDisp,NewCmap,rootC,ColorMapSize); } break; case UnmapNotify: { cmdW_State = IconicState; } break; case MapNotify: { cmdW_State = NormalState; } break; case ConfigureNotify: { XConfigureEvent *conf_event = (XConfigureEvent *) event; if (conf_event->window == cmdW && (conf_event->width != cmd_width || conf_event->height != cmd_height)) XResizeWindow(theDisp,cmdW,cmd_width,cmd_height); } break; default: break; } } /* button press events */ if (XFindContext(theDisp, theEvent.xany.window, xwin_context, (caddr_t *) &which_xwin)==0) { if(*(which_xwin->event_handler)!=NULL) (*(which_xwin->event_handler))(which_xwin); if (Scale_Data && (oUpper != Upper || oLower != Lower)) { Rescale(); oLower=Lower; oUpper=Upper; } } }
BOOL xf_create_window(xfContext* xfc) { XGCValues gcv; XEvent xevent; int width, height; char* windowTitle; rdpSettings* settings = xfc->settings; ZeroMemory(&xevent, sizeof(xevent)); width = xfc->sessionWidth; height = xfc->sessionHeight; if (!xfc->hdc) if (!(xfc->hdc = gdi_CreateDC(CLRBUF_32BPP, xfc->bpp))) return FALSE; if (!xfc->remote_app) { xfc->attribs.background_pixel = BlackPixelOfScreen(xfc->screen); xfc->attribs.border_pixel = WhitePixelOfScreen(xfc->screen); xfc->attribs.backing_store = xfc->primary ? NotUseful : Always; xfc->attribs.override_redirect = False; xfc->attribs.colormap = xfc->colormap; xfc->attribs.bit_gravity = NorthWestGravity; xfc->attribs.win_gravity = NorthWestGravity; #ifdef WITH_XRENDER xfc->offset_x = 0; xfc->offset_y = 0; #endif if (settings->WindowTitle) { windowTitle = _strdup(settings->WindowTitle); if (!windowTitle) return FALSE; } else if (settings->ServerPort == 3389) { windowTitle = malloc(1 + sizeof("FreeRDP: ") + strlen(settings->ServerHostname)); sprintf(windowTitle, "FreeRDP: %s", settings->ServerHostname); } else { windowTitle = malloc(1 + sizeof("FreeRDP: ") + strlen(settings->ServerHostname) + sizeof(":00000")); sprintf(windowTitle, "FreeRDP: %s:%i", settings->ServerHostname, settings->ServerPort); } #ifdef WITH_XRENDER if (settings->SmartSizing && !xfc->fullscreen) { if (settings->SmartSizingWidth) width = settings->SmartSizingWidth; if (settings->SmartSizingHeight) height = settings->SmartSizingHeight; xfc->scaledWidth = width; xfc->scaledHeight = height; } #endif xfc->window = xf_CreateDesktopWindow(xfc, windowTitle, width, height); free(windowTitle); if (xfc->fullscreen) xf_SetWindowFullscreen(xfc, xfc->window, xfc->fullscreen); xfc->unobscured = (xevent.xvisibility.state == VisibilityUnobscured); XSetWMProtocols(xfc->display, xfc->window->handle, &(xfc->WM_DELETE_WINDOW), 1); xfc->drawable = xfc->window->handle; } else { xfc->drawable = DefaultRootWindow(xfc->display); } ZeroMemory(&gcv, sizeof(gcv)); if (xfc->modifierMap) XFreeModifiermap(xfc->modifierMap); xfc->modifierMap = XGetModifierMapping(xfc->display); if (!xfc->gc) xfc->gc = XCreateGC(xfc->display, xfc->drawable, GCGraphicsExposures, &gcv); if (!xfc->primary) xfc->primary = XCreatePixmap(xfc->display, xfc->drawable, xfc->sessionWidth, xfc->sessionHeight, xfc->depth); xfc->drawing = xfc->primary; if (!xfc->bitmap_mono) xfc->bitmap_mono = XCreatePixmap(xfc->display, xfc->drawable, 8, 8, 1); if (!xfc->gc_mono) xfc->gc_mono = XCreateGC(xfc->display, xfc->bitmap_mono, GCGraphicsExposures, &gcv); XSetFunction(xfc->display, xfc->gc, GXcopy); XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetForeground(xfc->display, xfc->gc, BlackPixelOfScreen(xfc->screen)); XFillRectangle(xfc->display, xfc->primary, xfc->gc, 0, 0, xfc->sessionWidth, xfc->sessionHeight); XFlush(xfc->display); if (!xfc->image) xfc->image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0, (char*) xfc->primary_buffer, xfc->sessionWidth, xfc->sessionHeight, xfc->scanline_pad, 0); return TRUE; }
void xf_end_paint(rdpUpdate* update) { GDI* gdi; xfInfo* xfi; sint32 x, y; uint32 w, h; gdi = GET_GDI(update); xfi = GET_XFI(update); if (xfi->remote_app != True) { if (xfi->complex_regions != True) { if (gdi->primary->hdc->hwnd->invalid->null) return; x = gdi->primary->hdc->hwnd->invalid->x; y = gdi->primary->hdc->hwnd->invalid->y; w = gdi->primary->hdc->hwnd->invalid->w; h = gdi->primary->hdc->hwnd->invalid->h; XPutImage(xfi->display, xfi->primary, xfi->gc, xfi->image, x, y, x, y, w, h); XCopyArea(xfi->display, xfi->primary, xfi->window->handle, xfi->gc, x, y, w, h, x, y); } else { int i; int ninvalid; HGDI_RGN cinvalid; if (gdi->primary->hdc->hwnd->ninvalid < 1) return; ninvalid = gdi->primary->hdc->hwnd->ninvalid; cinvalid = gdi->primary->hdc->hwnd->cinvalid; for (i = 0; i < ninvalid; i++) { x = cinvalid[i].x; y = cinvalid[i].y; w = cinvalid[i].w; h = cinvalid[i].h; XPutImage(xfi->display, xfi->primary, xfi->gc, xfi->image, x, y, x, y, w, h); XCopyArea(xfi->display, xfi->primary, xfi->window->handle, xfi->gc, x, y, w, h, x, y); } XFlush(xfi->display); } } else { if (gdi->primary->hdc->hwnd->invalid->null) return; x = gdi->primary->hdc->hwnd->invalid->x; y = gdi->primary->hdc->hwnd->invalid->y; w = gdi->primary->hdc->hwnd->invalid->w; h = gdi->primary->hdc->hwnd->invalid->h; xf_rail_paint(xfi, update->rail, x, y, x + w - 1, y + h - 1); } }
//////////////////////////////////////////////////////////// /// /see WindowImpl::ShowMouseCursor //////////////////////////////////////////////////////////// void WindowImplX11::ShowMouseCursor(bool Show) { XDefineCursor(ourDisplay, myWindow, Show ? None : myHiddenCursor); XFlush(ourDisplay); }
// // I_GetClipboardText // // by Denis Lukianov - 20 Mar 2006 // Cross-platform clipboard functionality // std::string I_GetClipboardText (void) { #ifdef X11 std::string ret; Display *dis = XOpenDisplay(NULL); int screen = DefaultScreen(dis); if(!dis) { Printf(PRINT_HIGH, "I_GetClipboardText: XOpenDisplay failed"); return ""; } XLockDisplay(dis); Window WindowEvents = XCreateSimpleWindow(dis, RootWindow(dis, screen), 0, 0, 1, 1, 0, BlackPixel(dis, screen), BlackPixel(dis, screen)); if(XGetSelectionOwner(dis, XA_PRIMARY) != None) { if(!XConvertSelection(dis, XA_PRIMARY, XA_STRING, XA_PRIMARY, WindowEvents, CurrentTime)) { XDestroyWindow(dis, WindowEvents); XUnlockDisplay(dis); XCloseDisplay(dis); Printf(PRINT_HIGH, "I_GetClipboardText: XConvertSelection failed"); return ""; } XFlush (dis); // Wait for the reply for(;;) { XEvent e; XNextEvent(dis, &e); if(e.type == SelectionNotify) break; } Atom type; int format, result; u_long len, bytes_left, temp; u_char *data; result = XGetWindowProperty(dis, WindowEvents, XA_PRIMARY, 0, 0, False, AnyPropertyType, &type, &format, &len, &bytes_left, &data); if(result != Success) { XDestroyWindow(dis, WindowEvents); XUnlockDisplay(dis); XCloseDisplay(dis); Printf(PRINT_HIGH, "I_GetClipboardText: XGetWindowProperty failed(1)"); return ""; } if(!bytes_left) { XDestroyWindow(dis, WindowEvents); DPrintf("I_GetClipboardText: Len was: %d", len); XUnlockDisplay(dis); XCloseDisplay(dis); return ""; } result = XGetWindowProperty(dis, WindowEvents, XA_PRIMARY, 0, bytes_left, False, AnyPropertyType, &type, &format, &len, &temp, &data); if(result != Success) { XDestroyWindow(dis, WindowEvents); XUnlockDisplay(dis); XCloseDisplay(dis); Printf(PRINT_HIGH, "I_GetClipboardText: XGetWindowProperty failed(2)"); return ""; } ret = std::string((const char *)data, len); XFree(data); } XDestroyWindow(dis, WindowEvents); XUnlockDisplay(dis); XCloseDisplay(dis); return ret; #endif #if defined WIN32 && !defined _XBOX std::string ret; if(!IsClipboardFormatAvailable(CF_TEXT)) return ""; if(!OpenClipboard(NULL)) return ""; HANDLE hClipboardData = GetClipboardData(CF_TEXT); if(!hClipboardData) { CloseClipboard(); return ""; } const char *cData = reinterpret_cast<const char *>(GlobalLock(hClipboardData)); SIZE_T uiSize = static_cast<SIZE_T>(GlobalSize(hClipboardData)); if(cData && uiSize) { for(size_t i = 0; i < uiSize; i++) { if(!cData[i]) { uiSize = i; break; } } ret = std::string(cData, uiSize); } GlobalUnlock(hClipboardData); CloseClipboard(); return ret; #endif #ifdef OSX ScrapRef scrap; Size size; int err = GetCurrentScrap(&scrap); if(err) { Printf(PRINT_HIGH, "GetCurrentScrap error: %d", err); return ""; } err = GetScrapFlavorSize(scrap, FOUR_CHAR_CODE('TEXT'), &size); if(err) { Printf(PRINT_HIGH, "GetScrapFlavorSize error: %d", err); return ""; } char *data = new char[size+1]; err = GetScrapFlavorData(scrap, FOUR_CHAR_CODE('TEXT'), &size, data); data[size] = 0; if(err) { Printf(PRINT_HIGH, "GetScrapFlavorData error: %d", err); delete[] data; return ""; } std::string ret(data); delete[] data; return ret; #endif return ""; }
//////////////////////////////////////////////////////////// /// /see sfWindowImpl::SetCursorPosition //////////////////////////////////////////////////////////// void WindowImplX11::SetCursorPosition(unsigned int Left, unsigned int Top) { XWarpPointer(ourDisplay, None, myWindow, 0, 0, 0, 0, Left, Top); XFlush(ourDisplay); }
/* ** GLW_SetMode */ int GLW_SetMode( const char *drivername, int mode, qboolean fullscreen ) { int attrib[] = { GLX_RGBA, // 0 GLX_RED_SIZE, 4, // 1, 2 GLX_GREEN_SIZE, 4, // 3, 4 GLX_BLUE_SIZE, 4, // 5, 6 GLX_DOUBLEBUFFER, // 7 GLX_DEPTH_SIZE, 1, // 8, 9 GLX_STENCIL_SIZE, 1, // 10, 11 None }; // these match in the array #define ATTR_RED_IDX 2 #define ATTR_GREEN_IDX 4 #define ATTR_BLUE_IDX 6 #define ATTR_DEPTH_IDX 9 #define ATTR_STENCIL_IDX 11 Window root; XVisualInfo *visinfo; XSetWindowAttributes attr; XSizeHints sizehints; unsigned long mask; int colorbits, depthbits, stencilbits; int tcolorbits, tdepthbits, tstencilbits; int dga_MajorVersion, dga_MinorVersion; int actualWidth, actualHeight; int i; const char* glstring; // bk001130 - from cvs1.17 (mkv) ri.Printf( PRINT_ALL, "Initializing OpenGL display\n"); ri.Printf (PRINT_ALL, "...setting mode %d:", mode ); if ( !R_GetModeInfo( &glConfig.vidWidth, &glConfig.vidHeight, &glConfig.windowAspect, mode ) ) { ri.Printf( PRINT_ALL, " invalid mode\n" ); return RSERR_INVALID_MODE; } ri.Printf( PRINT_ALL, " %d %d\n", glConfig.vidWidth, glConfig.vidHeight); if (!(dpy = XOpenDisplay(NULL))) { fprintf(stderr, "Error couldn't open the X display\n"); return RSERR_INVALID_MODE; } scrnum = DefaultScreen(dpy); root = RootWindow(dpy, scrnum); actualWidth = glConfig.vidWidth; actualHeight = glConfig.vidHeight; // Get video mode list #ifdef HAVE_XF86DGA if (!XF86VidModeQueryVersion(dpy, &vidmode_MajorVersion, &vidmode_MinorVersion)) { #endif /* HAVE_XF86DGA */ vidmode_ext = qfalse; #ifdef HAVE_XF86DGA } else { ri.Printf(PRINT_ALL, "Using XFree86-VidModeExtension Version %d.%d\n", vidmode_MajorVersion, vidmode_MinorVersion); vidmode_ext = qtrue; } #endif /* HAVE_XF86DGA */ // Check for DGA dga_MajorVersion = 0, dga_MinorVersion = 0; #ifdef HAVE_XF86DGA if (in_dgamouse->value) { if (!XF86DGAQueryVersion(dpy, &dga_MajorVersion, &dga_MinorVersion)) { // unable to query, probably not supported ri.Printf( PRINT_ALL, "Failed to detect XF86DGA Mouse\n" ); ri.Cvar_Set( "in_dgamouse", "0" ); } else { ri.Printf( PRINT_ALL, "XF86DGA Mouse (Version %d.%d) initialized\n", dga_MajorVersion, dga_MinorVersion); } } #endif /* HAVE_XF86DGA */ #ifdef HAVE_XF86DGA if (vidmode_ext) { int best_fit, best_dist, dist, x, y; XF86VidModeGetAllModeLines(dpy, scrnum, &num_vidmodes, &vidmodes); // Are we going fullscreen? If so, let's change video mode if (fullscreen) { best_dist = 9999999; best_fit = -1; for (i = 0; i < num_vidmodes; i++) { if (glConfig.vidWidth > vidmodes[i]->hdisplay || glConfig.vidHeight > vidmodes[i]->vdisplay) continue; x = glConfig.vidWidth - vidmodes[i]->hdisplay; y = glConfig.vidHeight - vidmodes[i]->vdisplay; dist = (x * x) + (y * y); if (dist < best_dist) { best_dist = dist; best_fit = i; } } if (best_fit != -1) { actualWidth = vidmodes[best_fit]->hdisplay; actualHeight = vidmodes[best_fit]->vdisplay; // change to the mode XF86VidModeSwitchToMode(dpy, scrnum, vidmodes[best_fit]); vidmode_active = qtrue; // Move the viewport to top left XF86VidModeSetViewPort(dpy, scrnum, 0, 0); ri.Printf(PRINT_ALL, "XFree86-VidModeExtension Activated at %dx%d\n", actualWidth, actualHeight); } else { fullscreen = 0; ri.Printf(PRINT_ALL, "XFree86-VidModeExtension: No acceptable modes found\n"); } } else { ri.Printf(PRINT_ALL, "XFree86-VidModeExtension: Ignored on non-fullscreen/Voodoo\n"); } } #endif /* HAVE_XF86DGA */ if (!r_colorbits->value) colorbits = 24; else colorbits = r_colorbits->value; if ( !Q_stricmp( r_glDriver->string, _3DFX_DRIVER_NAME ) ) colorbits = 16; if (!r_depthbits->value) depthbits = 24; else depthbits = r_depthbits->value; stencilbits = r_stencilbits->value; for (i = 0; i < 16; i++) { // 0 - default // 1 - minus colorbits // 2 - minus depthbits // 3 - minus stencil if ((i % 4) == 0 && i) { // one pass, reduce switch (i / 4) { case 2 : if (colorbits == 24) colorbits = 16; break; case 1 : if (depthbits == 24) depthbits = 16; else if (depthbits == 16) depthbits = 8; case 3 : if (stencilbits == 24) stencilbits = 16; else if (stencilbits == 16) stencilbits = 8; } } tcolorbits = colorbits; tdepthbits = depthbits; tstencilbits = stencilbits; if ((i % 4) == 3) { // reduce colorbits if (tcolorbits == 24) tcolorbits = 16; } if ((i % 4) == 2) { // reduce depthbits if (tdepthbits == 24) tdepthbits = 16; else if (tdepthbits == 16) tdepthbits = 8; } if ((i % 4) == 1) { // reduce stencilbits if (tstencilbits == 24) tstencilbits = 16; else if (tstencilbits == 16) tstencilbits = 8; else tstencilbits = 0; } if (tcolorbits == 24) { attrib[ATTR_RED_IDX] = 8; attrib[ATTR_GREEN_IDX] = 8; attrib[ATTR_BLUE_IDX] = 8; } else { // must be 16 bit attrib[ATTR_RED_IDX] = 4; attrib[ATTR_GREEN_IDX] = 4; attrib[ATTR_BLUE_IDX] = 4; } attrib[ATTR_DEPTH_IDX] = tdepthbits; // default to 24 depth attrib[ATTR_STENCIL_IDX] = tstencilbits; visinfo = qglXChooseVisual(dpy, scrnum, attrib); if (!visinfo) { continue; } ri.Printf( PRINT_ALL, "Using %d/%d/%d Color bits, %d depth, %d stencil display.\n", attrib[ATTR_RED_IDX], attrib[ATTR_GREEN_IDX], attrib[ATTR_BLUE_IDX], attrib[ATTR_DEPTH_IDX], attrib[ATTR_STENCIL_IDX]); glConfig.colorBits = tcolorbits; glConfig.depthBits = tdepthbits; glConfig.stencilBits = tstencilbits; break; } if (!visinfo) { ri.Printf( PRINT_ALL, "Couldn't get a visual\n" ); return RSERR_INVALID_MODE; } /* window attributes */ attr.background_pixel = BlackPixel(dpy, scrnum); attr.border_pixel = 0; attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); attr.event_mask = X_MASK; if (vidmode_active) { mask = CWBackPixel | CWColormap | CWSaveUnder | CWBackingStore | CWEventMask | CWOverrideRedirect; attr.override_redirect = True; attr.backing_store = NotUseful; attr.save_under = False; } else mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; win = XCreateWindow(dpy, root, 0, 0, actualWidth, actualHeight, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr); XStoreName( dpy, win, CLIENT_WINDOW_TITLE ); /* GH: Don't let the window be resized */ sizehints.flags = PMinSize | PMaxSize; sizehints.min_width = sizehints.max_width = actualWidth; sizehints.min_height = sizehints.max_height = actualHeight; XSetWMNormalHints( dpy, win, &sizehints ); XMapWindow( dpy, win ); if (vidmode_active) XMoveWindow(dpy, win, 0, 0); XFlush(dpy); XSync(dpy,False); // bk001130 - from cvs1.17 (mkv) ctx = qglXCreateContext(dpy, visinfo, NULL, True); XSync(dpy,False); // bk001130 - from cvs1.17 (mkv) /* GH: Free the visinfo after we're done with it */ XFree( visinfo ); qglXMakeCurrent(dpy, win, ctx); // bk001130 - from cvs1.17 (mkv) glstring = (char *)qglGetString (GL_RENDERER); ri.Printf( PRINT_ALL, "GL_RENDERER: %s\n", glstring ); // bk010122 - new software token (Indirect) if ( !Q_stricmp( glstring, "Mesa X11") || !Q_stricmp( glstring, "Mesa GLX Indirect") ) { if ( !r_allowSoftwareGL->integer ) { ri.Printf( PRINT_ALL, "\n\n***********************************************************\n" ); ri.Printf( PRINT_ALL, " You are using software Mesa (no hardware acceleration)! \n" ); ri.Printf( PRINT_ALL, " Driver DLL used: %s\n", drivername ); ri.Printf( PRINT_ALL, " If this is intentional, add\n" ); ri.Printf( PRINT_ALL, " \"+set r_allowSoftwareGL 1\"\n" ); ri.Printf( PRINT_ALL, " to the command line when starting the game.\n" ); ri.Printf( PRINT_ALL, "***********************************************************\n"); GLimp_Shutdown( ); return RSERR_INVALID_MODE; } else { ri.Printf( PRINT_ALL, "...using software Mesa (r_allowSoftwareGL==1).\n" ); } } return RSERR_OK; }
int main () { Display *display; Window win; XEvent report; XEvent msg; int x=10,y=10,h=100,w=100; display = XOpenDisplay(NULL); if (display == NULL) { fprintf(stderr, "couldn't connect to X server :0\n"); return 0; } win = XCreateWindow(display, RootWindow(display, 0), x, y, w, h, 0, CopyFromParent, CopyFromParent, CopyFromParent, 0, NULL); XSetWindowBackground(display,win,WhitePixel(display,0)); XSelectInput(display, win, (ExposureMask | StructureNotifyMask | GravityNotify)); XMapWindow(display, win); XFlush(display); sleep(1); XResizeWindow(display, win, w+5, h+5); XMoveWindow(display, win, x, y); while (1) { XNextEvent(display, &report); switch (report.type) { case MapNotify: printf("map notify\n"); break; case Expose: printf("exposed\n"); break; case GravityNotify: printf("gravity notify event 0x%x window 0x%x x %d y %d\n", report.xgravity.event, report.xgravity.window, report.xgravity.x, report.xgravity.y); break; case ConfigureNotify: { int se = report.xconfigure.send_event; int event = report.xconfigure.event; int window = report.xconfigure.window; int x = report.xconfigure.x; int y = report.xconfigure.y; int w = report.xconfigure.width; int h = report.xconfigure.height; int bw = report.xconfigure.border_width; int above = report.xconfigure.above; int or = report.xconfigure.override_redirect; printf("confignotify send %d ev 0x%x win 0x%x %i,%i-%ix%i bw %i\n" " above 0x%x ovrd %d\n", se,event,window,x,y,w,h,bw,above,or); break; } } } return 1; }