Example #1
0
void CreateDock(int argc, char *argv[])    /* this part comes from http://www.linuxmag-france.org/ */
{
   Window root;
   XWMHints wmHints;
   XSizeHints sizeHints;
   XClassHint classHint;
   Pixmap pixmask;
   unsigned long p_blanc;
   unsigned long p_noir;
   unsigned int borderWidth = 2;
   char *wname = argv[0] ;

   dpy = XOpenDisplay(NULL) ;

   if(dpy == NULL)
	  {
	     fprintf(stderr, "Can't open display\n") ;
	     exit(1) ;
	  }

   root = RootWindow(dpy,screen);
   p_blanc = WhitePixel(dpy,screen) ;
   p_noir = BlackPixel(dpy,screen) ;
   gc = XDefaultGC(dpy,screen) ;
   XSetForeground(dpy, gc, p_noir);
   XSetBackground(dpy, gc,p_noir);

   sizeHints.x = 0 ;
   sizeHints.y = 0 ;
   sizeHints.width = 64 ;
   sizeHints.height = 64 ;

   win = XCreateSimpleWindow(dpy,root,sizeHints.x,sizeHints.y , sizeHints.width, sizeHints.height, borderWidth, p_noir,p_noir) ;
   iconWin = XCreateSimpleWindow(dpy,root,sizeHints.x,sizeHints.y,sizeHints.width, sizeHints.height, borderWidth, p_noir,p_noir ) ;

   sizeHints.flags = USSize | USPosition ;
   XSetWMNormalHints(dpy,win,&sizeHints) ;
   wmHints.initial_state = WithdrawnState ;
   wmHints.icon_window = iconWin ;
   wmHints.icon_x = sizeHints.x ;
   wmHints.icon_y = sizeHints.y ;
   wmHints.window_group = win ;
   wmHints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint ;
   XSetWMHints(dpy, win, &wmHints) ;
   classHint.res_name = wname ;
   classHint.res_class = wname ;

   XSetClassHint(dpy, win, &classHint) ;
   XSetCommand(dpy,win, argv, argc) ;

   pixmask = XCreateBitmapFromData(dpy,win,fond_bits, fond_width, fond_height) ;
   XShapeCombineMask(dpy,win,ShapeBounding,0,0,pixmask,ShapeSet) ;
   XShapeCombineMask(dpy,iconWin,ShapeBounding, 0, 0, pixmask, ShapeSet) ;
   XpmCreatePixmapFromData(dpy,root,wmAppKill_xpm, &XPM, NULL,NULL) ;

   XSelectInput(dpy,win, ExposureMask | ButtonPressMask) ;
   XSelectInput(dpy,iconWin, ExposureMask | ButtonPressMask) ;

   XMapWindow(dpy,win) ;
}
Example #2
0
static void xsp_flush_frontbuffer(struct pipe_winsys *pws, struct pipe_surface *surface, void *context_private)
{
   struct xsp_pipe_winsys *xsp_winsys;
   struct xsp_context *xsp_context;

   assert(pws);
   assert(surface);
   assert(context_private);

   xsp_winsys = (struct xsp_pipe_winsys*)pws;
   xsp_context = (struct xsp_context*)context_private;
   xsp_winsys->fbimage->width = surface->width;
   xsp_winsys->fbimage->height = surface->height;
   xsp_winsys->fbimage->bytes_per_line = surface->width * (xsp_winsys->fbimage->bits_per_pixel >> 3);
   xsp_winsys->fbimage->data = (char*)((struct xsp_buffer *)softpipe_texture(surface->texture)->buffer)->data + surface->offset;

   XPutImage
   (
      xsp_winsys->display, xsp_context->drawable,
      XDefaultGC(xsp_winsys->display, xsp_winsys->screen),
      xsp_winsys->fbimage, 0, 0, 0, 0,
      surface->width, surface->height
   );
   XFlush(xsp_winsys->display);
}
int main(){
   Display *disp = NULL;
   Window ventana;
   XColor color;
   int t;
   
   disp = XOpenDisplay(NULL);
   ventana = XCreateSimpleWindow (disp, XDefaultRootWindow (disp), 100, 100, 500, 500, 1, 1,BlackPixel (disp, DefaultScreen(disp)));
   XMapWindow (disp, ventana);
   for(t = 0; t < 100; t++){
		
      XSetForeground (disp, XDefaultGC (disp, DefaultScreen(disp)), BlackPixel(disp, 0)^ObtieneColor(disp, "green"));
      XClearWindow(disp, ventana);      
      XDrawLine (disp,ventana,XDefaultGC (disp, DefaultScreen(disp)),t*1+80, t*2+40, t*2+40, t*3+80);
      XDrawLine (disp,ventana,XDefaultGC (disp, DefaultScreen(disp)),t*5+80, t*3+40, t*3+40, t*5+80);
      usleep(41666);  //24 por segundo
   }
   XDestroyWindow( disp, ventana);
   XCloseDisplay(disp);
   
   return(0);
}
Example #4
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;
}
Example #5
0
/* ------------------------------------------------------------------ */ 
int initGraphics() 
{
  theDisplay = XOpenDisplay(XDisplayName(NULL));
  if (theDisplay == NULL) {
    printf("You need to run the program under X-window.\n\n");
    exit(1);
  }
  theScreen  = XDefaultScreen(theDisplay);
  rootW      =  RootWindow(theDisplay, theScreen);
  theGC      = XDefaultGC(theDisplay, theScreen);
  theCmap    = XDefaultColormap(theDisplay, theScreen);
  theVisual  =  DefaultVisual(theDisplay, theScreen);
  theDepth   = XDefaultDepth(theDisplay, theScreen);
  // fprintf(stderr, "Visual %x Depth %d\n",  theVisual, theDepth);

  pScreen    = XDefaultScreenOfDisplay(theDisplay);
  sW         = XWidthOfScreen(pScreen);
  sH         = XHeightOfScreen(pScreen);
  theFont    = XLoadFont(theDisplay, FONT10 );
  XSetFont(theDisplay, theGC, theFont);

  return 0;
}
Example #6
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;
}
void
S9xXVDisplayDriver::update (int width, int height)
{
    int   current_width, current_height, final_pitch;
    uint8 *final_buffer;
    int   dst_x, dst_y, dst_width, dst_height;
    GtkAllocation allocation;

    gtk_widget_get_allocation (drawing_area, &allocation);
    current_width = allocation.width;
    current_height = allocation.height;

    if (width <= 0)
    {
        gdk_window_hide (gdk_window);
        return;
    }

    if (output_window_width  != current_width ||
        output_window_height != current_height)
    {
        resize_window (current_width, current_height);
    }

    if (config->scale_method > 0)
    {
        uint8 *src_buffer = (uint8 *) padded_buffer[0];
        uint8 *dst_buffer = (uint8 *) padded_buffer[1];
        int   src_pitch = image_width * image_bpp;
        int   dst_pitch = scaled_max_width * image_bpp;

        S9xFilter (src_buffer,
                   src_pitch,
                   dst_buffer,
                   dst_pitch,
                   width,
                   height);

        final_buffer = (uint8 *) padded_buffer[1];
        final_pitch = dst_pitch;
    }
    else
    {
        final_buffer = (uint8 *) padded_buffer[0];
        final_pitch = image_width * image_bpp;
    }

    update_image_size (width, height);

    if (format == FOURCC_YUY2)
    {
        S9xConvertYUV (final_buffer,
                       (uint8 *) xv_image->data,
                       final_pitch,
                       2 * xv_image->width,
                       width + (width < xv_image->width ? (width % 2) + 4 : 0),
                       height + (height < xv_image->height ? 4 : 0));
    }
    else
    {
        S9xConvertMask (final_buffer,
                        (uint8 *) xv_image->data,
                        final_pitch,
                        bytes_per_pixel * xv_image->width,
                        width + (width < xv_image->width ? (width % 2) + 4 : 0),
                        height + (height < xv_image->height ? 4 : 0),
                        rshift,
                        gshift,
                        bshift,
                        bpp);
    }

    dst_x = width; dst_y = height;
    dst_width = current_width; dst_height = current_height;
    S9xApplyAspect (dst_x, dst_y, dst_width, dst_height);

    if (last_known_width != dst_width || last_known_height != dst_height)
    {
        last_known_width = dst_width;
        last_known_height = dst_height;
        clear ();
    }

    XvShmPutImage (display,
                   xv_portid,
                   xwindow,
                   XDefaultGC (display, XDefaultScreen (display)),
                   xv_image,
                   0,
                   0,
                   width,
                   height,
                   dst_x,
                   dst_y,
                   dst_width,
                   dst_height,
                   False);

    top_level->set_mouseable_area (dst_x, dst_y, dst_width, dst_height);

    XSync (display, False);

    return;
}
Example #8
0
int mikaGlWindow::eventExpose( )
{
  static XImage *image = NULL;
  static cairo_t 		*cairo = NULL;
  static cairo_surface_t 	*csurface = NULL;
  static cairo_surface_t	*source = NULL;
  
  #ifdef _GLDEBUG
    printf("mikaGlWindow::eventExpose\n");
  #endif
  
  XGrabServer(window->dpy);
  /**
  csurface = cairo_xlib_surface_create(
                              window->dpy,
                              window->id,
                              DefaultVisual(window->dpy,window->screen),
                              mw,
                              mh
                              );
  */
  
  csurface = cairo_image_surface_create_for_data(
                              window->surface,
                              CAIRO_FORMAT_ARGB32,
                              mw,
                              mh,
                              4*mw
      );
  
  source = cairo_image_surface_create_for_data(
                              surface->pixels,
                              CAIRO_FORMAT_ARGB32,
                              mw,
                              mh,
                              4*mw
      );
  printf("\tcheck 01\n");
  
  cairo = cairo_create(csurface);
  cairo_set_source_surface(cairo, source, 0, 0);
  cairo_paint(cairo);
  
  cairo_destroy(cairo);
  cairo_surface_destroy(csurface);
  cairo_surface_destroy(source);
  
  printf("\tcheck 02\n");
  
  XPutImage(
    window->dpy,
    window->id,
    XDefaultGC(
      window->dpy,
      window->screen
      ),
    window->ximage,
    0,0,0,0,
    mw,mh
  );
  
  XUngrabServer(window->dpy);
  XFlush(window->dpy);
  XSync(window->dpy,0);
  
  return 0;
}