예제 #1
0
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);
}
예제 #2
0
파일: xlib-1.c 프로젝트: joeytwiddle/code
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;
}
예제 #3
0
/**
 * gst_v4l2_xoverlay_prepare_xwindow_id:
 * @v4l2object: the v4l2object
 * @required: %TRUE if display is required (ie. TRUE for v4l2sink, but
 *   FALSE for any other element with optional overlay capabilities)
 *
 * Helper function to create a windo if none is set from the application.
 */
void
gst_v4l2_xoverlay_prepare_xwindow_id (GstV4l2Object * v4l2object,
    gboolean required)
{
  if (!GST_V4L2_IS_OVERLAY (v4l2object))
    return;

  gst_x_overlay_prepare_xwindow_id (GST_X_OVERLAY (v4l2object->element));

  if (required && !v4l2object->xwindow_id) {
    GstV4l2Xv *v4l2xv;
    Window win;
    int width, height;
    long event_mask;

    if (!v4l2object->xv && GST_V4L2_IS_OPEN (v4l2object))
      gst_v4l2_xoverlay_open (v4l2object);

    v4l2xv = v4l2object->xv;

    /* if xoverlay is not supported, just bail */
    if (!v4l2xv)
      return;

    /* xoverlay is supported, but we don't have a window.. so create one */
    GST_DEBUG_OBJECT (v4l2object->element, "creating window");

    g_mutex_lock (v4l2xv->mutex);

    width = XDisplayWidth (v4l2xv->dpy, DefaultScreen (v4l2xv->dpy));
    height = XDisplayHeight (v4l2xv->dpy, DefaultScreen (v4l2xv->dpy));
    GST_DEBUG_OBJECT (v4l2object->element, "dpy=%p", v4l2xv->dpy);

    win = XCreateSimpleWindow (v4l2xv->dpy,
        DefaultRootWindow (v4l2xv->dpy),
        0, 0, width, height, 0, 0,
        XBlackPixel (v4l2xv->dpy, DefaultScreen (v4l2xv->dpy)));

    GST_DEBUG_OBJECT (v4l2object->element, "win=%lu", win);

    event_mask = ExposureMask | StructureNotifyMask;
    if (GST_IS_NAVIGATION (v4l2object->element)) {
      event_mask |= PointerMotionMask |
          KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask;
    }
    XSelectInput (v4l2xv->dpy, win, event_mask);
    v4l2xv->event_id = g_timeout_add (45, event_refresh, v4l2object);

    XMapRaised (v4l2xv->dpy, win);

    XSync (v4l2xv->dpy, FALSE);

    g_mutex_unlock (v4l2xv->mutex);

    GST_DEBUG_OBJECT (v4l2object->element, "got window");

    gst_v4l2_xoverlay_set_window_handle (v4l2object, win);
  }
}
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;
}
예제 #5
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
}
예제 #6
0
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;
}
예제 #7
0
파일: display_X11.c 프로젝트: mahkoh/scrot
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);
}
예제 #8
0
/**
 * gst_v4l2_xoverlay_prepare_xwindow_id:
 * @v4l2object: the v4l2object
 * @required: %TRUE if display is required (ie. TRUE for v4l2sink, but
 *   FALSE for any other element with optional overlay capabilities)
 *
 * Helper function to create a windo if none is set from the application.
 */
