int main( int argc, char* argv[] ) { // see openwindow.min for the setup code ... display = XOpenDisplay(""); if (!display) exit (-1); int screen = XDefaultScreen(display); int w = 300; int h = 300; window = XCreateSimpleWindow(display,DefaultRootWindow(display), 10, 10, w, h, 2, XBlackPixel(display, screen), XWhitePixel(display, screen)); XMapRaised(display, window); XFlush(display); sleep(1); // let server get set up before sending drawing commands // this is a hack until we get to events // drawing demo with graphics context here ... GC gc = XCreateGC(display, window, 0, 0); // create a graphics context XSetForeground(display, gc, XBlackPixel(display, screen)); XSetBackground(display, gc, XWhitePixel(display, screen)); XSetFillStyle(display, gc, FillSolid); XSetLineAttributes(display, gc, 3, // 3 is line width LineSolid, CapButt, JoinRound); // other line options // draw some things XDrawLine(display, window, gc, 10, 10, w-10, h-10); XFillRectangle(display, window, gc, 50, 50, w-(2*50), h-(2*50)); XSetForeground(display, gc, XWhitePixel(display, screen)); XDrawLine(display, window, gc, w-10, 10, 10, h-10); XFlush(display); std::cout << "ENTER2exit"; std::cin.get(); // wait for input XCloseDisplay(display); }
void Widget::show(const Point &point) { const iint32 x = point.x(); const iint32 y = point.y(); const iint32 width = minimumSize().width(); const iint32 height = minimumSize().height(); IdealGUI::Application *app = static_cast<IdealGUI::Application*>(application()); IdealGUI::Application::PrivateImpl *a_d = static_cast<IdealGUI::Application::PrivateImpl*>(app->d); Display *dpy = a_d->m_dpy; if (!D_I->m_window) { if (!d->m_parentWidget) { D_I->m_window = XCreateSimpleWindow(dpy, XDefaultRootWindow(dpy), x, y, width, height, 0, XWhitePixel(dpy, XDefaultScreen(dpy)), XWhitePixel(dpy, XDefaultScreen(dpy))); } else { D_I->m_window = XCreateSimpleWindow(dpy, static_cast<IdealGUI::Widget::PrivateImpl*>(d->m_parentWidget->d)->m_window, x, y, width, height, 0, XWhitePixel(dpy, XDefaultScreen(dpy)), XWhitePixel(dpy, XDefaultScreen(dpy))); } a_d->m_widgetMap[D_I->m_window] = this; XSelectInput(dpy, D_I->m_window, ExposureMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | FocusChangeMask | KeyPressMask | KeyReleaseMask | StructureNotifyMask | SubstructureNotifyMask); } XMapWindow(dpy, D_I->m_window); D_I->m_cs = cairo_xlib_surface_create(dpy, D_I->m_window, DefaultVisual(dpy, 0), width, height); }
int main(int argc, char *argv[]) { Display *dpy = XOpenDisplay(NULL); Window p; int x, y, width, height; char command[1000]; char hostname[256]; if (argc!=7) { fprintf(stderr, "usage: %s <parent> <x> <y> <width> <height> <pathname>\n", argv[0]); exit(EXIT_FAILURE); } sscanf(argv[1], "%x", (unsigned int *)&p); sscanf(argv[2], "%d", &x); sscanf(argv[3], "%d", &y); sscanf(argv[4], "%d", &width); sscanf(argv[5], "%d", &height); if (gethostname(&hostname[0], 255)!=0) { fprintf(stderr, "Can't get hostname\n"); exit(EXIT_FAILURE); } Window w = XCreateSimpleWindow(dpy, p, x, y, width, height, 0, XWhitePixel(dpy, 0), XWhitePixel(dpy, 0)); XMapRaised(dpy, w); XFlush(dpy); /* needs work: to check overflow */ /* -vo gl crashes tlamachilistli */ /* -vo x11 doesn't crash tlamachilistli but doesn't resize */ /* -vo xv doesn't display on external vga on thakaa */ /* -vo xv doesn't resize in tightvnc */ if (strcmp(hostname, "thakaa.ecn.purdue.edu")==0) { sprintf(&command[0], "mplayer 2>/dev/null -really-quiet -wid 0x%x -vo gl %s", (unsigned int)w, argv[6]); } else if (strcmp(hostname, "etterretning.ecn.purdue.edu")==0|| strcmp(hostname, "etterretning")==0) { sprintf(&command[0], "mplayer 2>/dev/null -really-quiet -wid 0x%x -vo x11 -zoom %s", (unsigned int)w, argv[6]); } else { sprintf(&command[0], "mplayer 2>/dev/null -really-quiet -wid 0x%x -vo xv %s", (unsigned int)w, argv[6]); } system(&command[0]); exit(EXIT_SUCCESS); }
int main(void) { Display *d; int s; Window w; XEvent ev; int should_quit = 0; d = XOpenDisplay(NULL); s = XDefaultScreen(d); w = XCreateSimpleWindow(d, XRootWindow(d, s), 0, 0, 200, 200, 0, XBlackPixel(d, s), XWhitePixel(d, s)); XSelectInput(d, w, ButtonPressMask); XMapWindow(d, w); while(!should_quit) { XNextEvent(d, &ev); switch(ev.type) { case ButtonPress: should_quit = 1; break; default: } } return 0; }
unsigned char *rmdMakeDummyPointer(Display *display, DisplaySpecs *specs, int size, int color, int type, unsigned char *npxl){ unsigned long bpixel = XBlackPixel(display, specs->screen); unsigned long wpixel = XWhitePixel(display, specs->screen); int i,k,o='.'; unsigned long b=(color)?'w':'b', w=(color)?'b':'w'; char pmask[1][16][16]={{ {w,w,o,o,o,o,o,o,o,o,o,o,o,o,o,o}, {w,b,w,o,o,o,o,o,o,o,o,o,o,o,o,o}, {w,b,b,w,o,o,o,o,o,o,o,o,o,o,o,o}, {w,b,b,b,w,o,o,o,o,o,o,o,o,o,o,o}, {w,b,b,b,b,w,o,o,o,o,o,o,o,o,o,o}, {w,b,b,b,b,b,w,o,o,o,o,o,o,o,o,o}, {w,b,b,b,b,b,b,w,o,o,o,o,o,o,o,o}, {w,b,b,b,b,b,b,b,w,o,o,o,o,o,o,o}, {w,b,b,b,b,b,b,b,b,w,o,o,o,o,o,o}, {w,b,b,b,b,b,w,w,w,w,o,o,o,o,o,o}, {w,b,b,b,b,b,w,o,o,o,o,o,o,o,o,o}, {w,b,b,w,w,b,b,w,o,o,o,o,o,o,o,o}, {w,b,w,o,w,b,b,w,o,o,o,o,o,o,o,o}, {w,w,o,o,o,w,b,b,w,o,o,o,o,o,o,o}, {o,o,o,o,o,w,b,b,w,o,o,o,o,o,o,o}, {o,o,o,o,o,o,w,w,o,o,o,o,o,o,o,o}} }; unsigned char *ret=malloc(size*sizeof(char[size*4])); unsigned char wp[4]={ (wpixel ^ 0xff000000) >> 24, (wpixel ^ 0x00ff0000) >> 16, (wpixel ^ 0x0000ff00) >> 8, (wpixel ^ 0x000000ff) }; unsigned char bp[4]={ (bpixel ^ 0xff000000) >> 24, (bpixel ^ 0x00ff0000) >> 16, (bpixel ^ 0x0000ff00) >> 8, (bpixel ^ 0x000000ff) }; *npxl=((wp[0]-1)!=bp[0])?wp[0]-100:wp[0]-102; for(i=0;i<size;i++){ for(k=0;k<size;k++){ ret[(i*size+k)*4+__ABYTE]=(pmask[type][i][k]=='w')? wp[0]:(pmask[type][i][k]=='b')? bp[0]:*npxl; ret[(i*size+k)*4+__RBYTE]=(pmask[type][i][k]=='w')? wp[1]:(pmask[type][i][k]=='b')? bp[1]:*npxl; ret[(i*size+k)*4+__GBYTE]=(pmask[type][i][k]=='w')? wp[2]:(pmask[type][i][k]=='b')? bp[2]:*npxl; ret[(i*size+k)*4+__BBYTE]=(pmask[type][i][k]=='w')? wp[3]:(pmask[type][i][k]=='b')? bp[3]:*npxl; } } return ret; }
int main (int argc, char *argv[]) { Display *dpy; Visual *visual; int depth; XSetWindowAttributes attributes; Window win; XFontStruct *fontinfo; XColor color, dummy; XGCValues gr_values; GC gc; XKeyEvent event; dpy = XOpenDisplay(NULL); visual = DefaultVisual(dpy, 0); depth = DefaultDepth(dpy, 0); attributes.background_pixel = XWhitePixel(dpy, 0); /* create the application window */ win = XCreateWindow(dpy, XRootWindow(dpy, 0), 50, 50, 400, 400, 5, depth, InputOutput, visual, CWBackPixel, &attributes); XSelectInput(dpy, win, ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask); fontinfo = XLoadQueryFont(dpy, "6x10"); XAllocNamedColor(dpy, DefaultColormap(dpy, 0), "green", &color, &dummy); gr_values.font = fontinfo->fid; gr_values.foreground = color.pixel; gc = XCreateGC(dpy, win, GCFont+GCForeground, &gr_values); XMapWindow(dpy, win); /* run till key press */ while(1){ XNextEvent(dpy, (XEvent *)&event); switch(event.type) { case Expose: XDrawLine(dpy, win, gc, 0, 0, 100, 100); XDrawRectangle(dpy, win, gc, 140, 140, 50, 50); XDrawString(dpy, win, gc, 100, 100, "hello X world", 13); break; case ButtonPress: case KeyPress: XUnloadFont(dpy, fontinfo->fid); XFreeGC(dpy, gc); XCloseDisplay(dpy); exit(0); break; case ConfigureNotify: /* reconfigure size of window here */ break; default: break; } } return(0); }
void drawDecorations(Display *display, Drawable window, GC gc, const char *title, XWindowAttributes attr) { if (!white || !black) { white = XWhitePixel(display, DefaultScreen(display)); black = XBlackPixel(display, DefaultScreen(display)); } // Draw bounding box whiteOutTitleBar(display, window, gc, attr); XSetForeground(display, gc, black); XDrawRectangle(display, window, gc, RECT_TITLEBAR); // Draw texture for (int y = TITLEBAR_TEXTURE_START; y < TITLEBAR_TEXTURE_START + TITLEBAR_CONTROL_SIZE; y += TITLEBAR_TEXTURE_SPACE) { XDrawLine(display, window, gc, 2, y, attr.width - 4, y); } // White out areas for buttons and title XSetForeground(display, gc, white); // Subwindow box XFillRectangle(display, window, gc, 1, TITLEBAR_THICKNESS, attr.width - 3, attr.height - (TITLEBAR_THICKNESS + 3)); // Draw buttons and title XSetForeground(display, gc, black); // Subwindow box XDrawRectangle(display, window, gc, 0, TITLEBAR_THICKNESS - 1, attr.width - 2, attr.height - 20); // Shadow XDrawLine(display, window, gc, 1, attr.height - 1, attr.width, attr.height - 1); XDrawLine(display, window, gc, attr.width - 1, attr.height - 1, attr.width - 1, 1); // White out the shadow ends XSetForeground(display, gc, white); XDrawPoint(display, window, gc, 0, attr.height - 1); XDrawPoint(display, window, gc, attr.width - 1, 0); XSetForeground(display, gc, black); // Draw Title drawTitle(display, window, gc, title, attr); // Draw Close Button drawCloseButton(display, window, gc, RECT_CLOSE_BTN); // Draw Maximize Button drawMaximizeButton(display, window, gc, RECT_MAX_BTN); #ifdef COLLAPSE_BUTTON_ENABLED // Draw Collapse Button drawCollapseButton(display, window, gc, RECT_COLLAPSE_BTN); #endif }
static xrandrt_t *xrandrt_init(const char *display_name) { xrandrt_t *xr; int fd; Display *disp; disp = XOpenDisplay(display_name); if ((xr = malloc(sizeof(*xr))) == NULL) { if (disp != NULL) XCloseDisplay(disp); } else { fd = XConnectionNumber(disp); memset(xr, 0, sizeof(*xr)); xr->disp = disp; xr->chan = g_io_channel_unix_new(fd); xr->evsrc = g_io_add_watch(xr->chan, G_IO_IN|G_IO_HUP|G_IO_ERR, xevent_cb,xr); printf("videoep: xrandr initialized\n"); { Window root; Visual *vis; int sno; unsigned long wp; unsigned long bp; Window win; int depth; XSetWindowAttributes attr; unsigned long mask; root = XDefaultRootWindow(disp); sno = XDefaultScreen(disp); vis = XDefaultVisual(disp, sno); depth = XDefaultDepth(disp, sno); bp = XBlackPixel(disp, sno); wp = XWhitePixel(disp, sno); mask = CWBackPixel | CWBorderPixel | CWEventMask; attr.background_pixel = wp; attr.border_pixel = bp; attr.event_mask = ButtonPressMask | FocusChangeMask; win = XCreateWindow(disp, root, 50,50, 400,300, 1, depth, InputOutput, vis, mask, &attr); XMapWindow(disp,win); XFlush(disp); } } return xr; }
static GC display_X11_create_gc(void) { XGCValues gcval; gcval.foreground = XWhitePixel(disp, 0); gcval.function = GXxor; gcval.background = XBlackPixel(disp, 0); gcval.plane_mask = gcval.background ^ gcval.foreground; gcval.subwindow_mode = IncludeInferiors; return XCreateGC(disp, scr->root, GCFunction | GCForeground | GCBackground | GCSubwindowMode, &gcval); }
WindowLinux::WindowLinux(const std::string &windowTitle, const AE::OS::WindowDesc &windowDesc) : Window(windowTitle, windowDesc) { AE::OS::WindowManagerLinux *myWindowManager = static_cast<AE::OS::WindowManagerLinux *>(AE::OS::WindowManager::getInstance()); ::Display *x11display = myWindowManager->_getX11Display(); mScreenID = XDefaultScreen(x11display); XSetWindowAttributes attributes; Visual *visual = XDefaultVisual(x11display, mScreenID); attributes.background_pixel = XWhitePixel(x11display, mScreenID); attributes.border_pixel = XBlackPixel(x11display, mScreenID); // attributes.override_redirect = True; attributes.override_redirect = False; attributes.event_mask = ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask | SubstructureNotifyMask | ResizeRedirectMask | KeyPressMask | KeyReleaseMask | ExposureMask | EnterWindowMask | LeaveWindowMask | // VisibilityChangeMask | FocusChangeMask; mWindow = XCreateWindow(x11display, RootWindow(x11display, mScreenID), windowDesc.position.x, windowDesc.position.y, windowDesc.dimensions.x, windowDesc.dimensions.y, 1, /* border width */ CopyFromParent, /* color depth */ InputOutput, /* window class */ visual, CWBackPixel | CWBorderPixel | CWEventMask | CWOverrideRedirect /* enabled attributes */, &attributes); XStoreName(x11display, mWindow, windowTitle.c_str()); // Override of the 'x' button (the closing one) Atom wmDeleteMessage = XInternAtom(x11display, "WM_DELETE_WINDOW", false); XSetWMProtocols(x11display, mWindow, &wmDeleteMessage, 1); }
int main (int argc, char *argv[]) { Display *dpy; XSetWindowAttributes attributes; Window win; GC gc; XKeyEvent event; int i; dpy = XOpenDisplay(NULL); attributes.background_pixel = XWhitePixel(dpy, 0); win = XCreateWindow(dpy, XRootWindow(dpy, 0), 0, 0, WINDOW_SIZE, WINDOW_SIZE, 0, DefaultDepth(dpy, 0), InputOutput, DefaultVisual(dpy, 0), CWBackPixel, &attributes); XSelectInput(dpy, win, ExposureMask | KeyPressMask); gc = XCreateGC(dpy, win, 0, NULL); XMapWindow(dpy, win); while(1) { XNextEvent(dpy, (XEvent *)&event); switch(event.type) { case Expose: { for (i=0; i<WINDOW_SIZE/2; i++) XDrawPoint(dpy, win, gc, WINDOW_SIZE/4+i, WINDOW_SIZE/2); } break; case KeyPress: { XFreeGC(dpy, gc); XCloseDisplay(dpy); exit(0); } break; default: {} break; } } return 0; }
int schro_opengl_connect (SchroOpenGL * display, const char *display_name) { int usable; XGCValues values; XPixmapFormatValues *px_formats; int n_formats; int i; display->display = XOpenDisplay (display_name); if (display->display == NULL) { return FALSE; } #ifdef HANDLE_X_ERRORS XSynchronize (display->display, True); XSetErrorHandler (x_error_handler); #endif usable = schro_opengl_check_features (display); if (!usable) { return FALSE; } display->screen = DefaultScreenOfDisplay (display->display); display->screen_num = DefaultScreen (display->display); display->visual = DefaultVisual (display->display, display->screen_num); display->root = DefaultRootWindow (display->display); display->white = XWhitePixel (display->display, display->screen_num); display->black = XBlackPixel (display->display, display->screen_num); display->depth = DefaultDepthOfScreen (display->screen); display->gc = XCreateGC (display->display, DefaultRootWindow (display->display), 0, &values); px_formats = XListPixmapFormats (display->display, &n_formats); for (i = 0; i < n_formats; i++) { SCHRO_ERROR ("%d: depth %d bpp %d pad %d", i, px_formats[i].depth, px_formats[i].bits_per_pixel, px_formats[i].scanline_pad); } schro_opengl_init_tmp_window (display); return TRUE; }
Window scrot_create_window(Display *dpy, int x, int y, int width, int height) { Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), x, y, width, height, 0, XBlackPixel(disp, 0), XWhitePixel(disp, 0)); XSelectInput(dpy, w, PropertyChangeMask | StructureNotifyMask | SubstructureRedirectMask | ConfigureRequest /* | ExposureMask */ ); struct { unsigned long flags; unsigned long functions; unsigned long decorations; long input_mode; unsigned long status; } hints = { 2, 1, 0, 0, 0 }; // _MOTIF_WM_HINTS is respected by most window managers // but freedesktop intends to deprecate it // replace with _NET_WM_WINDOW_TYPE_DESKTOP ? XChangeProperty (dpy, w, XInternAtom (dpy, "_MOTIF_WM_HINTS", False), XInternAtom (dpy, "_MOTIF_WM_HINTS", False), 32, PropModeReplace, (const unsigned char *) &hints, sizeof (hints) / sizeof (long)); window_set_skip_taskbar(dpy, w); XMapWindow(dpy, w); XMoveWindow(dpy, w, x, y); for(;;) { XEvent e; XNextEvent(dpy, &e); if (e.type == MapNotify) break; } return w; }
void PSSetPixel(Display *display, int pixel) { if (pixel != current_gray) { current_gray = pixel; if (pixel == XBlackPixel(display, XDefaultScreen(display))) { fprintf(PSfp, "%d G\n", inverse); } else if (pixel == XWhitePixel(display, XDefaultScreen(display))) { fprintf(PSfp, "%d G\n", !inverse); } else { fprintf(PSfp, "%5.3f G\n", ComputeGray(pixel)); } } }
void inicjujOkno(){ mydisplay = XOpenDisplay(""); myscreen = DefaultScreen(mydisplay); myvisual = DefaultVisual(mydisplay,myscreen); mydepth = DefaultDepth(mydisplay,myscreen); mywindowattributes.background_pixel = XWhitePixel(mydisplay,0); mywindowattributes.override_redirect = False; mywindow = XCreateWindow(mydisplay,XRootWindow(mydisplay,myscreen), 100,100,400,400,10,mydepth,InputOutput, myvisual,CWBackPixel|CWOverrideRedirect, &mywindowattributes); XSelectInput(mydisplay,mywindow,ExposureMask|ButtonPressMask|KeyPressMask); colorMap = DefaultColormap(mydisplay,myscreen); XAllocNamedColor(mydisplay,colorMap,"sienna4",&darkBrown,&dummy); XAllocNamedColor(mydisplay,colorMap,"WhiteSmoke",&white,&dummy); XAllocNamedColor(mydisplay,colorMap,"black",&black,&dummy); XAllocNamedColor(mydisplay,colorMap,"chocolate1",&lightBrown,&dummy); XStoreName(mydisplay,mywindow,"Wilk i owce"); XMapWindow(mydisplay,mywindow); mygc = DefaultGC(mydisplay,myscreen); }
/* This function gets the X Display and global info about it. Everything is stored in our object and will be cleaned when the object is disposed. Note here that caps for supported format are generated without any window or image creation */ GstXContext * ximageutil_xcontext_get (GstElement * parent, const gchar * display_name) { GstXContext *xcontext = NULL; XPixmapFormatValues *px_formats = NULL; gint nb_formats = 0, i; xcontext = g_new0 (GstXContext, 1); xcontext->disp = XOpenDisplay (display_name); GST_DEBUG_OBJECT (parent, "opened display %p", xcontext->disp); if (!xcontext->disp) { g_free (xcontext); return NULL; } xcontext->screen = DefaultScreenOfDisplay (xcontext->disp); xcontext->screen_num = DefaultScreen (xcontext->disp); xcontext->visual = DefaultVisual (xcontext->disp, xcontext->screen_num); xcontext->root = DefaultRootWindow (xcontext->disp); xcontext->white = XWhitePixel (xcontext->disp, xcontext->screen_num); xcontext->black = XBlackPixel (xcontext->disp, xcontext->screen_num); xcontext->depth = DefaultDepthOfScreen (xcontext->screen); xcontext->width = DisplayWidth (xcontext->disp, xcontext->screen_num); xcontext->height = DisplayHeight (xcontext->disp, xcontext->screen_num); xcontext->widthmm = DisplayWidthMM (xcontext->disp, xcontext->screen_num); xcontext->heightmm = DisplayHeightMM (xcontext->disp, xcontext->screen_num); xcontext->caps = NULL; GST_DEBUG_OBJECT (parent, "X reports %dx%d pixels and %d mm x %d mm", xcontext->width, xcontext->height, xcontext->widthmm, xcontext->heightmm); ximageutil_calculate_pixel_aspect_ratio (xcontext); /* We get supported pixmap formats at supported depth */ px_formats = XListPixmapFormats (xcontext->disp, &nb_formats); if (!px_formats) { XCloseDisplay (xcontext->disp); g_free (xcontext); return NULL; } /* We get bpp value corresponding to our running depth */ for (i = 0; i < nb_formats; i++) { if (px_formats[i].depth == xcontext->depth) xcontext->bpp = px_formats[i].bits_per_pixel; } XFree (px_formats); xcontext->endianness = (ImageByteOrder (xcontext->disp) == LSBFirst) ? G_LITTLE_ENDIAN : G_BIG_ENDIAN; #ifdef HAVE_XSHM /* Search for XShm extension support */ if (XShmQueryExtension (xcontext->disp) && ximageutil_check_xshm_calls (xcontext)) { xcontext->use_xshm = TRUE; GST_DEBUG ("ximageutil is using XShm extension"); } else { xcontext->use_xshm = FALSE; GST_DEBUG ("ximageutil is not using XShm extension"); } #endif /* HAVE_XSHM */ /* our caps system handles 24/32bpp RGB as big-endian. */ if ((xcontext->bpp == 24 || xcontext->bpp == 32) && xcontext->endianness == G_LITTLE_ENDIAN) { xcontext->endianness = G_BIG_ENDIAN; xcontext->r_mask_output = GUINT32_TO_BE (xcontext->visual->red_mask); xcontext->g_mask_output = GUINT32_TO_BE (xcontext->visual->green_mask); xcontext->b_mask_output = GUINT32_TO_BE (xcontext->visual->blue_mask); if (xcontext->bpp == 24) { xcontext->r_mask_output >>= 8; xcontext->g_mask_output >>= 8; xcontext->b_mask_output >>= 8; }
Imlib_Image scrot_sel_and_grab_image(void) { Imlib_Image im = NULL; static int xfd = 0; static int fdsize = 0; XEvent ev; fd_set fdset; int count = 0, done = 0; int rx = 0, ry = 0, rw = 0, rh = 0, btn_pressed = 0; int rect_x = 0, rect_y = 0, rect_w = 0, rect_h = 0; Cursor cursor, cursor_nw, cursor_ne, cursor_se, cursor_sw; Window target = None; GC gc; XGCValues gcval; xfd = ConnectionNumber(disp); fdsize = xfd + 1; cursor = XCreateFontCursor(disp, XC_crosshair); cursor_nw = XCreateFontCursor(disp, XC_ul_angle); cursor_ne = XCreateFontCursor(disp, XC_ur_angle); cursor_se = XCreateFontCursor(disp, XC_lr_angle); cursor_sw = XCreateFontCursor(disp, XC_ll_angle); gcval.foreground = XWhitePixel(disp, 0); gcval.function = GXxor; gcval.background = XBlackPixel(disp, 0); gcval.plane_mask = gcval.background ^ gcval.foreground; gcval.subwindow_mode = IncludeInferiors; gc = XCreateGC(disp, root, GCFunction | GCForeground | GCBackground | GCSubwindowMode, &gcval); if ((XGrabPointer (disp, root, False, ButtonMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, root, cursor, CurrentTime) != GrabSuccess)) gib_eprintf("couldn't grab pointer:"); if ((XGrabKeyboard (disp, root, False, GrabModeAsync, GrabModeAsync, CurrentTime) != GrabSuccess)) gib_eprintf("couldn't grab keyboard:"); while (1) { /* handle events here */ while (!done && XPending(disp)) { XNextEvent(disp, &ev); switch (ev.type) { case MotionNotify: if (btn_pressed) { if (rect_w) { /* re-draw the last rect to clear it */ XDrawRectangle(disp, root, gc, rect_x, rect_y, rect_w, rect_h); } rect_x = rx; rect_y = ry; rect_w = ev.xmotion.x - rect_x; rect_h = ev.xmotion.y - rect_y; /* Change the cursor to show we're selecting a region */ if (rect_w < 0 && rect_h < 0) XChangeActivePointerGrab(disp, ButtonMotionMask | ButtonReleaseMask, cursor_nw, CurrentTime); else if (rect_w < 0 && rect_h > 0) XChangeActivePointerGrab(disp, ButtonMotionMask | ButtonReleaseMask, cursor_sw, CurrentTime); else if (rect_w > 0 && rect_h < 0) XChangeActivePointerGrab(disp, ButtonMotionMask | ButtonReleaseMask, cursor_ne, CurrentTime); else if (rect_w > 0 && rect_h > 0) XChangeActivePointerGrab(disp, ButtonMotionMask | ButtonReleaseMask, cursor_se, CurrentTime); if (rect_w < 0) { rect_x += rect_w; rect_w = 0 - rect_w; } if (rect_h < 0) { rect_y += rect_h; rect_h = 0 - rect_h; } /* draw rectangle */ XDrawRectangle(disp, root, gc, rect_x, rect_y, rect_w, rect_h); XFlush(disp); } break; case ButtonPress: btn_pressed = 1; rx = ev.xbutton.x; ry = ev.xbutton.y; target = scrot_get_window(disp, ev.xbutton.subwindow, ev.xbutton.x, ev.xbutton.y); if (target == None) target = root; break; case ButtonRelease: done = 1; break; case KeyPress: fprintf(stderr, "Key was pressed, aborting shot\n"); done = 2; break; case KeyRelease: /* ignore */ break; default: break; } } if (done) break; /* now block some */ FD_ZERO(&fdset); FD_SET(xfd, &fdset); errno = 0; count = select(fdsize, &fdset, NULL, NULL, NULL); if ((count < 0) && ((errno == ENOMEM) || (errno == EINVAL) || (errno == EBADF))) gib_eprintf("Connection to X display lost"); } if (rect_w) { XDrawRectangle(disp, root, gc, rect_x, rect_y, rect_w, rect_h); XFlush(disp); } XUngrabPointer(disp, CurrentTime); XUngrabKeyboard(disp, CurrentTime); XFreeCursor(disp, cursor); XFreeGC(disp, gc); XSync(disp, True); if (done < 2) { scrot_do_delay(); Window client_window = None; if (rect_w > 5) { /* if a rect has been drawn, it's an area selection */ rw = ev.xbutton.x - rx; rh = ev.xbutton.y - ry; if (rw < 0) { rx += rw; rw = 0 - rw; } if (rh < 0) { ry += rh; rh = 0 - rh; } } else { /* else it's a window click */ if (!scrot_get_geometry(target, &client_window, &rx, &ry, &rw, &rh)) return NULL; } scrot_nice_clip(&rx, &ry, &rw, &rh); XBell(disp, 0); if(opt.alpha) im = scrot_grab_transparent_shot(disp, client_window, rx, ry, rw, rh); else im = gib_imlib_create_image_from_drawable(root, 0, rx, ry, rw, rh, 1); } return im; }
int selectArea( Display *disp, Window *root, Rect *rect ) { int rx = 0, ry = 0, rw = 0, rh = 0; int rect_x = 0, rect_y = 0, rect_w = 0, rect_h = 0; int btn_pressed = 0, done = 0; XEvent ev; Cursor cursor, cursor2; cursor = XCreateFontCursor(disp, XC_left_ptr); cursor2 = XCreateFontCursor(disp, XC_lr_angle); XGCValues gcval; gcval.foreground = XWhitePixel(disp, 0); gcval.function = GXxor; gcval.background = XBlackPixel(disp, 0); gcval.plane_mask = gcval.background ^ gcval.foreground; gcval.subwindow_mode = IncludeInferiors; GC gc; gc = XCreateGC(disp, *root, GCFunction | GCForeground | GCBackground | GCSubwindowMode, &gcval); /* this XGrab* stuff makes XPending true ? */ if ((XGrabPointer (disp, *root, False, ButtonMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, *root, cursor, CurrentTime) != GrabSuccess)) { printf("couldn't grab pointer:"); return -1; } while (!done) { while (!done && XPending(disp)) { XNextEvent(disp, &ev); switch (ev.type) { case MotionNotify: /* this case is purely for drawing rect on screen */ if (btn_pressed) { if (rect_w) { /* re-draw the last rect to clear it */ XDrawRectangle(disp, *root, gc, rect_x, rect_y, rect_w, rect_h); } else { /* Change the cursor to show we're selecting a region */ XChangeActivePointerGrab(disp, ButtonMotionMask | ButtonReleaseMask, cursor2, CurrentTime); } rect_x = rx; rect_y = ry; rect_w = ev.xmotion.x - rect_x; rect_h = ev.xmotion.y - rect_y; if (rect_w < 0) { rect_x += rect_w; rect_w = 0 - rect_w; } if (rect_h < 0) { rect_y += rect_h; rect_h = 0 - rect_h; } /* draw rectangle */ XDrawRectangle(disp, *root, gc, rect_x, rect_y, rect_w, rect_h); XFlush(disp); } break; case ButtonPress: btn_pressed = 1; rx = ev.xbutton.x; ry = ev.xbutton.y; break; case ButtonRelease: done = 1; break; } } } /* clear the drawn rectangle */ if (rect_w) { XDrawRectangle(disp, *root, gc, rect_x, rect_y, rect_w, rect_h); XFlush(disp); } rw = ev.xbutton.x - rx; rh = ev.xbutton.y - ry; /* cursor moves backwards */ if (rw < 0) { rx += rw; rw = 0 - rw; } if (rh < 0) { ry += rh; rh = 0 - rh; } rect->w = rw; rect->h = rh; rect->x = rx; rect->y = ry; XFreeGC(disp, gc); return 0; }
int main(int argc, const char * argv[]) { if (argc != 2) { printf("Usage: %s output_filename\n", argv[0]); return EXIT_FAILURE; } const char * const filename = argv[1]; int rx = 0, ry = 0, rw = 0, rh = 0; int rect_x = 0, rect_y = 0, rect_w = 0, rect_h = 0; int btn_pressed = 0, done = 0; XEvent ev; Display *disp = XOpenDisplay(NULL); if(!disp) { return EXIT_FAILURE; } Screen *scr = NULL; scr = ScreenOfDisplay(disp, DefaultScreen(disp)); Window root = 0; root = RootWindow(disp, XScreenNumberOfScreen(scr)); Cursor cursor, cursor2; cursor = XCreateFontCursor(disp, XC_left_ptr); cursor2 = XCreateFontCursor(disp, XC_lr_angle); XGCValues gcval; gcval.foreground = XWhitePixel(disp, 0); gcval.function = GXxor; gcval.background = XBlackPixel(disp, 0); gcval.plane_mask = gcval.background ^ gcval.foreground; gcval.subwindow_mode = IncludeInferiors; GC gc; gc = XCreateGC(disp, root, GCFunction | GCForeground | GCBackground | GCSubwindowMode, &gcval); /* this XGrab* stuff makes XPending true ? */ if ((XGrabPointer (disp, root, False, ButtonMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, root, cursor, CurrentTime) != GrabSuccess)) printf("couldn't grab pointer:"); if ((XGrabKeyboard (disp, root, False, GrabModeAsync, GrabModeAsync, CurrentTime) != GrabSuccess)) printf("couldn't grab keyboard:"); while (!done) { while (!done && XPending(disp)) { XNextEvent(disp, &ev); switch (ev.type) { case MotionNotify: /* this case is purely for drawing rect on screen */ if (btn_pressed) { if (rect_w) { /* re-draw the last rect to clear it */ XDrawRectangle(disp, root, gc, rect_x, rect_y, rect_w, rect_h); } else { /* Change the cursor to show we're selecting a region */ XChangeActivePointerGrab(disp, ButtonMotionMask | ButtonReleaseMask, cursor2, CurrentTime); } rect_x = rx; rect_y = ry; rect_w = ev.xmotion.x - rect_x; rect_h = ev.xmotion.y - rect_y; if (rect_w < 0) { rect_x += rect_w; rect_w = 0 - rect_w; } if (rect_h < 0) { rect_y += rect_h; rect_h = 0 - rect_h; } /* draw rectangle */ XDrawRectangle(disp, root, gc, rect_x, rect_y, rect_w, rect_h); XFlush(disp); } break; case ButtonPress: btn_pressed = 1; rx = ev.xbutton.x; ry = ev.xbutton.y; break; case ButtonRelease: done = 1; break; } } } /* clear the drawn rectangle */ if (rect_w) { XDrawRectangle(disp, root, gc, rect_x, rect_y, rect_w, rect_h); XFlush(disp); } rw = ev.xbutton.x - rx; rh = ev.xbutton.y - ry; /* cursor moves backwards */ if (rw < 0) { rx += rw; rw = 0 - rw; } if (rh < 0) { ry += rh; rh = 0 - rh; } XCloseDisplay(disp); char buf[128]; sprintf(buf, "byzanz-record %s -c -x %d -y %d -w %d -h %d\n", filename, rx, ry, rw, rh); printf(buf); system(buf); return EXIT_SUCCESS; }
int main(int argc, char **argv) { char curs[] = {0, 0, 0, 0, 0, 0, 0, 0}; char buf[32], passwd[256], passdisp[256]; int num, screen, width, height, update, sleepmode, term, pid; #ifndef HAVE_BSD_AUTH const char *pws; #endif unsigned int len; Bool running = True; Cursor invisible; Display *dpy; KeySym ksym; Pixmap pmap; Window root, w; XColor black, red, dummy; XEvent ev; XSetWindowAttributes wa; XFontStruct* font; GC gc; XGCValues values; // defaults char* passchar = "*"; char* fontname = "-*-dejavu sans-bold-r-*-*-*-420-100-100-*-*-iso8859-1"; char* username = "******"; int showline = 1; for (int i = 0; i < argc; i++) { if (!strcmp(argv[i], "-c")) { if (i + 1 < argc) passchar = argv[i + 1]; else die("error: no password character given.\n"); } else if (!strcmp(argv[i], "-f")) { if (i + 1 < argc) fontname = argv[i + 1]; else die("error: font not specified.\n"); }else if (!strcmp(argv[i], "-u")) { if (i + 1 < argc) username = argv[i + 1]; else die("error: username not specified.\n"); } else if (!strcmp(argv[i], "-v")) die("sflock-"VERSION", © 2010 Ben Ruijl\n"); else if (!strcmp(argv[i], "-h")) showline = 0; else if (!strcmp(argv[i], "?")) die("usage: sflock [-v] [-c passchars] [-f fontname] [-u username]\n"); } // fill with password characters for (int i = 0; i < sizeof passdisp; i+= strlen(passchar)) for (int j = 0; j < strlen(passchar); j++) passdisp[i + j] = passchar[j]; /* disable tty switching */ if ((term = open("/dev/console", O_RDWR)) == -1) { perror("error opening console"); } if ((ioctl(term, VT_LOCKSWITCH)) == -1) { perror("error locking console"); } /* deamonize */ pid = fork(); if (pid < 0) die("Could not fork sflock."); if (pid > 0) exit(0); // exit parent #ifndef HAVE_BSD_AUTH pws = get_password(username); #else username = getlogin(); #endif if(!(dpy = XOpenDisplay(0))) die("sflock: cannot open dpy\n"); screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); width = DisplayWidth(dpy, screen); height = DisplayHeight(dpy, screen); wa.override_redirect = 1; wa.background_pixel = XBlackPixel(dpy, screen); w = XCreateWindow(dpy, root, 0, 0, width, height, 0, DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixel, &wa); XAllocNamedColor(dpy, DefaultColormap(dpy, screen), "orange red", &red, &dummy); XAllocNamedColor(dpy, DefaultColormap(dpy, screen), "black", &black, &dummy); pmap = XCreateBitmapFromData(dpy, w, curs, 8, 8); invisible = XCreatePixmapCursor(dpy, pmap, pmap, &black, &black, 0, 0); XDefineCursor(dpy, w, invisible); XMapRaised(dpy, w); font = XLoadQueryFont(dpy, fontname); if (font == 0) { die("error: could not find font. Try using a full description.\n"); } gc = XCreateGC(dpy, w, (unsigned long)0, &values); XSetFont(dpy, gc, font->fid); XSetForeground(dpy, gc, XWhitePixel(dpy, screen)); for(len = 1000; len; len--) { if(XGrabPointer(dpy, root, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask, GrabModeAsync, GrabModeAsync, None, invisible, CurrentTime) == GrabSuccess) break; usleep(1000); } if((running = running && (len > 0))) { for(len = 1000; len; len--) { if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime) == GrabSuccess) break; usleep(1000); } running = (len > 0); } len = 0; XSync(dpy, False); update = True; sleepmode = False; /* main event loop */ while(running && !XNextEvent(dpy, &ev)) { if (sleepmode) { DPMSEnable(dpy); DPMSForceLevel(dpy, DPMSModeOff); XFlush(dpy); } if (update) { int x, y, dir, ascent, descent; XCharStruct overall; XClearWindow(dpy, w); XTextExtents (font, passdisp, len, &dir, &ascent, &descent, &overall); x = (width - overall.width) / 2; y = (height + ascent - descent) / 2; XDrawString(dpy,w,gc, (width - XTextWidth(font, username, strlen(username))) / 2, y - ascent - 20, username, strlen(username)); if (showline) XDrawLine(dpy, w, gc, width * 3 / 8 , y - ascent - 10, width * 5 / 8, y - ascent - 10); XDrawString(dpy,w,gc, x, y, passdisp, len); update = False; } if (ev.type == MotionNotify) { sleepmode = False; } if(ev.type == KeyPress) { sleepmode = False; buf[0] = 0; num = XLookupString(&ev.xkey, buf, sizeof buf, &ksym, 0); if(IsKeypadKey(ksym)) { if(ksym == XK_KP_Enter) ksym = XK_Return; else if(ksym >= XK_KP_0 && ksym <= XK_KP_9) ksym = (ksym - XK_KP_0) + XK_0; } if(IsFunctionKey(ksym) || IsKeypadKey(ksym) || IsMiscFunctionKey(ksym) || IsPFKey(ksym) || IsPrivateKeypadKey(ksym)) continue; switch(ksym) { case XK_Return: passwd[len] = 0; #ifdef HAVE_BSD_AUTH running = !auth_userokay(getlogin(), NULL, "auth-xlock", passwd); #else running = strcmp(crypt(passwd, pws), pws); #endif if (running != 0) // change background on wrong password XSetWindowBackground(dpy, w, red.pixel); len = 0; break; case XK_Escape: len = 0; if (DPMSCapable(dpy)) { sleepmode = True; } break; case XK_BackSpace: if(len) --len; break; default: if(num && !iscntrl((int) buf[0]) && (len + num < sizeof passwd)) { memcpy(passwd + len, buf, num); len += num; } break; } update = True; // show changes } } /* free and unlock */ setreuid(geteuid(), 0); if ((ioctl(term, VT_UNLOCKSWITCH)) == -1) { perror("error unlocking console"); } close(term); setuid(getuid()); // drop rights permanently XUngrabPointer(dpy, CurrentTime); XFreePixmap(dpy, pmap); XFreeFont(dpy, font); XFreeGC(dpy, gc); XDestroyWindow(dpy, w); XCloseDisplay(dpy); return 0; }
main() { int xw,yw,xw1,yw1; int fdw; struct buffer *bufw; bufsize=sizeof(struct buffer); printf("Rozmiar bufora: %5d\n",bufsize); bufw=(struct buffer *) malloc(bufsize); p=getpid(); XInitThreads(); mydisplay = XOpenDisplay(""); myscreen = DefaultScreen(mydisplay); myvisual = DefaultVisual(mydisplay,myscreen); mydepth = DefaultDepth(mydisplay,myscreen); mywindowattributes.background_pixel = XWhitePixel(mydisplay,myscreen); mywindowattributes.override_redirect = False; mywindowattributes.backing_store = Always; mywindowattributes.bit_gravity = NorthWestGravity; mywindow = XCreateWindow(mydisplay,XRootWindow(mydisplay,myscreen), 0,0,500,500,10,mydepth,InputOutput, myvisual,CWBackingStore|CWBackingPlanes|CWBitGravity| CWBackPixel|CWOverrideRedirect,&mywindowattributes); XSelectInput(mydisplay,mywindow,KeyPressMask|ButtonPressMask|ButtonMotionMask); mycolormap = DefaultColormap(mydisplay,myscreen); XAllocNamedColor(mydisplay,mycolormap,"red",&mycolorm,&dummy); XAllocNamedColor(mydisplay,mycolormap,"blue",&mycolorm1,&dummy); XMapWindow(mydisplay,mywindow); mygc = DefaultGC(mydisplay,myscreen); fdw=open("rysunek",O_WRONLY|O_CREAT|O_APPEND,0700); printf("Plik otwarty do zapisu\n"); pthread_create(&tid,NULL,reader,(void *) &p); printf("Moj czytelnik utworzony\n"); pthread_create(&tid1,NULL,reader,NULL); printf("Jego czytelnik utworzony\n"); while (1) { XNextEvent(mydisplay,&myevent); printf("event no. %5d\n",myevent.type); switch (myevent.type) { case ButtonPress: xw1=myevent.xbutton.x; yw1=myevent.xbutton.y; printf("button: %3d %3d\n",xw1,yw1); bufw->x=xw1; bufw->y=yw1; bufw->prev=0; bufw->pid=p; write(fdw,bufw,bufsize); break; case MotionNotify: xw=myevent.xmotion.x; yw=myevent.xmotion.y; printf("motion: %3d %3d\n",xw,yw); bufw->x=xw; bufw->y=yw; bufw->prev=1; bufw->pid=p; write(fdw,bufw,bufsize); xw1=xw; yw1=yw; break; case KeyPress: XCloseDisplay(mydisplay); end(); close(fdw); exit(0); } } }
void InitXGraphics(int argc, char **argv, int ny, int nx, int nd, MET_MAP_PIX *** MetMap) { /* following is for the X11 libraries */ int i, x, y, screen; /* screen is an int. */ int border_width; int c1, c2, c3; float re, best_re; long dy, dx; int best_e, best_ndx, best_ndy; int el, ndxl, ndyl; int buf = 50; #ifdef HAVE_X11 Colormap cmap; /* map from pixel values to colors */ char *window_name = "DHSVM Realtime Display", *display_name = NULL; XSizeHints size_hints; /* connect to Xserver */ if ((display = XOpenDisplay(display_name)) == NULL) { fprintf(stderr, "InitXGraphics: cannot connect to X server %s\n", XDisplayName(display_name)); exit(-1); } /* get screen size */ screen = DefaultScreen(display); dx = 0.95 * DisplayWidth(display, screen); dy = 0.95 * DisplayHeight(display, screen); border_width = 4; x = 0; y = 0; /* figure out the actual size of the window and stuff */ /* now we need to figure out the expansion factor for the number of graphs */ /* want to maximize the size of each graph while constrained by the number of graphs and the screen size */ /* save top 20 pixels of the display for the date counter */ /* save 40 pixels for the X11 window title bar- allocated by system */ /* save left 10 pixels for border */ dx = dx - 10; dy = dy - 60; best_e = -10; best_ndx = 1; for (ndxl = 1; ndxl <= nd; ndxl++) { for (el = -10; el <= 10; el++) { if (el != 0) { if (el < 0) re = 1 / ((float) (-el)); if (el > 0) re = (float) el; ndyl = nd / (ndxl); if (ndxl * ndyl < nd) ndyl = ndyl + 1; c1 = nd * (nx * re + buf) * (ny * re + buf); c2 = ndxl * (nx * re + buf); c3 = ndyl * (ny * re + buf); if (c1 <= dx * dy && c2 <= dx && c3 <= dy) { /* printf("ndx %d ndy %d e %d \n",ndxl,ndy,el); printf("nx ny buf re %d %d %d %f\n",nx,ny,buf,re); printf("c1 c2 c3 rh1 rh2 rh3 %d %d %d %d %d %d \n",c1,c2,c3,dx*dy,dx,dy); */ if (el > best_e) { best_e = el; best_ndx = ndxl; best_re = re; } } } } } printf("best use of display for %d images: \n", nd); printf("Expand images by factor %f with %d columns\n", best_re, best_ndx); e = best_e; ndx = best_ndx; best_ndy = nd / best_ndx; if (best_ndy * best_ndx < nd) best_ndy = best_ndy + 1; /* now create the window given the new size classes */ dx = best_ndx * (nx * best_re + buf) + 10; dy = best_ndy * (ny * best_re + buf) + 60; window = XCreateSimpleWindow(display, RootWindow(display, screen), 0, 0, dx, dy, border_width, WhitePixel(display, screen), WhitePixel(display, screen)); size_hints.flags = PPosition | PSize | PMinSize | PMaxSize; size_hints.x = 0; size_hints.y = 0; size_hints.width = dx; size_hints.height = dy; size_hints.min_width = 200; size_hints.min_height = 200; size_hints.max_width = DisplayWidth(display, screen); size_hints.max_height = DisplayHeight(display, screen); XSetStandardProperties(display, window, window_name, window_name, None, NULL, 0, &size_hints); black = XBlackPixel(display, screen); white = XWhitePixel(display, screen); gc = XCreateGC(display, window, 0, 0); XMapWindow(display, window); cmap = XDefaultColormap(display, screen); /* black to blue */ for (i = 0; i < 10; i++) { my_color[i].red = 0; my_color[i].green = 0; my_color[i].blue = 65535 * i / 9; } /* blue to cyan */ for (i = 10; i < 20; i++) { my_color[i].red = 0; my_color[i].green = i * 65535 / 19; my_color[i].blue = 65535; } /*cyan to green */ for (i = 20; i < 25; i++) { my_color[i].red = 0; my_color[i].green = 65535; my_color[i].blue = 65535 - (65535 * (i - 20) / 5); } /*green to yellow */ for (i = 25; i < 30; i++) { my_color[i].red = (i - 25) * 65535 / 5; my_color[i].green = 65535; my_color[i].blue = 0; } /*yellow to magenta */ for (i = 30; i < 40; i++) { my_color[i].red = 65535; my_color[i].green = 65535 - (65535 * (i - 30) / 9); my_color[i].blue = 65535 * (i - 30) / 9; } /*magenta to red */ for (i = 40; i < 50; i++) { my_color[i].red = 65335; my_color[i].green = 0; my_color[i].blue = 65535 - (65535 * (i - 40) / 9); } for (i = 0; i < 50; i++) { if (XAllocColor(display, cmap, &my_color[i]) == 0) { printf("Can't do DHSVM colors\n"); exit(3); } } /* done initializing the X11 Display, available for drawing */ /* initialize the memory used solely by the drawing functions */ if (!((*MetMap) = (MET_MAP_PIX **) calloc(ny, sizeof(MET_MAP_PIX *)))) ReportError("InitXGraphics", 1); for (y = 0; y < ny; y++) { if (!((*MetMap)[y] = (MET_MAP_PIX *) calloc(nx, sizeof(MET_MAP_PIX)))) ReportError("InitXGraphics", 1); } if ((temp_array = (float **) malloc(ny * sizeof(float *))) == NULL) { ReportError("draw.c", 1); } for (y = 0; y < ny; y++) { if ((temp_array[y] = (float *) malloc(nx * sizeof(float))) == NULL) { ReportError("draw.c", 1); } } #endif }
void XWindow::init(const XDisplay &d) { windowMutex = new Mutex(true); delegationsToExecute = new Collection<void *>(); controls = new Collection<Control *>(); windowDisplay = d.d; windowScreen = XDefaultScreen(windowDisplay); windowParent = XRootWindow(windowDisplay, windowScreen); windowVisual = DefaultVisual(windowDisplay, windowScreen); area = new NRectangle(0, 0, 400, 300); borderwidth = 1; colordepth = DefaultDepth(windowDisplay, windowScreen); visible = false; backcolor = new NColor(0.95, 0.95, 0.97, 1.0); font = new NFont("Ubuntu Mono", NFont::FontWeightBold, 10); drawEnabled = true; composeKeySymBuffer = new Text(""); // Creates delegates dOnWindowKeyPress = new NDelegationManager(); dOnWindowKeyRelease = new NDelegationManager(); dOnWindowKeySymbol = new NDelegationManager(); dOnWindowKeymap = new NDelegationManager(); dOnWindowKeyboardMapping = new NDelegationManager(); dOnWindowMouseDown = new NDelegationManager(); dOnWindowMouseUp = new NDelegationManager(); dOnWindowMouseMove = new NDelegationManager(); dOnWindowEnterLeave = new NDelegationManager(); dOnWindowDraw = new NDelegationManager(); dOnWindowShow = new NDelegationManager(); dOnWindowMove = new NDelegationManager(); dOnWindowResize = new NDelegationManager(); dOnWindowFocus = new NDelegationManager(); dOnWindowPropertyChange = new NDelegationManager(); dOnWindowColormapChange = new NDelegationManager(); dOnWindowGrabButton = new NDelegationManager(); dOnWindowVisibilityChange = new NDelegationManager(); XSetWindowAttributes attrs; memset(&attrs, 0, sizeof(attrs)); attrs.background_pixel = XWhitePixel(windowDisplay, windowScreen); attrs.border_pixel = XBlackPixel(windowDisplay, windowScreen); attrs.override_redirect = 0; // Create window window = XCreateWindow( windowDisplay, windowParent, area->GetX(), area->GetY(), area->GetWidth(), area->GetHeight(), borderwidth, colordepth, InputOutput, windowVisual, CWBackPixel | CWBorderPixel | CWOverrideRedirect, &attrs); XException::CheckResult(window); // Select events int res = XSelectInput(windowDisplay, window, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | ButtonMotionMask | KeymapStateMask | ExposureMask | VisibilityChangeMask | StructureNotifyMask | FocusChangeMask | PropertyChangeMask | ColormapChangeMask | OwnerGrabButtonMask); XException::CheckResult(res); // Select Xkb events if (!XkbSelectEvents(windowDisplay, XkbUseCoreKbd, XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask, XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask)) throw new XException("Cannot select Xkb events", __FILE__, __LINE__, __func__); if (!XkbSelectEvents(windowDisplay, XkbUseCoreKbd, XkbAllEventsMask, XkbAllEventsMask)) throw new XException("Cannot select Xkb events", __FILE__, __LINE__, __func__); // Create a graphics context gc = new XWindowGraphics(*this); // Show window SetVisible(true); }
int wyswietl(circle *circles, int id) { mydisplay = XOpenDisplay(""); myscreen = DefaultScreen(mydisplay); myvisual = DefaultVisual(mydisplay,myscreen); mydepth = DefaultDepth(mydisplay,myscreen); mywindowattributes.background_pixel = XWhitePixel(mydisplay,myscreen); mywindowattributes.override_redirect = False; mywindowattributes.backing_store = Always; mywindowattributes.bit_gravity = NorthWestGravity; mywindow = XCreateWindow(mydisplay,XRootWindow(mydisplay,myscreen), 100,100,600,600,10,mydepth,InputOutput, myvisual,CWBackingStore|CWBackingPlanes|CWBitGravity| CWBackPixel|CWOverrideRedirect,&mywindowattributes); XSelectInput(mydisplay,mywindow,ExposureMask|KeyPressMask|KeyReleaseMask|ButtonPressMask|ButtonMotionMask); mycolormap = DefaultColormap(mydisplay,myscreen); XAllocNamedColor(mydisplay,mycolormap,"blue",&mycolor,&dummy); XAllocNamedColor(mydisplay,mycolormap,"white",&mycolor1,&dummy); XAllocNamedColor(mydisplay,mycolormap,"black",&mycolor2,&dummy); XAllocNamedColor(mydisplay,mycolormap,"red",&mycolor3,&dummy); myname="Berek"; XStoreName(mydisplay,mywindow,myname); XMapWindow(mydisplay,mywindow); mygc = DefaultGC(mydisplay,myscreen); while (1) { if(XPending(mydisplay) > 0) { XNextEvent(mydisplay,&myevent); switch (myevent.type) { case Expose: XSetFunction(mydisplay,mygc,GXcopy); pokaz_wszystkich(circles, id); if(circles[id].czy_berek == true) { XSetForeground(mydisplay,mygc,mycolor3.pixel); } else { XSetForeground(mydisplay,mygc,mycolor.pixel); } circles[id].x = 100; circles[id].y = 100; circles[id].size = 60; // pokaz_wszystkich(circles, id); XFillArc(mydisplay, mywindow, mygc, circles[id].x, circles[id].y, circles[id].size, circles[id].size, 0, 360*64); //pokaz_wszystkich(circles, id); //int i; for(i=0; i<6; i++) {printf("%d %d %d\n", circles[i].ID, circles[i].x, circles[i].y); } XFlush(mydisplay); break; case KeyPress: // printf("%x\n", myevent.xkey.keycode); //EXIT XSetForeground(mydisplay, mygc, mycolor1.pixel); XFillRectangle(mydisplay, mywindow, mygc, 0, 0, 600, 600); sprawdz(circles, id); pokaz_wszystkich(circles, id); if(myevent.xkey.keycode == 0x09) { XCloseDisplay(mydisplay); shmdt(adres); shmctl(pamiec, IPC_RMID, NULL); exit(0); } //UP if(myevent.xkey.keycode == 0x62) {//0x62) { sprawdz(circles, id); XSetForeground(mydisplay,mygc,mycolor1.pixel); XFillArc(mydisplay, mywindow, mygc, circles[id].x, circles[id].y, circles[id].size, circles[id].size, 0, 360*64); if(circles[id].czy_berek == true) { XSetForeground(mydisplay,mygc,mycolor3.pixel); } else {XSetForeground(mydisplay,mygc,mycolor.pixel); } circles[id].y -= 5; XFillArc(mydisplay, mywindow, mygc, circles[id].x, circles[id].y, circles[id].size, circles[id].size, 0, 360*64); XFlush(mydisplay); } //RIGHT if(myevent.xkey.keycode == 0x66) {//0x66) { sprawdz(circles, id); XSetForeground(mydisplay,mygc,mycolor1.pixel); XFillArc(mydisplay, mywindow, mygc, circles[id].x, circles[id].y, circles[id].size, circles[id].size, 0, 360*64); if(circles[id].czy_berek == true) { XSetForeground(mydisplay,mygc,mycolor3.pixel); } else {XSetForeground(mydisplay,mygc,mycolor.pixel); } circles[id].x += 5; XFillArc(mydisplay, mywindow, mygc, circles[id].x, circles[id].y, circles[id].size, circles[id].size, 0, 360*64); XFlush(mydisplay); } //LEFT if(myevent.xkey.keycode == 0x64) {//0x64) { sprawdz(circles, id); XSetForeground(mydisplay,mygc,mycolor1.pixel); XFillArc(mydisplay, mywindow, mygc, circles[id].x, circles[id].y, circles[id].size, circles[id].size, 0, 360*64); if(circles[id].czy_berek == true) { XSetForeground(mydisplay,mygc,mycolor3.pixel); } else {XSetForeground(mydisplay,mygc,mycolor.pixel); } circles[id].x -= 5; XFillArc(mydisplay, mywindow, mygc, circles[id].x, circles[id].y, circles[id].size, circles[id].size, 0, 360*64); XFlush(mydisplay); } //DOWN if(myevent.xkey.keycode == 0x68) {//0x68) { sprawdz(circles, id); XSetForeground(mydisplay,mygc,mycolor1.pixel); XFillArc(mydisplay, mywindow, mygc, circles[id].x, circles[id].y, circles[id].size, circles[id].size, 0, 360*64); if(circles[id].czy_berek == true) { XSetForeground(mydisplay,mygc,mycolor3.pixel); } else {XSetForeground(mydisplay,mygc,mycolor.pixel); } circles[id].y += 5; XFillArc(mydisplay, mywindow, mygc, circles[id].x, circles[id].y, circles[id].size, circles[id].size, 0, 360*64); XFlush(mydisplay); } break; } } } }
int main(void) { Display *d; int s; Window w; XEvent ev; int should_quit = 0; int width,height; XFontStruct *font; XCharStruct text_bounds; XGCValues values; unsigned long valuemask; GC gc; char outdata[256] = "Press me!"; int dummy; d = XOpenDisplay(NULL); s = XDefaultScreen(d); w = XCreateSimpleWindow(d, XRootWindow(d, s), 0, 0, width=200, height=200, 0, XBlackPixel(d, s), XWhitePixel(d, s)); font = XLoadQueryFont(d, "variable"); values.foreground = XBlackPixel(d, s); values.font = font->fid; valuemask = 0; valuemask |= GCForeground | GCFont; gc = XCreateGC(d, w, valuemask, &values); XTextExtents(font, outdata, strlen(outdata), &dummy, &dummy, &dummy, &text_bounds); XSelectInput(d, w, ButtonPressMask|ExposureMask|KeyPressMask); XMapWindow(d, w); while(!should_quit) { XNextEvent(d, &ev); switch(ev.type) { case Expose: XDrawString(d, w, gc, (width-text_bounds.width)/2, (height-text_bounds.ascent-text_bounds.descent)/2, outdata, strlen(outdata)); break; case ButtonPress: sprintf(outdata, "That was button %d", ev.xbutton.button); XTextExtents(font, outdata, strlen(outdata), &dummy, &dummy, &dummy, &text_bounds); /* This clears and makes sure we receive a new expose. */ XClearArea(d, w, 0,0,0,0, 1); break; case KeyPress: { KeySym keysym; char buf[32]; int n; n = XLookupString(&ev.xkey, buf, sizeof(buf), &keysym, NULL); if(keysym== XK_Escape) should_quit = 1; else if(n) { int i; for(i=0; i<n; i++) fputc(buf[i], stdout); fflush(stdout); } } break; default: } } return 0; }