void greate_win_flag(xkb_info *k,gpointer data) { //int timer; AConvert *aconv = (AConvert *)data; int revert_to; Window focuswin; XWindowAttributes win_attributes; Window junkwin; int rx, ry, pos_x,pos_y=0; if(aconv->sxkb->view_flag==0) return; XGetInputFocus(GDK_DISPLAY(), &focuswin, &revert_to); if (focuswin) { XGetWindowAttributes(GDK_DISPLAY(), focuswin, &win_attributes); XTranslateCoordinates (GDK_DISPLAY(), focuswin, win_attributes.root, -win_attributes.border_width,-win_attributes.border_width, &rx, &ry, &junkwin); pos_x=rx;//((win_attributes.width/2)+rx); pos_y=ry;//((win_attributes.height/2)+ry); } else { pos_x=0;//200; pos_y=0;//200; } if(!aconv->sxkb->flag_win) { aconv->sxkb->flag_win = gtk_window_new (GTK_WINDOW_POPUP); gtk_widget_set_size_request (GTK_WIDGET(aconv->sxkb->flag_win), 32, 24); gtk_widget_set_uposition(GTK_WIDGET(aconv->sxkb->flag_win),pos_x,pos_y); //gtk_window_set_position (GTK_WINDOW (sven->sxkb->flag_win), GTK_WIN_POS_CENTER); aconv->sxkb->flag_image = gtk_image_new(); gtk_widget_show (aconv->sxkb->flag_image); gtk_container_add (GTK_CONTAINER (aconv->sxkb->flag_win), aconv->sxkb->flag_image); gtk_widget_show_all (aconv->sxkb->flag_win); } else { if (k->flag_img) { GdkPixbuf *pixbuf=gdk_pixbuf_scale_simple (k->flag_img,32,24,GDK_INTERP_BILINEAR); gtk_image_set_from_pixbuf(GTK_IMAGE(aconv->sxkb->flag_image),pixbuf); g_object_unref(pixbuf); } else { GdkPixbuf *pixbuf=create_pixbuf_flag("zz",32,24); gtk_image_set_from_pixbuf(GTK_IMAGE(aconv->sxkb->flag_image),pixbuf); g_object_unref(pixbuf); } gtk_widget_set_uposition(GTK_WIDGET(aconv->sxkb->flag_win),pos_x,pos_y); gtk_widget_show_all (aconv->sxkb->flag_win); } if (aconv->sxkb->timeId != 0) g_source_remove(aconv->sxkb->timeId); aconv->sxkb->timeId = g_timeout_add (800,timer_hide_win, aconv); }
// ===== GetWindowState() ===== LX11::WINDOWSTATE LX11::GetWindowState(WId win, bool forDisplay){ //forDisplay lets the function know whether it needs to follow the TaskBar/Pager ignore rules //OPENBOX DOES NOT SUPPORT THE _NET_WM_STATE VALUES (4/7/14) Display *disp = QX11Info::display(); /* Atom SA = XInternAtom(disp, "_NET_WM_STATE", false); Atom ATTENTION = XInternAtom(disp, "_NET_WM_STATE_DEMANDS_ATTENTION", false); Atom SKIPP = XInternAtom(disp, "_NET_WM_STATE_SKIP_PAGER", false); Atom HIDDEN = XInternAtom(disp, "_NET_WM_STATE_HIDDEN", false); Atom SKIPT = XInternAtom(disp, "_NET_WM_STATE_SKIP_TASKBAR", false); Atom MODAL = XInternAtom(disp, "_NET_WM_STATE_MODAL", false); */ //Atom type; //int format; //unsigned long num, bytes; //unsigned char *data = 0; /* int status = XGetWindowProperty( disp, win, SA, 0, ~(0L), false, AnyPropertyType, &type, &format, &num, &bytes, &data); LX11::WINDOWSTATE state = LX11::VISIBLE; if(status >= Success && data){ Atom *array = (Atom*) data; for(unsigned int i=0; i<num; i++){ if(forDisplay && (array[i] == SKIPP || array[i]==SKIPT || array[i]==MODAL) ){ state = LX11::IGNORE; break; }else if(array[i]==HIDDEN){ qDebug() << "Hidden Window:" << win; state = LX11::INVISIBLE; }else if(array[i]==ATTENTION){ qDebug() << "Attention Window: " << win; state = LX11::ATTENTION; } } XFree(data); } */ LX11::WINDOWSTATE state = LX11::VISIBLE; if(state==LX11::VISIBLE){ //Use another method for detecting whether the window is actually mapped (more reliable) /*Atom STATE = XInternAtom(disp, "WM_STATE", false); //re-use the other variables data = 0; if( 0 != XGetWindowProperty( disp, win, STATE, 0, ~(0L), false, AnyPropertyType, &type, &format, &num, &bytes, &data) ){ qint32 *array = (qint32 *) data; if(array[0]==NormalState){ state = LX11::VISIBLE; } else if(array[0]==IconicState){ state = LX11::INVISIBLE; } else{ qDebug() << "Unknown State:" << win; state = LX11::IGNORE; } } */ XWindowAttributes attr; if( 0 != XGetWindowAttributes(disp, win, &attr) ){ if(attr.map_state==IsUnmapped || attr.map_state==IsUnviewable){ state = LX11::INVISIBLE; } } } //If visible, check whether it is the active window if(state == LX11::VISIBLE){ if(win == LX11::ActiveWindow()){ state = LX11::ACTIVE; } } return state; }
void setup(void) { int x, y, screen = DefaultScreen(dc->dpy); Window root = RootWindow(dc->dpy, screen); XSetWindowAttributes swa; XIM xim; #ifdef XINERAMA int n; XineramaScreenInfo *info; #endif normcol[ColBG] = getcolor(dc, normbgcolor); normcol[ColFG] = getcolor(dc, normfgcolor); selcol[ColBG] = getcolor(dc, selbgcolor); selcol[ColFG] = getcolor(dc, selfgcolor); outcol[ColBG] = getcolor(dc, outbgcolor); outcol[ColFG] = getcolor(dc, outfgcolor); clip = XInternAtom(dc->dpy, "CLIPBOARD", False); utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False); /* calculate menu geometry */ bh = dc->font.height + 2; lines = MAX(lines, 0); mh = (lines + 1) * bh; #ifdef XINERAMA if((info = XineramaQueryScreens(dc->dpy, &n))) { int a, j, di, i = 0, area = 0; unsigned int du; Window w, pw, dw, *dws; XWindowAttributes wa; XGetInputFocus(dc->dpy, &w, &di); if(mon != -1 && mon < n) i = mon; if(!i && w != root && w != PointerRoot && w != None) { /* find top-level window containing current input focus */ do { if(XQueryTree(dc->dpy, (pw = w), &dw, &w, &dws, &du) && dws) XFree(dws); } while(w != root && w != pw); /* find xinerama screen with which the window intersects most */ if(XGetWindowAttributes(dc->dpy, pw, &wa)) for(j = 0; j < n; j++) if((a = INTERSECT(wa.x, wa.y, wa.width, wa.height, info[j])) > area) { area = a; i = j; } } /* no focused window is on screen, so use pointer location instead */ if(mon == -1 && !area && XQueryPointer(dc->dpy, root, &dw, &dw, &x, &y, &di, &di, &du)) for(i = 0; i < n; i++) if(INTERSECT(x, y, 1, 1, info[i])) break; x = info[i].x_org; y = info[i].y_org + (topbar ? 0 : info[i].height - mh); mw = info[i].width; XFree(info); } else #endif { x = 0; y = topbar ? 0 : DisplayHeight(dc->dpy, screen) - mh; mw = DisplayWidth(dc->dpy, screen); } promptw = (prompt && *prompt) ? textw(dc, prompt) : 0; inputw = MIN(inputw, mw/3); match(); /* create menu window */ swa.override_redirect = True; swa.background_pixel = normcol[ColBG]; swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask; win = XCreateWindow(dc->dpy, root, x, y, mw, mh, 0, DefaultDepth(dc->dpy, screen), CopyFromParent, DefaultVisual(dc->dpy, screen), CWOverrideRedirect | CWBackPixel | CWEventMask, &swa); /* open input methods */ xim = XOpenIM(dc->dpy, NULL, NULL, NULL); xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, win, XNFocusWindow, win, NULL); XMapRaised(dc->dpy, win); resizedc(dc, mw, mh); drawmenu(); }
EGLSurface eglCreateWindowSurface(EGLDisplay egldisplay, EGLConfig config, NativeWindowType native_window, EGLint const * attrib_list) { if (x11_enabled == 0) { return real_eglCreateWindowSurface(egldisplay,config,native_window,attrib_list); } window = (Window*) native_window; puts("Getting window information..."); XWindowAttributes window_attributes; XGetWindowAttributes(display,window,&window_attributes); printf("Window Location: %i,%i \n Window Dimensions %i x %i \n Bit depth : %i \n",window_attributes.x,window_attributes.y,window_attributes.width,window_attributes.height,window_attributes.depth); width=window_attributes.width ; height=window_attributes.height; depth=window_attributes.depth; EGLint attr[] = { // some attributes to set up our egl-interface EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_SURFACE_TYPE, EGL_PIXMAP_BIT | EGL_OPENGL_ES2_BIT, EGL_NONE }; EGLConfig ecfg; EGLint num_config; if (!eglChooseConfig(edisplay, attr, &ecfg, 1, &num_config)) { fprintf(stderr, "Failed to choose config (eglError: %s)\n"); return EGL_NO_SURFACE; } EGLint pixel_format = EGL_PIXEL_FORMAT_ARGB_8888_BRCM; EGLint rt; eglGetConfigAttrib(edisplay, ecfg, EGL_RENDERABLE_TYPE, &rt); if (rt & EGL_OPENGL_ES_BIT) { pixel_format |= EGL_PIXEL_FORMAT_RENDER_GLES_BRCM; pixel_format |= EGL_PIXEL_FORMAT_GLES_TEXTURE_BRCM; } if (rt & EGL_OPENGL_ES2_BIT) { pixel_format |= EGL_PIXEL_FORMAT_RENDER_GLES2_BRCM; pixel_format |= EGL_PIXEL_FORMAT_GLES2_TEXTURE_BRCM; } if (rt & EGL_OPENVG_BIT) { pixel_format |= EGL_PIXEL_FORMAT_RENDER_VG_BRCM; pixel_format |= EGL_PIXEL_FORMAT_VG_IMAGE_BRCM; } if (rt & EGL_OPENGL_BIT) { pixel_format |= EGL_PIXEL_FORMAT_RENDER_GL_BRCM; } EGLint pixmap[5]; pixmap[0] = 0; pixmap[1] = 0; pixmap[2] = width; pixmap[3] = height; pixmap[4] = pixel_format; eglCreateGlobalImageBRCM(width, height, pixmap[4], 0, width*4, pixmap); egl_surface = eglCreatePixmapSurface(edisplay, ecfg, pixmap, 0); puts("EGL Surface Created"); EGLint ctxattr[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; EGLContext context = eglCreateContext ( edisplay, ecfg, EGL_NO_CONTEXT, ctxattr ); real_eglMakeCurrent(edisplay, egl_surface, egl_surface, context); return egl_surface; }
static void egg_tray_manager_handle_dock_request(EggTrayManager *manager, XClientMessageEvent *xevent) { GtkWidget *socket; Window *window; ENTER; socket = gtk_socket_new (); gtk_widget_set_app_paintable (socket, TRUE); gtk_widget_set_double_buffered (socket, FALSE); gtk_widget_add_events (socket, GDK_EXPOSURE_MASK); g_signal_connect (socket, "realize", G_CALLBACK (egg_tray_manager_make_socket_transparent), NULL); g_signal_connect (socket, "expose_event", G_CALLBACK (egg_tray_manager_socket_exposed), NULL); g_signal_connect_after (socket, "style_set", G_CALLBACK (egg_tray_manager_socket_style_set), NULL); gtk_widget_show (socket); /* We need to set the child window here * so that the client can call _get functions * in the signal handler */ window = g_new (Window, 1); *window = xevent->data.l[2]; DBG("plug window %lx\n", *window); g_object_set_data_full (G_OBJECT (socket), "egg-tray-child-window", window, g_free); g_signal_emit(manager, manager_signals[TRAY_ICON_ADDED], 0, socket); /* Add the socket only if it's been attached */ if (GTK_IS_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(socket)))) { GtkRequisition req; XWindowAttributes wa; DBG("socket has window. going on\n"); gtk_socket_add_id(GTK_SOCKET (socket), xevent->data.l[2]); g_signal_connect(socket, "plug_removed", G_CALLBACK(egg_tray_manager_plug_removed), manager); gdk_error_trap_push(); XGetWindowAttributes(GDK_DISPLAY(), *window, &wa); if (gdk_error_trap_pop()) { ERR("can't embed window %lx\n", xevent->data.l[2]); goto error; } g_hash_table_insert(manager->socket_table, GINT_TO_POINTER(xevent->data.l[2]), socket); req.width = req.height = 1; gtk_widget_size_request(socket, &req); RET(); } error: DBG("socket has NO window. destroy it\n"); g_signal_emit(manager, manager_signals[TRAY_ICON_REMOVED], 0, socket); gtk_widget_destroy(socket); RET(); }
void TestMap() { XSizeHints *hints; XWindowAttributes attr; Window w; /* Create the window. */ w = XCreateSimpleWindow(display, rootWindow, 100, 100, 200, 100, 0, 0, 0); XSelectInput(display, w, StructureNotifyMask | PropertyNotify); /* Map the window and wait for it. */ XMapWindow(display, w); Assert(AwaitEvent(MapNotify)); /* Unmap the window and wait for it. */ XUnmapWindow(display, w); Assert(AwaitEvent(UnmapNotify)); /* Map the window and wait for it (again). */ XMapWindow(display, w); Assert(AwaitEvent(MapNotify)); /* Minimize and wait. */ Minimize(w); Assert(AwaitEvent(UnmapNotify)); /* Restore and wait. */ Unminimize(w); Assert(AwaitEvent(MapNotify)); /* Maximize and wait. */ Maximize(w, 1, 1); Assert(AwaitEvent(ConfigureNotify)); /* Unmaximize and wait. */ Unmaximize(w, 0, 1); Assert(AwaitEvent(ConfigureNotify)); /* Unmaximize and wait. */ Unmaximize(w, 1, 0); Assert(AwaitEvent(ConfigureNotify)); /* Change the size hints. */ hints = XAllocSizeHints(); hints->flags = PMinSize; hints->min_width = 300; hints->min_height = 200; XSetWMNormalHints(display, w, hints); XFree(hints); XSync(display, False); sleep(1); IgnoreEvents(); XGetWindowAttributes(display, w, &attr); Assert(attr.width == 300); Assert(attr.height == 200); /* Shade and wait. */ Shade(w); Assert(AwaitEvent(UnmapNotify)); /* Maximize and wait. */ Maximize(w, 0, 1); Assert(AwaitEvent(MapNotify)); /* Shade and wait. */ Shade(w); Assert(AwaitEvent(UnmapNotify)); /* Unshade and wait. */ Unshade(w); Assert(AwaitEvent(MapNotify)); /* Destroy the window. */ XDestroyWindow(display, w); }
// Is the window mapped? static bool IsMapped(Display *display, Window window) { XWindowAttributes attr; XGetWindowAttributes(display, window, &attr); return (attr.map_state != IsUnmapped); }
void copy_vsection_web(void) { static char *routine_name = "copy_vsection_web"; static char *xwd_file_path; static char *web_file_path; static int first_time = TRUE; XWindowAttributes attributes; FILE *xwd_file; /* * Get the output filenames */ if (first_time) { xwd_file_path = xGetResString(Glob->rdisplay, Glob->prog_name, "vsection_xwd_file", VSECTION_XWD_FILE); web_file_path = xGetResString(Glob->rdisplay, Glob->prog_name, "vsection_web_file", VSECTION_WEB_FILE); first_time = FALSE; } /* * Get the window attributes. */ if (!XGetWindowAttributes(Glob->rdisplay, Glob->vsection_window, &attributes)) { fprintf(stderr, "ERROR - %s:%s\n", Glob->prog_name, routine_name); fprintf(stderr, "Cannot get X window attributes for creating XWD file.\n"); return; } /* * Open the output file. */ if ((xwd_file = fopen(xwd_file_path, "w")) == NULL) { fprintf(stderr, "ERROR - %s:%s\n", Glob->prog_name, routine_name); fprintf(stderr, "Cannot open XWD file for output\n"); perror(xwd_file_path); return; } /* * Copy the CAPPI to an xwd file */ XUTIL_dump_pixmap_xwd(Glob->rdisplay, Glob->vsection.pixmap, &attributes, xwd_file); /* * Close the output file. */ fclose(xwd_file); /* * Convert to web format */ convert_xwd_to_web(xwd_file_path, web_file_path); return; }
/* * create XImage */ void fastViewer::createImage(const image& img) { int screen; display_info_s& di = display_info; XWindowAttributes win_attributes; bool resizeWin = false; if ((di.height != img.rows()) || (di.width != img.columns())) { resizeWin = true; } di.height = img.rows(); di.width = img.columns(); if (di.win == 0) { createWindow(); } if (resizeWin) { XResizeWindow(di.display,di.win,di.width,di.height); } screen = DefaultScreen(di.display); XGetWindowAttributes(di.display, di.win, &win_attributes); di.depth = win_attributes.depth; // TODO: maybe screen->root_depth is more precise than win_attr.depth // We should try it. // check if the X-Server has a 32 bit interface if (di.depth < 24) { throw exception("Error: Fast Viewer works only with 32 bit depth!"); } if (useShareMemory) { // // Shared Memory Setup // di.shmimage = XShmCreateImage(di.display, DefaultVisual(di.display, screen), di.depth, ZPixmap, NULL, &shminfo, di.width, di.height); if(isNull(di.shmimage)) { throw exception("fastViewer::shmimage == NULL:"); } int sharedMemSize = di.shmimage->bytes_per_line * di.shmimage->height; shminfo.shmid = shmget(IPC_PRIVATE, sharedMemSize, IPC_CREAT | 0777); if(shminfo.shmid < 0) { std::string str; str = "fastViewer::shmget failed:"; str += strerror(errno); throw exception(str); } shminfo.shmaddr = (char *) shmat(shminfo.shmid, (void *) 0, 0); if (shminfo.shmaddr == 0) { std::string str; str = "fastViewer::shmmat failed:"; str += std::strerror(errno); throw exception(str); } di.shmimage->data = shminfo.shmaddr; XShmAttach(di.display, &shminfo); data.useExternData(di.height,di.width,(rgbPixel*)di.shmimage->data); data.fill(img); } else { // // without shared memory // const int blockSize = img.rows()*img.columns()*4; remoteData = new char[blockSize]; data.useExternData(di.height,di.width,(rgbPixel*)remoteData); data.fill(img); di.shmimage = XCreateImage(di.display, DefaultVisual(di.display, screen), di.depth, ZPixmap, 0, remoteData, di.width, di.height,8,0); if(isNull(di.shmimage)) { throw exception("fastViewer::shmimage == NULL:"); } } }
void TrayIcon::draw(QPaintEvent* /*event*/) { Display* dsp = QX11Info::display(); XWindowAttributes attr; if (!XGetWindowAttributes(dsp, mIconId, &attr)) { qWarning() << "Paint error"; return; } XImage* ximage = XGetImage(dsp, mIconId, 0, 0, attr.width, attr.height, AllPlanes, ZPixmap); if (!ximage) { qWarning() << " * Error image is NULL"; return; } // qDebug() << "Paint icon **************************************"; // qDebug() << " * XComposite: " << isXCompositeAvailable(); // qDebug() << " * Icon geometry:" << iconGeometry(); // qDebug() << " Icon"; // qDebug() << " * window id: " << hex << mIconId; // qDebug() << " * window name:" << xfitMan().getName(mIconId); // qDebug() << " * size (WxH): " << attr.width << "x" << attr.height; // qDebug() << " * pos (XxY): " << attr.x << attr.y; // qDebug() << " * color depth:" << attr.depth; // qDebug() << " XImage"; // qDebug() << " * size (WxH): " << ximage->width << "x" << ximage->height; // switch (ximage->format) // { // case XYBitmap: qDebug() << " * format: XYBitmap"; break; // case XYPixmap: qDebug() << " * format: XYPixmap"; break; // case ZPixmap: qDebug() << " * format: ZPixmap"; break; // } // qDebug() << " * color depth: " << ximage->depth; // qDebug() << " * bits per pixel:" << ximage->bits_per_pixel; //const uchar* d =(uchar*) ximage->data; QImage image = QImage((const uchar*) ximage->data, ximage->width, ximage->height, ximage->bytes_per_line, QImage::Format_ARGB32_Premultiplied); // Draw QImage ........................... QPainter painter(this); QRect iconRect = iconGeometry(); if (image.size() != iconRect.size()) { image = image.scaled(iconRect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); QRect r = image.rect(); r.moveCenter(iconRect.center()); iconRect = r; } // qDebug() << " Draw rect:" << iconRect; painter.drawImage(iconRect, image); XDestroyImage(ximage); // debug << "End paint icon **********************************"; }
bool TrayIcon::init() { Display* dsp = QX11Info::display(); XWindowAttributes attr; if (! XGetWindowAttributes(dsp, mIconId, &attr)) return false; // qDebug() << "New tray icon ***********************************"; // qDebug() << " * window id: " << hex << mIconId; // qDebug() << " * window name:" << xfitMan().getName(mIconId); // qDebug() << " * size (WxH): " << attr.width << "x" << attr.height; // qDebug() << " * color depth:" << attr.depth; unsigned long mask = 0; XSetWindowAttributes set_attr; Visual* visual = attr.visual; set_attr.colormap = attr.colormap; set_attr.background_pixel = 0; set_attr.border_pixel = 0; mask = CWColormap|CWBackPixel|CWBorderPixel; mWindowId = XCreateWindow(dsp, this->winId(), 0, 0, mIconSize.width(), mIconSize.height(), 0, attr.depth, InputOutput, visual, mask, &set_attr); xError = false; XErrorHandler old; old = XSetErrorHandler(windowErrorHandler); XReparentWindow(dsp, mIconId, mWindowId, 0, 0); XSync(dsp, false); XSetErrorHandler(old); if (xError) { qWarning() << "****************************************"; qWarning() << "* Not icon_swallow *"; qWarning() << "****************************************"; XDestroyWindow(dsp, mWindowId); return false; } { Atom acttype; int actfmt; unsigned long nbitem, bytes; unsigned char *data = 0; int ret; ret = XGetWindowProperty(dsp, mIconId, xfitMan().atom("_XEMBED_INFO"), 0, 2, false, xfitMan().atom("_XEMBED_INFO"), &acttype, &actfmt, &nbitem, &bytes, &data); if (ret == Success) { if (data) XFree(data); } else { qWarning() << "TrayIcon: xembed error"; XDestroyWindow(dsp, mWindowId); return false; } } { XEvent e; e.xclient.type = ClientMessage; e.xclient.serial = 0; e.xclient.send_event = True; e.xclient.message_type = xfitMan().atom("_XEMBED"); e.xclient.window = mIconId; e.xclient.format = 32; e.xclient.data.l[0] = CurrentTime; e.xclient.data.l[1] = XEMBED_EMBEDDED_NOTIFY; e.xclient.data.l[2] = 0; e.xclient.data.l[3] = mWindowId; e.xclient.data.l[4] = 0; XSendEvent(dsp, mIconId, false, 0xFFFFFF, &e); } XSelectInput(dsp, mIconId, StructureNotifyMask); mDamage = XDamageCreate(dsp, mIconId, XDamageReportRawRectangles); XCompositeRedirectWindow(dsp, mWindowId, CompositeRedirectManual); XMapWindow(dsp, mIconId); XMapRaised(dsp, mWindowId); xfitMan().resizeWindow(mWindowId, mIconSize.width(), mIconSize.height()); xfitMan().resizeWindow(mIconId, mIconSize.width(), mIconSize.height()); return true; }
static void * halftone_init (Display *dpy, Window window) { int x, y, i; int count; int spacing; double factor; double min_mass; double max_mass; double min_speed; double max_speed; XGCValues gc_values; XWindowAttributes attrs; halftone_screen *halftone; halftone = (halftone_screen *) calloc (1, sizeof(halftone_screen)); halftone->dpy = dpy; halftone->window = window; //halftone->delay = get_integer_resource (dpy, "delay", "Integer"); //halftone->delay = (halftone->delay < 0 ? DEFAULT_DELAY : halftone->delay); halftone->delay = delay; halftone->delay = (halftone->delay < 0 ? DEFAULT_DELAY : halftone->delay); halftone->gc = XCreateGC (halftone->dpy, halftone->window, 0, &gc_values); halftone->buffer_width = -1; halftone->buffer_height = -1; halftone->dots = NULL; /* Read command line arguments and set all settings. */ //count = get_integer_resource (dpy, "count", "Count"); count = count_; halftone->gravity_point_count = count < 1 ? DEFAULT_COUNT : count; //spacing = get_integer_resource (dpy, "spacing", "Integer"); spacing = spacing_; halftone->spacing = spacing < 1 ? DEFAULT_SPACING : spacing; //factor = get_float_resource (dpy, "sizeFactor", "Double"); factor = sizeFactor; halftone->max_dot_size = (factor < 0 ? DEFAULT_SIZE_FACTOR : factor) * halftone->spacing; //min_mass = get_float_resource (dpy, "minMass", "Double"); min_mass = minMass; min_mass = min_mass < 0 ? DEFAULT_MIN_MASS : min_mass; //max_mass = get_float_resource (dpy, "maxMass", "Double"); max_mass = maxMass; max_mass = max_mass < 0 ? DEFAULT_MAX_MASS : max_mass; max_mass = max_mass < min_mass ? min_mass : max_mass; //min_speed = get_float_resource (dpy, "minSpeed", "Double"); min_speed = minSpeed; min_speed = min_speed < 0 ? DEFAULT_MIN_SPEED : min_speed; //max_speed = get_float_resource (dpy, "maxSpeed", "Double"); max_speed = maxSpeed; max_speed = max_speed < 0 ? DEFAULT_MAX_SPEED : max_speed; max_speed = max_speed < min_speed ? min_speed : max_speed; /* Set up the moving gravity points. */ halftone->gravity_point_x = (double *) malloc(halftone->gravity_point_count * sizeof(double)); halftone->gravity_point_y = (double *) malloc(halftone->gravity_point_count * sizeof(double)); halftone->gravity_point_mass = (double *) malloc(halftone->gravity_point_count * sizeof(double)); halftone->gravity_point_x_inc = (double *) malloc(halftone->gravity_point_count * sizeof(double)); halftone->gravity_point_y_inc = (double *) malloc(halftone->gravity_point_count * sizeof(double)); for (i = 0; i < halftone->gravity_point_count; i++) { halftone->gravity_point_x[i] = frand(1); halftone->gravity_point_y[i] = frand(1); halftone->gravity_point_mass[i] = min_mass + (max_mass - min_mass) * frand(1); halftone->gravity_point_x_inc[i] = min_speed + (max_speed - min_speed) * frand(1); halftone->gravity_point_y_inc[i] = min_speed + (max_speed - min_speed) * frand(1); } /* Set up the dots. */ XGetWindowAttributes(halftone->dpy, halftone->window, &attrs); //halftone->ncolors = get_integer_resource (dpy, "colors", "Colors"); halftone->ncolors = colors; if (halftone->ncolors < 4) halftone->ncolors = 4; halftone->colors = (XColor *) calloc(halftone->ncolors, sizeof(XColor)); make_smooth_colormap (attrs.screen, attrs.visual, attrs.colormap, halftone->colors, &halftone->ncolors, True, 0, False); halftone->color0 = 0; halftone->color1 = halftone->ncolors / 2; //halftone->cycle_speed = get_integer_resource (dpy, "cycleSpeed", "CycleSpeed"); halftone->cycle_speed = cycleSpeed; halftone->color_tick = 0; update_buffer(halftone, &attrs); update_dot_attributes(halftone, &attrs); for (x = 0; x < halftone->dots_width; x++) for (y = 0; y < halftone->dots_height; y++) { halftone->dots[x + y * halftone->dots_width] = 0; } return halftone; }
static unsigned long * SetPalette(struct state *st ) { XWindowAttributes XWinAttribs; XColor Color, *aColors; signed short iColor; float nHalfColors; XGetWindowAttributes( st->dpy, st->window, &XWinAttribs ); Color.red = RANDOM() % 0xFFFF; Color.green = RANDOM() % 0xFFFF; Color.blue = RANDOM() % 0xFFFF; if( strcasecmp( st->sColor, "random" ) && !XParseColor( st->dpy, XWinAttribs.colormap, st->sColor, &Color ) ) fprintf( stderr, "%s: color %s not found in database. Choosing to random...\n", progname, st->sColor ); #ifdef VERBOSE printf( "%s: Base color (RGB): <%d, %d, %d>\n", progname, Color.red, Color.green, Color.blue ); #endif /* VERBOSE */ st->iColorCount = get_integer_resource(st->dpy, "ncolors", "Integer" ); if( st->iColorCount < 2 ) st->iColorCount = 2; if( st->iColorCount > 255 ) st->iColorCount = 255; aColors = calloc( st->iColorCount, sizeof(XColor) ); st->aiColorVals = calloc( st->iColorCount, sizeof(unsigned long) ); for( iColor=0; iColor<st->iColorCount; iColor++ ) { nHalfColors = st->iColorCount / 2.0F; /* Black -> Base Color */ if( iColor < (st->iColorCount/2) ) { aColors[ iColor ].red = ( Color.red / nHalfColors ) * iColor; aColors[ iColor ].green = ( Color.green / nHalfColors ) * iColor; aColors[ iColor ].blue = ( Color.blue / nHalfColors ) * iColor; } /* Base Color -> White */ else { aColors[ iColor ].red = ( ( ( 0xFFFF - Color.red ) / nHalfColors ) * ( iColor - nHalfColors ) ) + Color.red; aColors[ iColor ].green = ( ( ( 0xFFFF - Color.green ) / nHalfColors ) * ( iColor - nHalfColors ) ) + Color.green; aColors[ iColor ].blue = ( ( ( 0xFFFF - Color.blue ) / nHalfColors ) * ( iColor - nHalfColors ) ) + Color.blue; } if( !XAllocColor( st->dpy, XWinAttribs.colormap, &aColors[ iColor ] ) ) { /* start all over with less colors */ XFreeColors( st->dpy, XWinAttribs.colormap, st->aiColorVals, iColor, 0 ); free( aColors ); free( st->aiColorVals ); st->iColorCount--; aColors = calloc( st->iColorCount, sizeof(XColor) ); st->aiColorVals = calloc( st->iColorCount, sizeof(unsigned long) ); iColor = -1; } else st->aiColorVals[ iColor ] = aColors[ iColor ].pixel; } free( aColors ); XSetWindowBackground( st->dpy, st->window, st->aiColorVals[ 0 ] ); return st->aiColorVals; }
GLboolean stubIsWindowVisible(WindowInfo *win) { #if defined(WINDOWS) # ifdef VBOX_WITH_WDDM if (stub.bRunningUnderWDDM) return win->mapped; # endif return GL_TRUE; #elif defined(Darwin) return GL_TRUE; #elif defined(GLX) Display *dpy = stubGetWindowDisplay(win); if (dpy) { XWindowAttributes attr; XLOCK(dpy); XGetWindowAttributes(dpy, win->drawable, &attr); XUNLOCK(dpy); if (attr.map_state == IsUnmapped) { return GL_FALSE; } # if 1 return GL_TRUE; # else if (attr.override_redirect) { return GL_TRUE; } if (!stub.bXExtensionsChecked) { stubCheckXExtensions(win); } if (!stub.bHaveXComposite) { return GL_TRUE; } else { Pixmap p; crLockMutex(&stub.mutex); XLOCK(dpy); XSync(dpy, false); oldErrorHandler = XSetErrorHandler(errorHandler); /*@todo this will create new pixmap for window every call*/ p = XCompositeNameWindowPixmap(dpy, win->drawable); XSync(dpy, false); XSetErrorHandler(oldErrorHandler); XUNLOCK(dpy); switch (lastXError) { case Success: XFreePixmap(dpy, p); crUnlockMutex(&stub.mutex); return GL_FALSE; break; case BadMatch: /*Window isn't redirected*/ lastXError = Success; break; default: crWarning("Unexpected XError %i", (int)lastXError); lastXError = Success; } crUnlockMutex(&stub.mutex); return GL_TRUE; } # endif } else { /* probably created by crWindowCreate() */ return win->mapped; } #endif }
void exposeCB (Widget w, ExposeCD *cd, XtcwpAxesCallbackStruct *ca) { Model *model=cd->model; char *edgecolor=cd->edgecolor; char *tricolor=cd->tricolor; float bclip=cd->bclip; float wclip=cd->wclip; Region region=ca->region; Position x=ca->x,y=ca->y; Dimension width=ca->width,height=ca->height; float x1beg=ca->x1beg,x1end=ca->x1end, x2beg=ca->x2beg,x2end=ca->x2end; int style=ca->style; Display *dpy=NULL; Window win; Region drawregion,tempregion; XWindowAttributes wa; Colormap cmap; XColor scolor,ecolor; XRectangle rect; long black=0; long white=0; GC gcedge,gctri; FGC fgcedge,fgctri,fgc; float x1,y1,x2,y2,x3,y3; Face *f; /* JG */ dpy=XtDisplay(w); win=XtWindow(w); black=(long) BlackPixelOfScreen(XtScreen(w)); white=(long) WhitePixelOfScreen(XtScreen(w)); /* .. JG */ /* determine current colormap */ XGetWindowAttributes(dpy,win,&wa); cmap = wa.colormap; /* create GCs */ gcedge = XCreateGC(dpy,win,0L,NULL); gctri = XCreateGC(dpy,win,0L,NULL); /* set line colors */ if (XAllocNamedColor(dpy,cmap,edgecolor,&scolor,&ecolor)) XSetForeground(dpy,gcedge,ecolor.pixel); else XSetForeground(dpy,gcedge,black); if (XAllocNamedColor(dpy,cmap,tricolor,&scolor,&ecolor)) XSetForeground(dpy,gctri,ecolor.pixel); else XSetForeground(dpy,gctri,white); /* clip to intersection of axes rectangle and expose region */ rect.x = x; rect.y = y; rect.width = width; rect.height = height; tempregion = XCreateRegion(); XUnionRectWithRegion(&rect,tempregion,tempregion); drawregion = XCreateRegion(); XIntersectRegion(region,tempregion,drawregion); XSetRegion(dpy,gcedge,drawregion); XSetRegion(dpy,gctri,drawregion); /* create FGCs with clipping */ if (style==XtcwpNORMAL) { fgcedge = FXCreateFGC(gcedge,x,y,width,height, x1beg,x2end,x1end-x1beg,x2beg-x2end); FSetClipRectangle(fgcedge,x1beg,x2end,x1end,x2beg); fgctri = FXCreateFGC(gctri,x,y,width,height, x1beg,x2end,x1end-x1beg,x2beg-x2end); FSetClipRectangle(fgctri,x1beg,x2end,x1end,x2beg); } else { fgcedge = FXCreateFGC(gcedge,x,y,width,height, x2beg,x1beg,x2end-x2beg,x1end-x1beg); FSetClipRectangle(fgcedge,x2beg,x1beg,x2end,x1end); fgctri = FXCreateFGC(gctri,x,y,width,height, x2beg,x1beg,x2end-x2beg,x1end-x1beg); FSetClipRectangle(fgctri,x2beg,x1beg,x2end,x1end); } /* draw image */ drawimage(dpy,win,drawregion,fgctri,model,bclip,wclip,style); /* loop over triangles */ f = model->f; do { /* get float coordinates of vertices */ if (style==XtcwpNORMAL) { x1 = f->eu->vu->v->x; y1 = f->eu->vu->v->y; x2 = f->eu->euCW->vu->v->x; y2 = f->eu->euCW->vu->v->y; x3 = f->eu->euCCW->vu->v->x; y3 = f->eu->euCCW->vu->v->y; } else { x1 = f->eu->vu->v->y; y1 = f->eu->vu->v->x; x2 = f->eu->euCW->vu->v->y; y2 = f->eu->euCW->vu->v->x; x3 = f->eu->euCCW->vu->v->y; y3 = f->eu->euCCW->vu->v->x; } /* draw edges of triangle */ fgc = f->eu->e->fixed ? fgcedge : fgctri; if (((fgc==fgcedge && !STREQ(edgecolor,"none")) || (fgc==fgctri && !STREQ(tricolor,"none")))) FXDrawLine(dpy,win,fgc,x1,y1,x2,y2); fgc = f->eu->euCW->e->fixed ? fgcedge : fgctri; if (((fgc==fgcedge && !STREQ(edgecolor,"none")) || (fgc==fgctri && !STREQ(tricolor,"none")))) FXDrawLine(dpy,win,fgc,x2,y2,x3,y3); fgc = f->eu->euCCW->e->fixed ? fgcedge : fgctri; if (((fgc==fgcedge && !STREQ(edgecolor,"none")) || (fgc==fgctri && !STREQ(tricolor,"none")))) FXDrawLine(dpy,win,fgc,x3,y3,x1,y1); f = f->fNext; } while (f!=model->f); /* free everything */ FXFreeFGC(fgcedge); FXFreeFGC(fgctri); XFreeGC(dpy,gcedge); XFreeGC(dpy,gctri); XDestroyRegion(drawregion); XDestroyRegion(tempregion); }
static void x11video_prepare(MSFilter *f){ X11Video *s=(X11Video*)f->data; unsigned int n; unsigned int nadaptors; int i; XvAdaptorInfo *xai=NULL; XvPortID port=-1; int imgfmt_id=0; XShmSegmentInfo *shminfo=&s->shminfo; XWindowAttributes wa = {0}; if (s->display==NULL) return; if (s->window_id==0){ if(s->auto_window) { s->window_id=createX11Window(s); } if (s->window_id==0) return; s->own_window=TRUE; } /* Make sure X11 window is ready to use*/ XSync(s->display, False); if (s->own_window==FALSE){ /*we need to register for resize events*/ XSelectInput(s->display,s->window_id,StructureNotifyMask); } XGetWindowAttributes(s->display,s->window_id,&wa); XClearWindow(s->display,s->window_id); ms_message("x11video_prepare(): Window has size %ix%i, received video is %ix%i",wa.width,wa.height,s->vsize.width,s->vsize.height); if (wa.width<MS_LAYOUT_MIN_SIZE || wa.height<MS_LAYOUT_MIN_SIZE){ return; } s->wsize.width=wa.width; s->wsize.height=wa.height; s->fbuf.w=s->vsize.width; s->fbuf.h=s->vsize.height; s->port=-1; if (XvQueryExtension(s->display, &n, &n, &n, &n, &n)!=0){ ms_error("Fail to query xv extension"); return; } if (XShmQueryExtension(s->display)==0){ ms_error("Fail to query xshm extension"); return; } if (XvQueryAdaptors(s->display,DefaultRootWindow(s->display), &nadaptors, &xai)!=0){ ms_error("XvQueryAdaptors failed."); return; } for (n=0;n<nadaptors && port==-1;++n){ XvAdaptorInfo *ai=&xai[n]; XvImageFormatValues *imgfmt; int nimgfmt=0; ms_message("Found output adaptor; name=%s num_ports=%i, with %i formats:", ai->name,(int)ai->num_ports,(int)ai->num_formats); imgfmt=XvListImageFormats(s->display,ai->base_id,&nimgfmt); for(i=0;i<nimgfmt;++i){ char fcc[5]={0}; memcpy(fcc,&imgfmt[i].id,4); ms_message("type=%s/%s id=%s", imgfmt[i].type == XvYUV ? "YUV" : "RGB", imgfmt[i].format==XvPlanar ? "Planar" : "Packed",fcc); if (port==-1 && imgfmt[i].format==XvPlanar && strcasecmp(fcc,"YV12")==0){ int k; /*we found a format interesting to us*/ for(k=0;k<ai->num_ports;++k){ if (XvGrabPort(s->display,ai->base_id+k,CurrentTime)==0){ ms_message("Grabbed port %i",(int)ai->base_id+k); port=ai->base_id+k; imgfmt_id=imgfmt[i].id; break; } } } } if (imgfmt) XFree(imgfmt); } XvFreeAdaptorInfo(xai); if (port==-1){ ms_error("Could not find suitable format or Xv port to work with."); return; } s->port=port; /*create the shared memory XvImage*/ memset(shminfo,0,sizeof(*shminfo)); s->xv_image=XvShmCreateImage(s->display,s->port,imgfmt_id,NULL,s->fbuf.w,s->fbuf.h,shminfo); if (s->xv_image==NULL){ ms_error("XvShmCreateImage failed."); x11video_unprepare(f); return; } /*allocate some shared memory to receive the pixel data */ shminfo->shmid=shmget(IPC_PRIVATE, s->xv_image->data_size,IPC_CREAT | 0777); if (shminfo->shmid==-1){ ms_error("Could not allocate %i bytes of shared memory: %s", s->xv_image->data_size, strerror(errno)); x11video_unprepare(f); return; } shminfo->shmaddr=shmat(shminfo->shmid,NULL,0); if (shminfo->shmaddr==(void*)-1){ ms_error("shmat() failed: %s",strerror(errno)); shminfo->shmaddr=NULL; x11video_unprepare(f); return; } /*ask the x-server to attach this shared memory segment*/ x11_error=FALSE; if (!XShmAttach(s->display,shminfo)){ ms_error("XShmAttach failed !"); x11video_unprepare(f); return ; } s->xv_image->data=s->shminfo.shmaddr; s->fbuf.planes[0]=(void*)s->xv_image->data; s->fbuf.planes[2]=s->fbuf.planes[0]+(s->xv_image->height*s->xv_image->pitches[0]); s->fbuf.planes[1]=s->fbuf.planes[2]+((s->xv_image->height/2)*s->xv_image->pitches[1]); s->fbuf.strides[0]=s->xv_image->pitches[0]; s->fbuf.strides[2]=s->xv_image->pitches[1]; s->fbuf.strides[1]=s->xv_image->pitches[2]; /* set picture black */ x11video_fill_background(f); /*Create a GC*/ s->gc=XCreateGC(s->display,s->window_id,0,NULL); if (s->gc==NULL){ ms_error("XCreateGC() failed."); x11video_unprepare(f); return ; } s->ready=TRUE; }
void ovg_open(int x, int y, int w, int h) { Window root; XSetWindowAttributes swa,xattr; XWindowAttributes gwa; XClassHint *classHint; XVisualInfo *vi; GLint att[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None }; char instance[] = "libovg", className[] = "libovg"; if (x_display == NULL){ //in the case of closing a previous window if ((x_display = XOpenDisplay(NULL)) == NULL){ fprintf(stderr, "Error opening X Display\n"); return; } } root = DefaultRootWindow(x_display); if ((vi = glXChooseVisual(x_display, 0, att)) == NULL){ fprintf(stderr, "No visual found\n"); return; } if (y == 0){ //for some reason, //y=0 makes the window //default to center of displau, not 0,0 y++; } swa.event_mask = ExposureMask | KeyPressMask; win = XCreateWindow(x_display,root, x,y,w,h,0, CopyFromParent,InputOutput, CopyFromParent, CWEventMask, &swa); xattr.override_redirect=0; XChangeWindowAttributes(x_display, win, CWOverrideRedirect, &xattr); XStoreName(x_display, win, "LibOVG"); classHint = XAllocClassHint(); if (classHint){ classHint->res_name = instance; classHint->res_class = className; } XSetClassHint(x_display, win, classHint); XFree(classHint); XMapWindow(x_display, win); glc = glXCreateContext(x_display, vi, NULL, GL_TRUE); glXMakeCurrent(x_display, win, glc); // set up screen ratio XGetWindowAttributes(x_display, win, &gwa); if (vgCreateContextSH(w, h) != VG_TRUE){ fprintf(stderr, "Error creating context\n"); return; } ovg_clear(); }
static void x11video_process(MSFilter *f){ X11Video *obj=(X11Video*)f->data; mblk_t *inm; int update=0; MSPicture lsrc={0}; MSPicture src={0}; MSRect mainrect,localrect; bool_t precious=FALSE; bool_t local_precious=FALSE; XWindowAttributes wa; MSTickerLateEvent late_info; ms_filter_lock(f); if ((obj->window_id == 0) || (x11_error == TRUE)) goto end; XGetWindowAttributes(obj->display,obj->window_id,&wa); if (x11_error == TRUE) { ms_error("Could not get window attributes for window %lu", obj->window_id); goto end; } if (wa.width!=obj->wsize.width || wa.height!=obj->wsize.height){ ms_warning("Resized to %ix%i", wa.width,wa.height); obj->wsize.width=wa.width; obj->wsize.height=wa.height; XClearWindow(obj->display,obj->window_id); } ms_ticker_get_last_late_tick(f->ticker, &late_info); if(late_info.current_late_ms > 100) { ms_warning("Dropping frames because we're late"); goto end; } if (!obj->show) { goto end; } if (!obj->ready){ goto end; } if (f->inputs[0]!=NULL && (inm=ms_queue_peek_last(f->inputs[0]))!=0) { if (ms_yuv_buf_init_from_mblk(&src,inm)==0){ MSVideoSize newsize; newsize.width=src.w; newsize.height=src.h; precious=mblk_get_precious_flag(inm); if (!ms_video_size_equal(newsize,obj->vsize) ) { ms_message("received size is %ix%i",newsize.width,newsize.height); obj->vsize=newsize; if (obj->autofit){ MSVideoSize new_window_size; static const MSVideoSize min_size=MS_VIDEO_SIZE_QVGA; /*don't resize less than QVGA, it is too small*/ if (min_size.width*min_size.height>newsize.width*newsize.height){ new_window_size.width=newsize.width*2; new_window_size.height=newsize.height*2; }else new_window_size=newsize; obj->wsize=new_window_size; ms_message("autofit: new window size should be %ix%i",new_window_size.width,new_window_size.height); XResizeWindow(obj->display,obj->window_id,new_window_size.width,new_window_size.height); XSync(obj->display,FALSE); } x11video_unprepare(f); x11video_prepare(f); if (!obj->ready) goto end; } } update=1; } /*process last video message for local preview*/ if (obj->corner!=-1 && f->inputs[1]!=NULL && (inm=ms_queue_peek_last(f->inputs[1]))!=0) { if (ms_yuv_buf_init_from_mblk(&lsrc,inm)==0){ obj->lsize.width=lsrc.w; obj->lsize.height=lsrc.h; local_precious=mblk_get_precious_flag(inm); update=1; } } ms_layout_compute(obj->vsize, obj->vsize,obj->lsize,obj->corner,obj->scale_factor,&mainrect,&localrect); if (lsrc.w!=0 && obj->corner!=-1){ /* first reduce the local preview image into a temporary image*/ if (obj->local_msg==NULL){ obj->local_msg=ms_yuv_buf_alloc(&obj->local_pic,localrect.w,localrect.h); } if (obj->sws2==NULL){ obj->sws2=ms_scaler_create_context(lsrc.w,lsrc.h,MS_YUV420P,localrect.w,localrect.h,MS_YUV420P, MS_SCALER_METHOD_BILINEAR); } ms_scaler_process(obj->sws2,lsrc.planes,lsrc.strides,obj->local_pic.planes,obj->local_pic.strides); if (!local_precious) ms_yuv_buf_mirror(&obj->local_pic); } if (update && src.w!=0){ ms_yuv_buf_copy(src.planes,src.strides,obj->fbuf.planes,obj->fbuf.strides,obj->vsize); if (obj->mirror && !precious) ms_yuv_buf_mirror(&obj->fbuf); } /*copy resized local view into a corner:*/ if (update && obj->local_msg!=NULL && obj->corner!=-1){ MSPicture corner=obj->fbuf; MSVideoSize roi; roi.width=obj->local_pic.w; roi.height=obj->local_pic.h; corner.w=obj->local_pic.w; corner.h=obj->local_pic.h; corner.planes[0]+=localrect.x+(localrect.y*corner.strides[0]); corner.planes[1]+=(localrect.x/2)+((localrect.y/2)*corner.strides[1]); corner.planes[2]+=(localrect.x/2)+((localrect.y/2)*corner.strides[2]); corner.planes[3]=0; ms_yuv_buf_copy(obj->local_pic.planes,obj->local_pic.strides, corner.planes,corner.strides,roi); } if (update){ MSRect rect; ms_layout_center_rectangle(obj->wsize,obj->vsize,&rect); //ms_message("XvShmPutImage() %ix%i --> %ix%i",obj->fbuf.w,obj->fbuf.h,obj->wsize.width,obj->wsize.height); XvShmPutImage(obj->display,obj->port,obj->window_id,obj->gc, obj->xv_image, 0,0,obj->fbuf.w,obj->fbuf.h, rect.x,rect.y,rect.w,rect.h,TRUE); XSync(obj->display,FALSE); } end: ms_filter_unlock(f); if (f->inputs[0]!=NULL) ms_queue_flush(f->inputs[0]); if (f->inputs[1]!=NULL) ms_queue_flush(f->inputs[1]); }
static Bool InitializeAll(struct state *st) { XGCValues xgcv; XWindowAttributes xgwa; /* XSetWindowAttributes xswa;*/ Colormap cmap; XColor color; int n,i; double rspeed; st->cosilines = True; XGetWindowAttributes(st->dpy,st->win[0],&xgwa); cmap=xgwa.colormap; /* xswa.backing_store=Always; XChangeWindowAttributes(st->dpy,st->win[0],CWBackingStore,&xswa);*/ xgcv.function=GXcopy; xgcv.foreground=get_pixel_resource (st->dpy, cmap, "background", "Background"); st->fgc[32]=XCreateGC(st->dpy,st->win[0],GCForeground|GCFunction,&xgcv); n=0; if (mono_p) { st->fgc[0]=st->fgc[32]; xgcv.foreground=get_pixel_resource (st->dpy, cmap, "foreground", "Foreground"); st->fgc[1]=XCreateGC(st->dpy,st->win[0],GCForeground|GCFunction,&xgcv); for (i=0;i<32;i+=2) st->fgc[i]=st->fgc[0]; for (i=1;i<32;i+=2) st->fgc[i]=st->fgc[1]; } else for (i=0;i<32;i++) { color.red=colors[n++]<<8; color.green=colors[n++]<<8; color.blue=colors[n++]<<8; color.flags=DoRed|DoGreen|DoBlue; XAllocColor(st->dpy,cmap,&color); xgcv.foreground=color.pixel; st->fgc[i]=XCreateGC(st->dpy,st->win[0],GCForeground|GCFunction,&xgcv); } st->cgc=XCreateGC(st->dpy,st->win[0],GCForeground|GCFunction,&xgcv); XSetGraphicsExposures(st->dpy,st->cgc,False); st->cosilines = get_boolean_resource(st->dpy, "random","Boolean"); #ifdef HAVE_DOUBLE_BUFFER_EXTENSION if (get_boolean_resource (st->dpy, "useDBE", "Boolean")) st->usedouble = True; st->win[1] = xdbe_get_backbuffer (st->dpy, st->win[0], XdbeUndefined); if (!st->win[1]) { st->usedouble = False; st->win[1] = st->win[0]; } #endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ st->delay=get_integer_resource(st->dpy, "delay","Integer"); rspeed=get_float_resource(st->dpy, "speed","Float"); if (rspeed<0.0001 || rspeed>0.2) { fprintf(stderr,"Speed not in valid range! (0.0001 - 0.2), using 0.1 \n"); rspeed=0.1; } st->sizx=xgwa.width; st->sizy=xgwa.height; st->midx=st->sizx>>1; st->midy=st->sizy>>1; st->stateX=0; st->stateY=0; if (!make_rots(st,rspeed,rspeed)) { fprintf(stderr,"Not enough memory for tables!\n"); return False; } return True; }
static void decorCheckForDmOnScreen (CompScreen *s, Bool updateWindows) { CompDisplay *d = s->display; Atom actual; int result, format; unsigned long n, left; unsigned char *data; Window dmWin = None; DECOR_DISPLAY (s->display); DECOR_SCREEN (s); result = XGetWindowProperty (d->display, s->root, dd->supportingDmCheckAtom, 0L, 1L, FALSE, XA_WINDOW, &actual, &format, &n, &left, &data); if (result == Success && data) { if (n) { XWindowAttributes attr; memcpy (&dmWin, data, sizeof (Window)); compCheckForError (d->display); XGetWindowAttributes (d->display, dmWin, &attr); if (compCheckForError (d->display)) dmWin = None; } XFree (data); } if (dmWin != ds->dmWin) { CompWindow *w; int i; if (dmWin) { for (i = 0; i < DECOR_NUM; i++) ds->decor[i] = decorCreateDecoration (s, s->root, dd->decorAtom[i]); } else { for (i = 0; i < DECOR_NUM; i++) { if (ds->decor[i]) { decorReleaseDecoration (s, ds->decor[i]); ds->decor[i] = 0; } } for (w = s->windows; w; w = w->next) { DECOR_WINDOW (w); if (dw->decor) { decorReleaseDecoration (s, dw->decor); dw->decor = 0; } } } ds->dmWin = dmWin; if (updateWindows) { for (w = s->windows; w; w = w->next) decorWindowUpdate (w, TRUE); } } }
bool GetEvent(Event &event){ #ifdef LINUX if(XPending(dpy)){ XEvent xev; // Keyboard Key Press (Keysym code available in /usr/include/X11/keysymdef.h) if( XCheckWindowEvent(dpy, glWin, KeyPressMask, &xev) ) { event.type = TMGL_Press; KeySym ks = XKeycodeToKeysym(dpy, xev.xkey.keycode, 0); MapKey(ks, event.input); } // Keyboard Key Release (Keysym code available in /usr/include/X11/keysymdef.h) else if(XCheckWindowEvent(dpy, glWin, KeyReleaseMask, &xev)) { event.type = TMGL_Release; KeySym ks = XKeycodeToKeysym(dpy, xev.xkey.keycode, 0); MapKey(ks, event.input); } // Mouse Button Press else if(XCheckWindowEvent(dpy, glWin, ButtonPressMask, &xev)) { event.type = TMGL_Press; MapMouse(xev.xbutton.button, event.input); event.motion.x = xev.xbutton.x; event.motion.y = xev.xbutton.y; } // Mouse Button Release else if(XCheckWindowEvent(dpy, glWin, ButtonReleaseMask, &xev)) { event.type = TMGL_Release; MapMouse(xev.xbutton.button, event.input); event.motion.x = xev.xbutton.x; event.motion.y = xev.xbutton.y; } // Mouse Motion else if(XCheckWindowEvent(dpy, glWin, PointerMotionMask, &xev)) { event.type = TMGL_Motion; event.motion.x = xev.xmotion.x; event.motion.y = xev.xmotion.y; } // Window Exposure else if(XCheckWindowEvent(dpy, glWin, ExposureMask, &xev)) { XWindowAttributes gwa; event.type = TMGL_Expose; XGetWindowAttributes(dpy, glWin, &gwa); event.expose.width = gwa.width; event.expose.height = gwa.height; } // Other Events else { return false; } return true; } #endif // LINUX implementation return false; }
XVisualInfo *X11_GL_GetVisual(_THIS) { #if SDL_VIDEO_OPENGL_GLX /* 64 seems nice. */ int attribs[64]; int i; /* load the gl driver from a default path */ if ( ! this->gl_config.driver_loaded ) { /* no driver has been loaded, use default (ourselves) */ if ( X11_GL_LoadLibrary(this, NULL) < 0 ) { return NULL; } } /* See if we already have a window which we must use */ if ( SDL_windowid ) { XWindowAttributes a; XVisualInfo vi_in; int out_count; XGetWindowAttributes(SDL_Display, SDL_Window, &a); vi_in.screen = SDL_Screen; vi_in.visualid = XVisualIDFromVisual(a.visual); glx_visualinfo = XGetVisualInfo(SDL_Display, VisualScreenMask|VisualIDMask, &vi_in, &out_count); return glx_visualinfo; } /* Setup our GLX attributes according to the gl_config. */ i = 0; attribs[i++] = GLX_RGBA; attribs[i++] = GLX_RED_SIZE; attribs[i++] = this->gl_config.red_size; attribs[i++] = GLX_GREEN_SIZE; attribs[i++] = this->gl_config.green_size; attribs[i++] = GLX_BLUE_SIZE; attribs[i++] = this->gl_config.blue_size; if( this->gl_config.alpha_size ) { attribs[i++] = GLX_ALPHA_SIZE; attribs[i++] = this->gl_config.alpha_size; } if( this->gl_config.buffer_size ) { attribs[i++] = GLX_BUFFER_SIZE; attribs[i++] = this->gl_config.buffer_size; } if( this->gl_config.double_buffer ) { attribs[i++] = GLX_DOUBLEBUFFER; } attribs[i++] = GLX_DEPTH_SIZE; attribs[i++] = this->gl_config.depth_size; if( this->gl_config.stencil_size ) { attribs[i++] = GLX_STENCIL_SIZE; attribs[i++] = this->gl_config.stencil_size; } if( this->gl_config.accum_red_size ) { attribs[i++] = GLX_ACCUM_RED_SIZE; attribs[i++] = this->gl_config.accum_red_size; } if( this->gl_config.accum_green_size ) { attribs[i++] = GLX_ACCUM_GREEN_SIZE; attribs[i++] = this->gl_config.accum_green_size; } if( this->gl_config.accum_blue_size ) { attribs[i++] = GLX_ACCUM_BLUE_SIZE; attribs[i++] = this->gl_config.accum_blue_size; } if( this->gl_config.accum_alpha_size ) { attribs[i++] = GLX_ACCUM_ALPHA_SIZE; attribs[i++] = this->gl_config.accum_alpha_size; } if( this->gl_config.stereo ) { attribs[i++] = GLX_STEREO; } if( this->gl_config.multisamplebuffers ) { attribs[i++] = GLX_SAMPLE_BUFFERS_ARB; attribs[i++] = this->gl_config.multisamplebuffers; } if( this->gl_config.multisamplesamples ) { attribs[i++] = GLX_SAMPLES_ARB; attribs[i++] = this->gl_config.multisamplesamples; } if( this->gl_config.accelerated >= 0 && glXExtensionSupported(this, "GLX_EXT_visual_rating") ) { attribs[i++] = GLX_VISUAL_CAVEAT_EXT; attribs[i++] = GLX_NONE_EXT; } #ifdef GLX_DIRECT_COLOR /* Try for a DirectColor visual for gamma support */ if ( !SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) { attribs[i++] = GLX_X_VISUAL_TYPE; attribs[i++] = GLX_DIRECT_COLOR; } #endif attribs[i++] = None; glx_visualinfo = this->gl_data->glXChooseVisual(GFX_Display, SDL_Screen, attribs); #ifdef GLX_DIRECT_COLOR if( !glx_visualinfo && !SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) { /* No DirectColor visual? Try again.. */ attribs[i-3] = None; glx_visualinfo = this->gl_data->glXChooseVisual(GFX_Display, SDL_Screen, attribs); } #endif if( !glx_visualinfo ) { SDL_SetError( "Couldn't find matching GLX visual"); return NULL; } return glx_visualinfo; #else SDL_SetError("X11 driver not configured with OpenGL"); return NULL; #endif }
/** * Request the video to avoid the conflicts **/ WId VideoWidget::request( struct vout_window_t *p_wnd, unsigned int *pi_width, unsigned int *pi_height, bool b_keep_size ) { if( stable ) { msg_Dbg( p_intf, "embedded video already in use" ); return 0; } assert( !p_window ); if( b_keep_size ) { *pi_width = size().width(); *pi_height = size().height(); } /* The owner of the video window needs a stable handle (WinId). Reparenting * in Qt4-X11 changes the WinId of the widget, so we need to create another * dummy widget that stays within the reparentable widget. */ stable = new QWidget(); QPalette plt = palette(); plt.setColor( QPalette::Window, Qt::black ); stable->setPalette( plt ); stable->setAutoFillBackground(true); /* Force the widget to be native so that it gets a winId() */ stable->setAttribute( Qt::WA_NativeWindow, true ); /* Indicates that the widget wants to draw directly onto the screen. Widgets with this attribute set do not participate in composition management */ /* This is currently disabled on X11 as it does not seem to improve * performance, but causes the video widget to be transparent... */ #if !defined (Q_WS_X11) && !defined (Q_WS_QPA) stable->setAttribute( Qt::WA_PaintOnScreen, true ); #endif layout->addWidget( stable ); #ifdef Q_WS_X11 /* HACK: Only one X11 client can subscribe to mouse button press events. * VLC currently handles those in the video display. * Force Qt4 to unsubscribe from mouse press and release events. */ Display *dpy = QX11Info::display(); Window w = stable->winId(); XWindowAttributes attr; XGetWindowAttributes( dpy, w, &attr ); attr.your_event_mask &= ~(ButtonPressMask|ButtonReleaseMask); attr.your_event_mask &= ~PointerMotionMask; XSelectInput( dpy, w, attr.your_event_mask ); # ifdef HAVE_XI int n; XIEventMask *xi_masks = XIGetSelectedEvents( dpy, w, &n ); if( xi_masks != NULL ) { for( int i = 0; i < n; i++ ) if( xi_masks[i].mask_len >= 1 ) { xi_masks[i].mask[0] &= ~XI_ButtonPressMask; xi_masks[i].mask[0] &= ~XI_ButtonReleaseMask; xi_masks[i].mask[0] &= ~XI_MotionMask; } XISelectEvents( dpy, w, xi_masks, n ); XFree( xi_masks ); } # endif #endif sync(); p_window = p_wnd; return stable->winId(); }
static void * compass_init (Display *dpy, Window window) { struct state *st = (struct state *) calloc (1, sizeof(*st)); XGCValues gcv; st->dpy = dpy; st->window = window; st->delay = get_integer_resource (st->dpy, "delay", "Integer"); st->dbuf = get_boolean_resource (st->dpy, "doubleBuffer", "Boolean"); # ifdef HAVE_JWXYZ /* Don't second-guess Quartz's double-buffering */ st->dbuf = False; # endif XGetWindowAttributes (st->dpy, st->window, &st->xgwa); st->size2 = MIN(st->xgwa.width, st->xgwa.height); if (st->xgwa.width > st->xgwa.height * 5 || /* goofy aspect ratio */ st->xgwa.height > st->xgwa.width * 5) st->size2 = MAX(st->xgwa.width, st->xgwa.height); { int max = 600; if (st->xgwa.width > 2560) max *= 2; /* Retina displays */ if (st->size2 > max) st->size2 = max; } st->size = (st->size2 / 2) * 0.8; st->x = st->xgwa.width/2; st->y = st->xgwa.height/2; if (st->dbuf) { #ifdef HAVE_DOUBLE_BUFFER_EXTENSION st->b = st->backb = xdbe_get_backbuffer (st->dpy, st->window, XdbeUndefined); #endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ if (!st->b) { st->x = st->size2/2; st->y = st->size2/2; st->ba = XCreatePixmap (st->dpy, st->window, st->size2, st->size2, st->xgwa.depth); st->bb = XCreatePixmap (st->dpy, st->window, st->size2, st->size2, st->xgwa.depth); st->b = st->ba; } } else { st->b = st->window; } st->discs[0] = (struct disc *) calloc (1, sizeof (struct disc)); st->discs[1] = (struct disc *) calloc (1, sizeof (struct disc)); st->discs[2] = (struct disc *) calloc (1, sizeof (struct disc)); st->discs[3] = 0; gcv.foreground = get_pixel_resource (st->dpy, st->xgwa.colormap, "foreground", "Foreground"); gcv.line_width = MAX(2, (st->size/60)); gcv.join_style = JoinBevel; st->discs[0]->draw = draw_ticks; st->discs[0]->gc = XCreateGC (st->dpy, st->b, GCForeground|GCLineWidth|GCJoinStyle, &gcv); init_spin (st->discs[0]); gcv.foreground = get_pixel_resource (st->dpy, st->xgwa.colormap, "arrow2Foreground", "Foreground"); gcv.line_width = MAX(4, (st->size / 30)); st->discs[1]->draw = draw_thick_arrow; st->discs[1]->gc = XCreateGC (st->dpy, st->b, GCForeground|GCLineWidth, &gcv); init_spin (st->discs[1]); gcv.foreground = get_pixel_resource (st->dpy, st->xgwa.colormap, "arrow1Foreground", "Foreground"); gcv.line_width = MAX(4, (st->size / 30)); st->discs[2]->draw = draw_thin_arrow; st->discs[2]->gc = XCreateGC (st->dpy, st->b, GCForeground|GCLineWidth, &gcv); init_spin (st->discs[2]); gcv.foreground = get_pixel_resource (st->dpy, st->xgwa.colormap, "pointerForeground", "Foreground"); st->ptr_gc = XCreateGC (st->dpy, st->b, GCForeground|GCLineWidth, &gcv); gcv.foreground = get_pixel_resource (st->dpy, st->xgwa.colormap, "background", "Background"); st->erase_gc = XCreateGC (st->dpy, st->b, GCForeground, &gcv); if (st->ba) XFillRectangle (st->dpy, st->ba, st->erase_gc, 0, 0, st->size2, st->size2); if (st->bb) XFillRectangle (st->dpy, st->bb, st->erase_gc, 0, 0, st->size2, st->size2); return st; }
void main(unsigned int argc, char **argv) { Arg args[10]; int n; int i; XmString message; XmString cancel_label, ok_label, help_label; char message_begin[120]; n = 0; CommonTestInit(argc, argv); n = 0; XtSetArg(args[n], XmNwidth, 10); n++; XtSetArg(args[n], XmNheight, 10); n++; XtSetValues(Shell1, args, n); XtRealizeWidget(Shell1); CommonPause(); XSetErrorHandler(ErrorHandle); /* * Initialize the PIInfo data values */ for (i = 0; i < NUM_TESTS; i++) PIInfo[i].actual_return = False; /* * Create top level shell widget as parent for test_button widgets */ n = 0; XtSetArg(args[n], XtNallowShellResize, TRUE); n++; test_top = XtAppCreateShell("test_top", /* application name */ "Test_top", /* application class */ topLevelShellWidgetClass, /* widget class */ display, /* display */ args, n); /* arguments */ /* * Create button1 widget */ display = XtDisplay(test_top); screen = DefaultScreenOfDisplay(display); test1_btn1_icon = XCreatePixmapFromBitmapData(display, rootWindow, btn1_bits, btn1_width, btn1_height, CommonGetColor("red"), CommonGetColor("yellow"), DefaultDepth(display, DefaultScreen(display))); test2_btn1_icon = XCreatePixmapFromBitmapData(display, rootWindow, btn2_bits, btn2_width, btn2_height, CommonGetColor("yellow"), CommonGetColor("red"), DefaultDepth(display, DefaultScreen(display))); n = 0; XtSetArg(args[n], XmNlabelType, XmPIXMAP); n++; XtSetArg(args[n], XmNlabelPixmap, test1_btn1_icon); n++; XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; test1_btn1 = XmCreatePushButton(test_top, "test1_btn1", args, n); XtManageChild(test1_btn1); XtRealizeWidget(test_top); /* * Create top level shell widget as parent for test_button2 widget */ n = 0; XtSetArg(args[n], XtNallowShellResize, TRUE); n++; test_top2 = XtAppCreateShell("test_top2", /* application name */ "Test_top2", /* application class */ topLevelShellWidgetClass, /* widget class */ display, /* display */ args, n); /* arguments */ /* * Create button2 widget */ n = 0; XtSetArg(args[n], XmNlabelType, XmPIXMAP); n++; XtSetArg(args[n], XmNlabelPixmap, test2_btn1_icon); n++; XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; test2_btn1 = XmCreatePushButton(test_top2, "test2_btn1", args, n); XtManageChild(test2_btn1); XtRealizeWidget(test_top2); test_wdw = XtWindow(test_top); top_wdw = XtWindow(Shell1); test_wdw2 = XtWindow(test_top2); XtAddEventHandler(Shell1, NoEventMask, True, CMEventHandler, NULL); XtAddEventHandler(test_top, NoEventMask, True, CMEventHandler, NULL); XtAddEventHandler(test_top2, NoEventMask, True, CMEventHandler, NULL); /* * Move the test_top shell window and the Shell1 window */ XMoveWindow(display, test_wdw, 100, 100); XMoveWindow(display, test_wdw2, 100, 300); /* * set protocols - WM_DELETE_WINDOW */ proto_atom = XmInternAtom(display, "WM_PROTOCOLS", False); delwin_atom = XmInternAtom(display, "WM_DELETE_WINDOW", False); XmAddWMProtocols(test_top, &delwin_atom, 1); #ifdef DONT /* * set protocols - WM_SAVE_YOURSELF */ savylf_atom = XmInternAtom(display, "WM_SAVE_YOURSELF", False); XmAddWMProtocols(test_top2, &savylf_atom, 1); /* * set protocols - WM_TAKE_FOCUS */ takfoc_atom = XmInternAtom(display, "WM_TAKE_FOCUS", False); /* change it on test_wdw2 */ XChangeProperty(display, test_wdw2, proto_atom, proto_atom, 32, PropModeReplace, (unsigned char *)&takfoc_atom, 1); #endif /* DONT */ CommonPause(); iteration++; /* * Check if window is not deleted after f.kill WM_DELETE_WINDOW */ ret_stat = XGetWindowAttributes(display, test_wdw, &win_attrs); /* * Actual return is if the window is still mapped and * recognizable. */ PIInfo[PIInfo_DW2].actual_return = ret_stat; /* * set protocols - _MOTIF_WM_MESSAGES */ /* add to the menu with the _MOTIF_WM_MENU property */ strcpy(menu_item, send_msg1); menu_atom = XmInternAtom(display, "_MOTIF_WM_MENU", False); XChangeProperty(display, test_wdw2, menu_atom, menu_atom, 8, PropModeReplace, (unsigned char *)menu_item, strlen(menu_item) + 1); /* add a message acceptance to widget */ motif_msg_atom = XmInternAtom(display, "_MOTIF_WM_MESSAGES", False); XmAddWMProtocols(test_top2, &motif_msg_atom, 1); msg_num = MSG_NUMBER; XmAddProtocolCallback(test_top2, motif_msg_atom, (Atom)msg_num, HandleMsgCB, NULL); PIUnmapWindow(test_wdw2); wm_set_hints.flags = (StateHint); wm_set_hints.initial_state = NormalState; XSetWMHints(display, test_wdw2, &wm_set_hints); XMapWindow(display, test_wdw2); XMoveWindow(display, test_wdw2, 100, 300); #ifdef DONT /* * Iconify test_wdw2, see if save_yourself works */ /* * Unmap the window to change state */ PIUnmapWindow(test_wdw2); /* * Map the window into iconic state */ wm_set_hints.flags = (StateHint); wm_set_hints.initial_state = IconicState; XSetWMHints(display, test_wdw2, &wm_set_hints); XMapWindow(display, test_wdw2); #endif /* DONT */ CommonPause(); #ifdef SHOW_P899 iteration++; /* * set protocols - _MOTIF_WM_MENU */ /* add to the menu with the _MOTIF_WM_MENU property */ strcpy(menu_item2, send_msg2); XChangeProperty(display, test_wdw2, menu_atom, menu_atom, 8, PropModeAppend, (unsigned char *)menu_item2, strlen(menu_item2) + 1); /* * Turn on acceptance of send_message2 */ msg_num = MSG_NUMBER2; XmAddProtocolCallback(test_top2, motif_msg_atom, (Atom)msg_num, HandleMsg2CB, NULL); PIUnmapWindow(test_wdw2); wm_set_hints.flags = (StateHint); wm_set_hints.initial_state = NormalState; XSetWMHints(display, test_wdw2, &wm_set_hints); XMapWindow(display, test_wdw2); XMoveWindow(display, test_wdw2, 100, 300); CommonPause(); #endif /* P899 */ iteration++; /* * set protocols - _MOTIF_WM_MENU */ /* add to the menu with the _MOTIF_WM_MENU property */ strcpy(menu_item2, send_msg3); XChangeProperty(display, test_wdw2, menu_atom, menu_atom, 8, PropModeReplace, (unsigned char *)menu_item2, strlen(menu_item2) + 1); #ifndef P899 /* * Turn on acceptance of send_message2 */ msg_num = MSG_NUMBER2; XmAddProtocolCallback(test_top2, motif_msg_atom, (Atom)msg_num, HandleMsg2CB, NULL); #endif /* P899 */ PIUnmapWindow(test_wdw2); wm_set_hints.flags = (StateHint); wm_set_hints.initial_state = NormalState; XSetWMHints(display, test_wdw2, &wm_set_hints); XMapWindow(display, test_wdw2); XMoveWindow(display, test_wdw2, 100, 300); CommonPause(); iteration++; /* * Put up a message box with the results of the test. */ display_summary(NUM_TESTS, TEST_DESCRIP_LENGTH, PIInfo); CommonPause(); /* * Loop and process events. */ XtAppMainLoop(app_context); }
void init_x(void) { XGCValues xgcv; XFontStruct *fontinfo; int i; dpy=XOpenDisplay(NULL); if (dpy==NULL) { fprintf(stderr,"Could not open display; is the DISPLAY variable set correctly?\n"); exit(1); } scr=DefaultScreen(dpy); width=900; height=600; ScreenWidth=width; ScreenHeight=height; vp.x2=width-1; vp.y2=height-1; // create our window w=XCreateWindow(dpy,RootWindow(dpy,scr),-1,-1, width, height, 0, CopyFromParent, InputOutput, CopyFromParent, 0, NULL); XMapWindow(dpy,w); XStoreName(dpy,w,"puff"); // create a background pixmap, that we're actually going to use for everything, because then the xserver takes care of redrawing the window when it is uncovered XGetWindowAttributes(dpy,w,&wa); pm=XCreatePixmap(dpy, RootWindow(dpy,scr),wa.width,wa.height,wa.depth); XSetWindowBackgroundPixmap(dpy,w,pm); // tell the window manager that we don't want to be resized to less than 640x480 (the old VGA resolution) XSizeHints* win_size_hints = XAllocSizeHints(); win_size_hints->flags = PMinSize; win_size_hints->min_width = 640; win_size_hints->min_height = 480; XSetWMNormalHints(dpy, w, win_size_hints); XFree(win_size_hints); // allocate 16 memory places to temporarily store pieces of the drawing for (i=0;i<16;i++) boxes[i]=XCreatePixmap(dpy, RootWindow(dpy,scr),32,32,wa.depth); // create several graphics contexts xgcv.foreground=WhitePixel(dpy,scr); xgcv.background=BlackPixel(dpy,scr); xgcv.function=GXcopy; gc = XCreateGC(dpy, w, GCForeground|GCBackground|GCFunction, &xgcv); XSetLineAttributes(dpy, gc, 1, LineSolid, CapRound, JoinRound); xgcv.foreground=BlackPixel(dpy,scr); xgcv.background=WhitePixel(dpy,scr); xgcv.function=GXcopy; gcclear = XCreateGC(dpy, w, GCForeground|GCBackground|GCFunction, &xgcv); gcpixel = XCreateGC(dpy, w, 0, &xgcv); xgcv.foreground=WhitePixel(dpy,scr); xgcv.background=BlackPixel(dpy,scr); xgcv.function=GXcopy; gctext = XCreateGC(dpy, w, GCForeground|GCBackground|GCFunction, &xgcv); xgcv.background=WhitePixel(dpy,scr); xgcv.foreground=BlackPixel(dpy,scr); xgcv.function=GXcopy; gcfill = XCreateGC(dpy, w, GCForeground|GCBackground|GCFunction, &xgcv); XSetLineAttributes(dpy, gcfill, 1000, LineSolid, CapRound, JoinRound); // very thick line, see FloodFill() for explanation // clear the screen XFillRectangle(dpy, pm, gcfill, 0,0,ScreenWidth,ScreenHeight); XClearWindow(dpy,w); // load an 8x13 font; the VGA font on which the partitioning of the screen is based is an 8x14 font fontinfo=XLoadQueryFont(dpy,"8x13"); XSetFont(dpy,gctext,fontinfo->fid); XSetFont(dpy,gc,fontinfo->fid); fontyoffs=fontinfo->ascent; // allocate a set of colours corresponding to those of the VGA mode originally used by puff getpascalcolours(); XSelectInput(dpy,w,KeyPressMask|KeyReleaseMask|StructureNotifyMask); XFlush(dpy); }
static void * whirlygig_init (Display *dpy, Window window) { struct state *st = (struct state *) calloc (1, sizeof(*st)); st->dpy = dpy; st->window = window; st->ncolors = NCOLORS; st->dbuf = get_boolean_resource (st->dpy, "doubleBuffer", "Boolean"); # ifdef HAVE_COCOA /* Don't second-guess Quartz's double-buffering */ st->dbuf = False; # endif st->start_time = st->current_time; st->info = (struct info *)malloc(sizeof(struct info)); st->screen = DefaultScreen(st->dpy); XGetWindowAttributes (st->dpy, st->window, &st->xgwa); if (st->dbuf) { #ifdef HAVE_DOUBLE_BUFFER_EXTENSION if (get_boolean_resource(st->dpy,"useDBE","Boolean")) { st->dbeclear_p = get_boolean_resource (st->dpy, "useDBEClear", "Boolean"); if (st->dbeclear_p) st->b = xdbe_get_backbuffer (st->dpy, st->window, XdbeBackground); else st->b = xdbe_get_backbuffer (st->dpy, st->window, XdbeUndefined); st->backb = st->b; } #endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ if (!st->b) { st->ba = XCreatePixmap (st->dpy, st->window, st->xgwa.width, st->xgwa.height,st->xgwa.depth); st->b = st->ba; } } else { st->b = st->window; } st->gcv.foreground = get_pixel_resource(st->dpy, st->xgwa.colormap, "foreground", "Foreground"); st->fgc = XCreateGC (st->dpy, st->b, GCForeground, &st->gcv); st->gcv.foreground = get_pixel_resource(st->dpy, st->xgwa.colormap, "background", "Background"); st->bgc = XCreateGC (st->dpy, st->b, GCForeground, &st->gcv); #ifdef HAVE_COCOA /* #### should turn off double-buffering instead */ jwxyz_XSetAntiAliasing (dpy, st->fgc, False); jwxyz_XSetAntiAliasing (dpy, st->bgc, False); #endif { Bool writable_p = False; make_uniform_colormap (st->dpy, st->xgwa.visual, st->xgwa.colormap, st->colors, &st->ncolors, True, &writable_p, True); } if (st->ba) XFillRectangle (st->dpy, st->ba, st->bgc, 0, 0, st->xgwa.width, st->xgwa.height); /* info is a structure holding all the random pieces of information I may want to pass to my baby functions -- much of it I may never use, but it is nice to have around just in case I want it to make a funky function funkier */ /* info->writable = get_boolean_resource (dpy, "cycle", "Boolean"); */ st->info->xspeed = get_float_resource(st->dpy, "xspeed" , "Float"); st->info->yspeed = get_float_resource(st->dpy, "yspeed" , "Float"); st->info->xamplitude = get_float_resource(st->dpy, "xamplitude", "Float"); st->info->yamplitude = get_float_resource(st->dpy, "yamplitude", "Float"); st->info->offset_period = get_float_resource(st->dpy, "offset_period", "Float"); st->info->whirlies = get_integer_resource(st->dpy, "whirlies", "Integer"); st->info->nlines = get_integer_resource(st->dpy, "nlines", "Integer"); st->info->half_width = st->xgwa.width / 2; st->info->half_height = st->xgwa.height / 2; st->info->speed = get_integer_resource(st->dpy, "speed" , "Integer"); st->info->trail = get_boolean_resource(st->dpy, "trail", "Integer"); st->info->color_modifier = get_integer_resource(st->dpy, "color_modifier", "Integer"); st->info->xoffset = get_float_resource(st->dpy, "xoffset", "Float"); st->info->yoffset = get_float_resource(st->dpy, "yoffset", "Float"); st->xmode_str = get_string_resource(st->dpy, "xmode", "Mode"); st->ymode_str = get_string_resource(st->dpy, "ymode", "Mode"); st->wrap = get_boolean_resource(st->dpy, "wrap", "Boolean"); st->modifier = 3000.0 + frand(1500.0); if (! st->xmode_str) st->xmode = spin_mode; else if (! strcmp (st->xmode_str, "spin")) st->xmode = spin_mode; else if (! strcmp (st->xmode_str, "funky")) st->xmode = funky_mode; else if (! strcmp (st->xmode_str, "circle")) st->xmode = circle_mode; else if (! strcmp (st->xmode_str, "linear")) st->xmode = linear_mode; else if (! strcmp (st->xmode_str, "test")) st->xmode = test_mode; else if (! strcmp (st->xmode_str, "fun")) st->xmode = fun_mode; else if (! strcmp (st->xmode_str, "innie")) st->xmode = innie_mode; else if (! strcmp (st->xmode_str, "lissajous")) st->xmode = lissajous_mode; else { st->xmode = random() % (int) lissajous_mode; } if (! st->ymode_str) st->ymode = spin_mode; else if (! strcmp (st->ymode_str, "spin")) st->ymode = spin_mode; else if (! strcmp (st->ymode_str, "funky")) st->ymode = funky_mode; else if (! strcmp (st->ymode_str, "circle")) st->ymode = circle_mode; else if (! strcmp (st->ymode_str, "linear")) st->ymode = linear_mode; else if (! strcmp (st->ymode_str, "test")) st->ymode = test_mode; else if (! strcmp (st->ymode_str, "fun")) st->ymode = fun_mode; else if (! strcmp (st->ymode_str, "innie")) st->ymode = innie_mode; else if (! strcmp (st->ymode_str, "lissajous")) st->ymode = lissajous_mode; else { st->ymode = random() % (int) lissajous_mode; } if (get_integer_resource(st->dpy, "start_time", "Integer") == -1) st->current_time = (unsigned long int)(random()); else st->current_time = get_integer_resource(st->dpy, "start_time", "Integer"); if (st->info->whirlies == -1) st->info->whirlies = 1 + (random() % 15); if (st->info->nlines == -1) st->info->nlines = 1 + (random() % 5); if (st->info->color_modifier == -1) st->info->color_modifier = 1 + (random() % 25); if (get_boolean_resource(st->dpy, "explain", "Integer")) st->explaining = 1; st->current_color = 1 + (random() % NCOLORS); return st; }
ClientWin * clientwin_create(MainWin *mw, Window client) { session_t *ps = mw->ps; ClientWin *cw = allocchk(malloc(sizeof(ClientWin))); { static const ClientWin CLIENTWT_DEF = CLIENTWT_INIT; memcpy(cw, &CLIENTWT_DEF, sizeof(ClientWin)); } XWindowAttributes attr; cw->mainwin = mw; cw->wid_client = client; if (ps->o.includeFrame) cw->src.window = wm_find_frame(ps, client); if (!cw->src.window) cw->src.window = client; cw->mini.format = mw->format; { XSetWindowAttributes sattr = { .border_pixel = 0, .background_pixel = 0, .colormap = mw->colormap, .event_mask = ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | ExposureMask | FocusChangeMask, .override_redirect = ps->o.lazyTrans, }; cw->mini.window = XCreateWindow(ps->dpy, (ps->o.lazyTrans ? ps->root : mw->window), 0, 0, 1, 1, 0, mw->depth, InputOutput, mw->visual, CWColormap | CWBackPixel | CWBorderPixel | CWEventMask | CWOverrideRedirect, &sattr); } if (!cw->mini.window) goto clientwin_create_err; { static const char *PREFIX = "mini window of "; const int len = strlen(PREFIX) + 20; char *str = allocchk(malloc(len)); snprintf(str, len, "%s%#010lx", PREFIX, cw->src.window); wm_wid_set_info(cw->mainwin->ps, cw->mini.window, str, None); free(str); } // Listen to events on the window. We don't want to miss any changes so // this is to be done as early as possible XSelectInput(cw->mainwin->ps->dpy, cw->src.window, SubstructureNotifyMask | StructureNotifyMask); XGetWindowAttributes(ps->dpy, client, &attr); if (IsViewable != attr.map_state) goto clientwin_create_err; clientwin_update(cw); // Get window pixmap if (ps->o.useNameWindowPixmap) { XCompositeRedirectWindow(ps->dpy, cw->src.window, CompositeRedirectAutomatic); cw->redirected = true; cw->cpixmap = XCompositeNameWindowPixmap(ps->dpy, cw->src.window); } // Create window picture { Drawable draw = cw->cpixmap; if (!draw) draw = cw->src.window; XRenderPictureAttributes pa = { .subwindow_mode = IncludeInferiors }; cw->origin = XRenderCreatePicture(cw->mainwin->ps->dpy, draw, cw->src.format, CPSubwindowMode, &pa); } if (!cw->origin) goto clientwin_create_err; XRenderSetPictureFilter(cw->mainwin->ps->dpy, cw->origin, FilterBest, 0, 0); return cw; clientwin_create_err: if (cw) clientwin_destroy(cw, False); return NULL; } void clientwin_update(ClientWin *cw) { Window tmpwin; XWindowAttributes wattr; XGetWindowAttributes(cw->mainwin->ps->dpy, cw->src.window, &wattr); XTranslateCoordinates(cw->mainwin->ps->dpy, cw->src.window, wattr.root, -wattr.border_width, -wattr.border_width, &cw->src.x, &cw->src.y, &tmpwin); cw->src.width = wattr.width; cw->src.height = wattr.height; cw->src.format = XRenderFindVisualFormat(cw->mainwin->ps->dpy, wattr.visual); cw->mini.x = cw->mini.y = 0; cw->mini.width = cw->mini.height = 1; }
Rect get_window_frame_size() { #ifdef WIN32 RECT border_rect; border_rect.left = 200; border_rect.right = 200 + 200; border_rect.top = 200; border_rect.bottom = 200 + 200; AdjustWindowRectEx(&border_rect, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX, FALSE, 0); Rect border_size(border_rect.left - 200, border_rect.top - 200, border_rect.right - 400, border_rect.bottom - 400); #else Display *d; Window w; d=XOpenDisplay(NULL); if(d==NULL) { throw Exception("Cannot open display"); } int s=DefaultScreen(d); const int win_xpos = 128; const int win_ypos = 128; const int win_width = 128; const int win_height = 128; w=XCreateSimpleWindow(d, RootWindow(d, s), win_xpos, win_ypos, win_width, win_height, 0, BlackPixel(d, s), WhitePixel(d, s)); XSelectInput(d, w, ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | StructureNotifyMask | PropertyChangeMask | PointerMotionMask | EnterWindowMask | LeaveWindowMask | KeymapStateMask | FocusChangeMask); // setup size hints: XSizeHints size_hints; memset(&size_hints, 0, sizeof(XSizeHints)); size_hints.x = win_xpos; size_hints.y = win_ypos; size_hints.width = win_width; size_hints.height = win_height; size_hints.base_width = win_width; size_hints.base_height = win_height; size_hints.min_width = size_hints.width; size_hints.min_height = size_hints.height; size_hints.max_width = size_hints.width; size_hints.max_height = size_hints.height; size_hints.flags = PSize|PBaseSize; size_hints.flags |= PMinSize | PMaxSize | PPosition; // These flags are important XSetWMNormalHints(d, w, &size_hints); XMapWindow(d, w); // Wait for mapped XEvent event; do { XMaskEvent(d, StructureNotifyMask, &event); }while ( (event.type != MapNotify) || (event.xmap.event != w) ); int xpos; int ypos; unsigned int width; unsigned int height; Window *children_ptr; unsigned int num_child; Window temp_window; XWindowAttributes attr; XGetWindowAttributes(d, w, &attr); xpos = attr.x; ypos = attr.y; width = attr.width; height = attr.height; // Search all parent windows .... there MUST be an easier may Window current_window = w; while(true) { children_ptr = NULL; XQueryTree(d, current_window, &temp_window, ¤t_window, &children_ptr, &num_child); if (children_ptr) XFree(children_ptr); if (!current_window) break; XGetWindowAttributes(d, current_window, &attr); xpos += attr.x; ypos += attr.y; } XDestroyWindow(d, w); XCloseDisplay(d); xpos -= win_xpos; ypos -= win_ypos; Rect border_size = Rect(-xpos, -ypos, 0, 0); #endif return border_size; }
int main(int argc, char** argv) { int width, height; int i; int fd; const char* display_name; display_name = getenv("DISPLAY"); display = XOpenDisplay(display_name); // This program may be installed as setuid root, so we don't want the // environment to affect the behavior of this program in unexpected, // potentially insecure, ways. environ = 0; // Move out of the way so that this process never holds up umount. if (-1 == chdir("/")) err(EXIT_FAILURE, "Failed to switch directory to the root directory"); // SysRq+F and runaway processes can activate the OOM killer, which may very // well kill this process. This is, of course, very bad for a screen locking // program, so we try to tell the OOM killer to kill us last. if (-1 != (fd = open("/proc/self/oom_adj", O_WRONLY))) { write(fd, "-17", 3); close(fd); } user_name = get_user_name(); host_name = get_host_name(); get_password_hash(); // Drop super-user privileges if we have to. if (0 == geteuid()) { setgid(getuid()); setuid(getuid()); } if (!display) errx(EXIT_FAILURE, "Failed to open display %s", display_name); if (!glXQueryExtension(display, 0, 0)) errx(EXIT_FAILURE, "No GLX extension present"); int attributes[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 16, None }; visual = glXChooseVisual(display, DefaultScreen(display), attributes); if (!visual) errx(EXIT_FAILURE, "glXChooseVisual failed"); XWindowAttributes root_window_attr; XGetWindowAttributes(display, RootWindow(display, DefaultScreen(display)), &root_window_attr); GLXContext glx_context = glXCreateContext(display, visual, 0, GL_TRUE); if (!glx_context) errx(EXIT_FAILURE, "Failed creating OpenGL context"); Colormap color_map = XCreateColormap( display, RootWindow(display, visual->screen), visual->visual, AllocNone); Pixmap mask = XCreatePixmap(display, XRootWindow(display, 0), 1, 1, 1); XGCValues xgc; xgc.function = GXclear; GC gc = XCreateGC(display, mask, GCFunction, &xgc); XFillRectangle(display, mask, gc, 0, 0, 1, 1); XColor color; color.pixel = 0; color.red = 0; color.flags = 4; Cursor cursor = XCreatePixmapCursor(display, mask, mask, &color, &color, 0, 0); XFreePixmap(display, mask); XFreeGC(display, gc); XSetWindowAttributes attr; attr.colormap = color_map; attr.border_pixel = 0; attr.event_mask = KeyPressMask | VisibilityChangeMask | ExposureMask | StructureNotifyMask | FocusChangeMask; attr.cursor = cursor; attr.override_redirect = True; width = root_window_attr.width; height = root_window_attr.height; window = XCreateWindow( display, RootWindow(display, visual->screen), 0, 0, width, height, 0, visual->depth, InputOutput, visual->visual, CWOverrideRedirect | CWCursor | CWColormap | CWEventMask, &attr); XMapRaised(display, window); attempt_grab(); XSetInputFocus(display, window, RevertToParent, CurrentTime); XFlush(display); char* p; if ((p = XSetLocaleModifiers("")) && *p) xim = XOpenIM(display, 0, 0, 0); if (!xim && (p = XSetLocaleModifiers("@im=none")) && *p) xim = XOpenIM(display, 0, 0, 0); if (!xim) errx(EXIT_FAILURE, "Failed to open X Input Method"); xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, window, XNFocusWindow, window, NULL); if (!xic) errx(EXIT_FAILURE, "Failed to create X Input Context"); XEvent event; XIfEvent(display, &event, wait_for_map_notify, (char*)window); if (!glXMakeCurrent(display, window, glx_context)) errx(EXIT_FAILURE, "glXMakeCurrent returned false"); if (XineramaQueryExtension(display, &i, &i) && XineramaIsActive(display)) screens = XineramaQueryScreens(display, &screen_count); if (!screen_count) { screen_count = 1; screens = malloc(sizeof(XineramaScreenInfo) * 1); screens[0].x_org = 0; screens[0].y_org = 0; screens[0].width = root_window_attr.width; screens[0].height = root_window_attr.height; } LOCK_init(); int done = 0; struct timeval start; gettimeofday(&start, 0); while (!done) { struct timeval now; double delta_time; gettimeofday(&now, 0); while (now.tv_sec < start.tv_sec) now.tv_sec += 24 * 60 * 60; while (XPending(display)) { XNextEvent(display, &event); switch (event.type) { case KeyPress: { char text[32]; Status status; KeySym key_sym; int len = Xutf8LookupString(xic, &event.xkey, text, sizeof(text) - 1, &key_sym, &status); text[len] = 0; LOCK_handle_key(key_sym, text); } break; case ConfigureNotify: width = event.xconfigure.width; height = event.xconfigure.height; glViewport(0, 0, event.xconfigure.width, event.xconfigure.height); break; case FocusOut: // If keyboard grabs have been unsuccessful so far, a FocusOut event // may occur. If so, we change the focus right back. XSetInputFocus(display, window, RevertToParent, CurrentTime); break; case VisibilityNotify: if (event.xvisibility.state != VisibilityUnobscured) XRaiseWindow(display, window); break; } } delta_time = (now.tv_sec - start.tv_sec) + (now.tv_usec - start.tv_usec) * 1.0e-6; start = now; LOCK_process_frame(width, height, delta_time); glXSwapBuffers(display, window); attempt_grab(); } return EXIT_SUCCESS; }