void
gst_v4l2_xoverlay_prepare_xwindow_id (GstV4l2Object * v4l2object,
    gboolean required)
{
  if (!GST_V4L2_IS_OVERLAY (v4l2object))
    return;

  gst_x_overlay_prepare_xwindow_id (GST_X_OVERLAY (v4l2object->element));

  if (required && !v4l2object->xwindow_id) {
    GstV4l2Xv *v4l2xv;
    Window win;
    int width, height;

    if (!v4l2object->xv && GST_V4L2_IS_OPEN (v4l2object))
      gst_v4l2_xoverlay_open (v4l2object);

    v4l2xv = v4l2object->xv;

    /* if xoverlay is not supported, just bail */
    if (!v4l2xv)
      return;

    /* xoverlay is supported, but we don't have a window.. so create one */
    GST_DEBUG_OBJECT (v4l2object->element, "creating window");

    g_mutex_lock (v4l2xv->mutex);

    width = XDisplayWidth (v4l2xv->dpy, DefaultScreen (v4l2xv->dpy));
    height = XDisplayHeight (v4l2xv->dpy, DefaultScreen (v4l2xv->dpy));
    GST_DEBUG_OBJECT (v4l2object->element, "dpy=%p", v4l2xv->dpy);

    win = XCreateSimpleWindow (v4l2xv->dpy,
        DefaultRootWindow (v4l2xv->dpy),
        0, 0, width, height, 0, 0,
        XBlackPixel (v4l2xv->dpy, DefaultScreen (v4l2xv->dpy)));

    GST_DEBUG_OBJECT (v4l2object->element, "win=%lu", win);

    XMapRaised (v4l2xv->dpy, win);
    XSync (v4l2xv->dpy, FALSE);

    v4l2xv->internal_window = TRUE;

    g_mutex_unlock (v4l2xv->mutex);

    GST_DEBUG_OBJECT (v4l2object->element, "got window");

    gst_v4l2_xoverlay_set_window_handle (v4l2object, win);
  }
}
예제 #9
0
		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);
		}
예제 #10
0
int main(int argc, char *argv[])
{
	Display *dpy;
	if(!(dpy = XOpenDisplay(0x0))) return 1;

	int scr = XDefaultScreen(dpy);
	int display_width = DisplayWidth(dpy, scr);
	GC gc = XDefaultGC(dpy, scr);

	XColor col = color(dpy, "green");
	Window win = XCreateSimpleWindow(dpy,
				XRootWindow(dpy, scr),
				display_width - 320 , 150, 
				300, 100, 
				3,
				col.pixel, XBlackPixel(dpy, scr));

	XStoreName(dpy, win, "clock");
	XSetForeground(dpy, gc, col.pixel);
	XMapWindow(dpy, win);
	
	Atom delete_message = XInternAtom(dpy, "WM_DELETE_WINDOW", True);
	XSetWMProtocols(dpy, win, &delete_message, 1);

	XFontStruct *font = get_font(dpy);
	
	XTextItem item;
	item.delta = 10;
	item.font = font -> fid;
	time_t now;
 
	while (1) {
		time(&now);
		char *msg1 = (char *)ctime(&now);
		XClearArea(dpy, win, 0, 0, 300, 100, False);		
		item.chars = msg1;
		item.nchars = strlen(msg1) - 1;
		XDrawText(dpy, win, gc, 50, 50, &item, 1);
		XFlush(dpy);
		sleep(1);
	}
	XDestroyWindow(dpy, win);
	XCloseDisplay(dpy);
	return 1;
}
예제 #11
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;
}
예제 #12
0
파일: main.c 프로젝트: braneed/scrot
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;
}
예제 #13
0
파일: psdriver.c 프로젝트: PNCG/genesis
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));
        }
    }
}
예제 #14
0
bool MythXDisplay::Open(void)
{
    MythXLocker locker(this);

    QString dispStr = GetMythUI()->GetX11Display();
    const char *dispCStr = NULL;
    if (!dispStr.isEmpty())
        dispCStr = dispStr.toAscii().constData();

    m_disp = XOpenDisplay(dispCStr);
    if (!m_disp)
        return false;

    xdisplays[m_disp] = this;
    m_screen_num = DefaultScreen(m_disp);
    m_screen     = DefaultScreenOfDisplay(m_disp);
    m_black      = XBlackPixel(m_disp, m_screen_num);
    m_depth      = DefaultDepthOfScreen(m_screen);
    m_root       = DefaultRootWindow(m_disp);

    return true;
}
예제 #15
0
/* 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;
    }
예제 #16
0
파일: main.c 프로젝트: braneed/scrot
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;
}
예제 #17
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;
}
예제 #18
0
파일: sflock.c 프로젝트: YmarkusY/sflock
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;
}
/* This function handles a GstVdpWindow creation */
static GstVdpWindow *
gst_vdp_sink_window_new (VdpSink * vdp_sink, gint width, gint height)
{
  GstVdpDevice *device = vdp_sink->device;
  GstVdpWindow *window = NULL;

  Window root;
  gint screen_num;
  gulong black;

  g_return_val_if_fail (GST_IS_VDP_SINK (vdp_sink), NULL);

  window = g_new0 (GstVdpWindow, 1);

  window->width = width;
  window->height = height;
  window->internal = TRUE;

  g_mutex_lock (vdp_sink->x_lock);

  screen_num = DefaultScreen (device->display);
  root = DefaultRootWindow (device->display);
  black = XBlackPixel (device->display, screen_num);

  window->win = XCreateSimpleWindow (vdp_sink->device->display,
      root, 0, 0, window->width, window->height, 0, 0, black);

  /* We have to do that to prevent X from redrawing the background on 
     ConfigureNotify. This takes away flickering of video when resizing. */
  XSetWindowBackgroundPixmap (vdp_sink->device->display, window->win, None);

  /* set application name as a title */
  gst_vdp_sink_window_set_title (vdp_sink, window, NULL);

  if (vdp_sink->handle_events) {
    Atom wm_delete;

    XSelectInput (vdp_sink->device->display, window->win, ExposureMask |
        StructureNotifyMask | PointerMotionMask | KeyPressMask |
        KeyReleaseMask | ButtonPressMask | ButtonReleaseMask);

    /* Tell the window manager we'd like delete client messages instead of
     * being killed */
    wm_delete =
        XInternAtom (vdp_sink->device->display, "WM_DELETE_WINDOW", False);
    (void) XSetWMProtocols (vdp_sink->device->display, window->win, &wm_delete,
        1);
  }

  XMapRaised (vdp_sink->device->display, window->win);

  XSync (vdp_sink->device->display, FALSE);

  g_mutex_unlock (vdp_sink->x_lock);

  gst_vdp_sink_window_decorate (vdp_sink, window);
  gst_vdp_sink_window_setup_vdpau (vdp_sink, window);

  gst_x_overlay_got_window_handle (GST_X_OVERLAY (vdp_sink),
      (guintptr) window->win);

  return window;
}
예제 #20
0
int main() {
	char gameTitle[] = "pong";
	int titleLength = strlen(gameTitle);
	Display *display = XOpenDisplay(NULL);
	if (!display) return 1;
	DisplayInfo(display);
	int screenNumber = DefaultScreen(display);
	unsigned long white = WhitePixel(display, screenNumber);
	unsigned long black = BlackPixel(display, screenNumber);
	Window window = XCreateSimpleWindow(
			display,
			DefaultRootWindow(display),
			0, 0,		// origin
			200, 200,	// size
			0, black,	// border
			white);		// background color
	XStoreName(display, window, gameTitle);
	XFontStruct *fontInfo = XLoadQueryFont(display, "10x20");
	XGCValues values;
	values.font = fontInfo->fid;
	values.foreground = XBlackPixel(display, screenNumber);
	unsigned long valueMask = GCFont+GCForeground;
	GC graphicalContext = XCreateGC(display, window, valueMask, &values);
	XMapWindow(display, window);
	Atom wmDeleteMessage = XInternAtom(display, "WM_DELETE_WINDOW", 0);
	XSetWMProtocols(display, window, &wmDeleteMessage, 1);
	XEvent event;
	int running = 1;
	long eventMask = ExposureMask | StructureNotifyMask | KeyPressMask | KeyReleaseMask;
	XSelectInput(display, window, eventMask);
	while (running) {
		XNextEvent(display, (XEvent *)&event);
		switch (event.type) {
			case Expose: {
			    /* if we have several other expose events waiting, don't redraw. */
			    /* we will do the redrawing when we receive the last of them.    */
			    if (event.xexpose.count > 0) break;
				XWindowAttributes windowAttributes;
				int fontDirection, fontAscent, fontDescent;
				XCharStruct textStructure;
				XTextExtents(
						fontInfo,
						gameTitle,
						titleLength,
						&fontDirection,
						&fontAscent,
						&fontDescent,
						&textStructure);
				XGetWindowAttributes(display, window, &windowAttributes);
				int textX = (windowAttributes.width - textStructure.width) / 2;
				int textY = (windowAttributes.height - (textStructure.ascent + textStructure.descent)) / 2;
				XDrawString(
						display,
						window,
						graphicalContext,
						textX,
						textY,
						gameTitle,
						titleLength);
				DrawElements(display, window, graphicalContext);
			} break;
			case KeyPress: {
		        /* translate the key code to a key symbol. */
		        KeySym keySymbol = XKeycodeToKeysym(display, event.xkey.keycode, 0);
		        switch (keySymbol) {
		        }
			} break;
			case ClientMessage: {
				if (event.xclient.data.l[0] == wmDeleteMessage) {
					running = 0;
				}
			} break;
			default:
				break;
		}
	}
	XDestroyWindow(display, window);
	XCloseDisplay(display);
	return 0;
}
예제 #21
0
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);
}
예제 #22
0
파일: xlib-3.c 프로젝트: joeytwiddle/code
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;
}
예제 #23
0
파일: getrect.c 프로젝트: inbre001/capture
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;
}
예제 #24
0
/* This function handles a GstVdpWindow creation */
static GstVdpWindow *
gst_vdp_sink_window_new (VdpSink * vdp_sink, gint width, gint height)
{
  GstVdpWindow *window = NULL;
  GstVdpDevice *device = vdp_sink->device;

  Window root;
  gint screen_num;
  gulong black;

  VdpStatus status;
  VdpColor color = { 0, };

  g_return_val_if_fail (GST_IS_VDP_SINK (vdp_sink), NULL);

  window = g_new0 (GstVdpWindow, 1);

  window->width = width;
  window->height = height;
  window->internal = TRUE;

  g_mutex_lock (vdp_sink->x_lock);

  screen_num = DefaultScreen (device->display);
  root = DefaultRootWindow (device->display);
  black = XBlackPixel (device->display, screen_num);

  window->win = XCreateSimpleWindow (vdp_sink->device->display,
      root, 0, 0, window->width, window->height, 0, 0, black);

  /* We have to do that to prevent X from redrawing the background on 
     ConfigureNotify. This takes away flickering of video when resizing. */
  XSetWindowBackgroundPixmap (vdp_sink->device->display, window->win, None);

  /* set application name as a title */
  gst_vdp_sink_window_set_title (vdp_sink, window, NULL);

  if (vdp_sink->handle_events) {
    Atom wm_delete;

    XSelectInput (vdp_sink->device->display, window->win, ExposureMask |
        StructureNotifyMask | PointerMotionMask | KeyPressMask |
        KeyReleaseMask | ButtonPressMask | ButtonReleaseMask);

    /* Tell the window manager we'd like delete client messages instead of
     * being killed */
    wm_delete =
        XInternAtom (vdp_sink->device->display, "WM_DELETE_WINDOW", False);
    (void) XSetWMProtocols (vdp_sink->device->display, window->win, &wm_delete,
        1);
  }

  XMapRaised (vdp_sink->device->display, window->win);

  XSync (vdp_sink->device->display, FALSE);

  g_mutex_unlock (vdp_sink->x_lock);

  gst_vdp_sink_window_decorate (vdp_sink, window);

  status = device->vdp_presentation_queue_target_create_x11 (device->device,
      window->win, &window->target);
  if (status != VDP_STATUS_OK) {
    GST_ELEMENT_ERROR (vdp_sink, RESOURCE, READ,
        ("Could not create presentation target"),
        ("Error returned from vdpau was: %s",
            device->vdp_get_error_string (status)));
  }

  status =
      device->vdp_presentation_queue_create (device->device, window->target,
      &window->queue);
  if (status != VDP_STATUS_OK) {
    GST_ELEMENT_ERROR (vdp_sink, RESOURCE, READ,
        ("Could not create presentation queue"),
        ("Error returned from vdpau was: %s",
            device->vdp_get_error_string (status)));
  }

  status =
      device->vdp_presentation_queue_set_background_color (window->queue,
      &color);
  if (status != VDP_STATUS_OK) {
    GST_ELEMENT_ERROR (vdp_sink, RESOURCE, READ,
        ("Could not set background color"),
        ("Error returned from vdpau was: %s",
            device->vdp_get_error_string (status)));
  }

  gst_x_overlay_got_xwindow_id (GST_X_OVERLAY (vdp_sink), window->win);

  return window;
}
예제 #25
0
int main(int argc, char *argv[])
{
	XSetErrorHandler(handler);
	XWindowAttributes attr;

	Display *dpy = XOpenDisplay(NULL);
	if(!(dpy = XOpenDisplay(0x0))) return 1;

	int scr = XDefaultScreen(dpy);
	int display_width = DisplayWidth(dpy, scr);
	int display_height = DisplayHeight(dpy, scr);

	XColor col = color(dpy, "green");
	Window win = XCreateSimpleWindow(dpy,
		XRootWindow(dpy, scr),
		0, 0, display_width + 10, display_height + 10, 2,
		XBlackPixel(dpy, scr), XBlackPixel(dpy, scr));

	XGetWindowAttributes(dpy, win, &attr);
	XStoreName(dpy, win, "xx");
 
	XSelectInput(dpy, win, 
		ExposureMask | KeyPressMask | ButtonPressMask | SubstructureNotifyMask);

	GC gc = XDefaultGC(dpy, scr);
 
	col = color(dpy, "green");
	XSetForeground(dpy, gc, col.pixel);

	col = color(dpy, "black");
	XSetBackground(dpy, gc, col.pixel);

	XFontStruct *font = get_font(dpy);

	XTextItem item;
	item.delta = 10;
	item.font = font -> fid; 
	XMapWindow(dpy, win);
	XEvent ev;
	int pid_about = 0;
	int loop = 1;
	while (loop) {
		XNextEvent(dpy, &ev);
		switch (ev.type)
		{
			case Expose:
			{
				XGetWindowAttributes(dpy, win, &attr);
				draw_text(dpy, gc, win, attr.width, attr.height, font);
				draw_lines(dpy, gc, win, attr.width, attr.height);
				draw_icons(dpy, gc, win, attr.width, 
						load_bitmap(dpy, "icon.bmp"));
				pixmap_ *cen = load_bitmap(dpy, "background.bmp");
				int h = cen -> height;
				int w = cen -> width;
				XCopyPlane(dpy, cen -> px, win, gc, 0, 0, w, h,
								attr.width/2 - w/2, attr.height/2 - h/2, 1);
			}
			break;
 
			case ButtonPress:
			{
				
				if(ev.xbutton.y_root - attr.y > attr.height - 80 &&
				   ev.xbutton.y_root - attr.y < attr.height - 30){
					if(ev.xbutton.x_root - attr.x >  5 * attr.width / 16 &&
				 	   ev.xbutton.x_root - attr.x < 11 * attr.width / 16){
						kill(0, SIGHUP);
						loop = 0;
					}
				}else if(ev.xbutton.y_root - attr.y > attr.height - 40 &&
				   	    ev.xbutton.y_root - attr.y < attr.height - 20){
					if(ev.xbutton.x_root - attr.x > 15 * attr.width / 16 &&
				 	   ev.xbutton.x_root - attr.x < 16 * attr.width / 16){
						if(pid_about == 0){
							pid_about = fork();
							if(!pid_about){
								about();
								exit(0);						
							}
						}else{
							kill(pid_about, SIGKILL);
							pid_about = 0;
						}
					}
				}else if(ev.xbutton.y_root - attr.y < 100){
					XGetWindowAttributes(dpy, win, &attr);
					int index = (ev.xbutton.x_root-attr.x)/
								(attr.width/4);		
					run(get_command(index));		
				}
			}
			break;
		}
	}
	XDestroyWindow(dpy, win);
	XCloseDisplay(dpy);
	return 1;
}
예제 #26
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
}
예제 #27
0
static GstDrawContext *
gst_pvrvideosink_get_dcontext (GstPVRVideoSink * pvrvideosink)
{
  GstDrawContext *dcontext = NULL;
  PVR2DERROR pvr_error;
  gint refresh_rate;
  DRI2WSDisplay *displayImpl;
  WSEGLError glerror;
  const WSEGLCaps *glcaps;

  GST_DEBUG_OBJECT (pvrvideosink, "Getting draw context");

  dcontext = g_new0 (GstDrawContext, 1);
  dcontext->x_lock = g_mutex_new ();

  dcontext->p_blt_info = g_new0 (PVR2D_3DBLT_EXT, 1);
  if (!dcontext->p_blt_info)
    goto p_blt_info_alloc_failed;

  dcontext->p_blt2d_info = g_new0 (PVR2DBLTINFO, 1);

  GST_LOG_OBJECT (pvrvideosink, "Opening X Display");
  dcontext->x_display = XOpenDisplay (NULL);

  if (dcontext->x_display == NULL)
    goto fail_open_display;

  GST_LOG_OBJECT (pvrvideosink, "WSEGL_GetFunctionTablePointer()");
  dcontext->wsegl_table = WSEGL_GetFunctionTablePointer ();

  GST_LOG_OBJECT (pvrvideosink, "pfnWSEGL_IsDisplayValid()");
  glerror = dcontext->wsegl_table->pfnWSEGL_IsDisplayValid (
      (NativeDisplayType) dcontext->x_display);

  if (glerror != WSEGL_SUCCESS)
    goto display_invalid;

  GST_LOG_OBJECT (pvrvideosink, "pfnWSEGL_InitialiseDisplay()");

  glerror = dcontext->wsegl_table->pfnWSEGL_InitialiseDisplay (
      (NativeDisplayType) dcontext->x_display, &dcontext->display_handle,
      &glcaps, &dcontext->glconfig);
  if (glerror != WSEGL_SUCCESS)
    goto display_init_failed;

  displayImpl = (DRI2WSDisplay *) dcontext->display_handle;
  dcontext->pvr_context = displayImpl->hContext;

  GST_LOG_OBJECT (pvrvideosink, "PVR2DGetScreenMode()");

  pvr_error = PVR2DGetScreenMode (dcontext->pvr_context,
      &dcontext->display_format, &dcontext->display_width,
      &dcontext->display_height, &dcontext->stride, &refresh_rate);
  if (pvr_error != PVR2D_OK)
    goto screen_mode_failed;

  GST_DEBUG_OBJECT (pvrvideosink,
      "Got format:%d, width:%d, height:%d, stride:%d, refresh_rate:%d",
      dcontext->display_format, dcontext->display_width,
      dcontext->display_height, dcontext->stride, refresh_rate);

  dcontext->screen_num = DefaultScreen (dcontext->x_display);
  dcontext->black = XBlackPixel (dcontext->x_display, dcontext->screen_num);

  GST_DEBUG_OBJECT (pvrvideosink, "Returning dcontext %p", dcontext);

  return dcontext;

p_blt_info_alloc_failed:
  {
    GST_ERROR_OBJECT (pvrvideosink, "Alloc of bltinfo failed");
    gst_pvrvideosink_dcontext_free (dcontext);
    return NULL;
  }

fail_open_display:
  {
    GST_ERROR_OBJECT (pvrvideosink, "Failed to open X Display");
    gst_pvrvideosink_dcontext_free (dcontext);
    return NULL;
  }

display_invalid:
  {
    GST_ERROR_OBJECT (pvrvideosink, "Display is not valid (glerror:%d)",
        glerror);
    gst_pvrvideosink_dcontext_free (dcontext);
    return NULL;
  }

display_init_failed:
  {
    GST_ERROR_OBJECT (pvrvideosink, "Error initializing display (glerror:%d)",
        glerror);
    gst_pvrvideosink_dcontext_free (dcontext);
    return NULL;
  }

screen_mode_failed:
  {
    GST_ERROR_OBJECT (pvrvideosink, "Failed to get screen mode. error : %s",
        gst_pvr2d_error_get_string (pvr_error));
    gst_pvrvideosink_dcontext_free (dcontext);
    return NULL;
  }
}