Exemple #1
0
void initXWin(int argc, char **argv)
{
	int pos;
	XWMHints wmhints;
	XSizeHints shints;

	winsize=astep ? ASTEPSIZE : NORMSIZE;

	if((d_display=XOpenDisplay(display))==NULL)
	{
		fprintf(stderr,"%s : Unable to open X display '%s'.\n", NAME, XDisplayName(display));
		exit(1);
	}
	_XA_GNUSTEP_WM_FUNC=XInternAtom(d_display, "_GNUSTEP_WM_FUNCTION", 0);
	deleteWin=XInternAtom(d_display, "WM_DELETE_WINDOW", 0);

	w_root=DefaultRootWindow(d_display);

	shints.x=0;
	shints.y=0;
	shints.flags=0;
	pos=(XWMGeometry(d_display, DefaultScreen(d_display), position, NULL, 0, &shints, &shints.x, &shints.y, &shints.width, &shints.height, &shints.win_gravity) & (XValue | YValue));
	shints.min_width=winsize;
	shints.min_height=winsize;
	shints.max_width=winsize;
	shints.max_height=winsize;
	shints.base_width=winsize;
	shints.base_height=winsize;
	shints.flags=PMinSize | PMaxSize | PBaseSize;

	createWin(&w_main, shints.x, shints.y);

	if(wmaker || astep || pos)
		shints.flags |= USPosition;
	if(wmaker)
	{
		wmhints.initial_state=WithdrawnState;
		wmhints.flags=WindowGroupHint | StateHint | IconWindowHint;
		createWin(&w_icon, shints.x, shints.y);
		w_activewin=w_icon;
		wmhints.icon_window=w_icon;
	}
	else
	{
		wmhints.initial_state=NormalState;
		wmhints.flags=WindowGroupHint | StateHint;
		w_activewin=w_main;
	}
	wmhints.window_group=w_main;
	XSetWMHints(d_display, w_main, &wmhints);
	XSetWMNormalHints(d_display, w_main, &shints);
	XSetCommand(d_display, w_main, argv, argc);
	XStoreName(d_display, w_main, NAME);
	XSetIconName(d_display, w_main, NAME);
	XSetWMProtocols(d_display, w_activewin, &deleteWin, 1);
}
Exemple #2
0
/*******************************************************************************\
|* openXwindow																   *|
\*******************************************************************************/
void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bits, int pixmask_width, int pixmask_height) {

	unsigned int	borderwidth = 1;
	XClassHint		classHint;
	char			*display_name = NULL;
	char			*wname = argv[0];
	XTextProperty	name;

	XGCValues		gcv;
	unsigned long	gcm;

	char			*geometry = NULL;

	int				dummy=0;
	int				i;

	for (i=1; argv[i]; i++) {
		if (!strcmp(argv[i], "-display"))
			display_name = argv[++i];
		else if (!strcmp(argv[i], "-geometry"))
			geometry = argv[++i];
	}

	if (!(display = XOpenDisplay(display_name))) {
		fprintf(stderr, "%s: can't open display %s\n",
						wname, XDisplayName(display_name));
		exit(1);
	}
	screen  = DefaultScreen(display);
	Root    = RootWindow(display, screen);
	d_depth = DefaultDepth(display, screen);
	x_fd    = XConnectionNumber(display);

	/* Convert XPM to XImage */
	GetXPM(&wmgen, pixmap_bytes);

	/* Create a window to hold the stuff */
	mysizehints.flags = USSize | USPosition;
	mysizehints.x = 0;
	mysizehints.y = 0;

	back_pix = GetColor("white");
	fore_pix = GetColor("black");

	XWMGeometry(display, screen, geometry, NULL, borderwidth, &mysizehints,
				&mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy);

	mysizehints.width = 64;
	mysizehints.height = 64;

	win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y,
				mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix);

	iconwin = XCreateSimpleWindow(display, win, mysizehints.x, mysizehints.y,
				mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix);

	/* Activate hints */
	XSetWMNormalHints(display, win, &mysizehints);
	classHint.res_name = wname;
	classHint.res_class = wname;
	XSetClassHint(display, win, &classHint);

	XSelectInput(display, win, ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask);
	XSelectInput(display, iconwin, ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask);

	if (XStringListToTextProperty(&wname, 1, &name) == 0) {
		fprintf(stderr, "%s: can't allocate window name\n", wname);
		exit(1);
	}

	XSetWMName(display, win, &name);

	/* Create GC for drawing */

	gcm = GCForeground | GCBackground | GCGraphicsExposures;
	gcv.foreground = fore_pix;
	gcv.background = back_pix;
	gcv.graphics_exposures = 0;
	NormalGC = XCreateGC(display, Root, gcm, &gcv);

	/* ONLYSHAPE ON */

	pixmask = XCreateBitmapFromData(display, win, pixmask_bits, pixmask_width, pixmask_height);

	XShapeCombineMask(display, win, ShapeBounding, 0, 0, pixmask, ShapeSet);
	XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet);

	/* ONLYSHAPE OFF */

	mywmhints.initial_state = WithdrawnState;
	mywmhints.icon_window = iconwin;
	mywmhints.icon_x = mysizehints.x;
	mywmhints.icon_y = mysizehints.y;
	mywmhints.window_group = win;
	mywmhints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint;

	XSetWMHints(display, win, &mywmhints);

	XSetCommand(display, win, argv, argc);
	XMapWindow(display, win);
}
Exemple #3
0
void init_display(  )
{
	XClassHint       classHint;
	XTextProperty    name;
	XGCValues        gcv;
	unsigned long    gcm;
	int              dummy=0;
	char           * progname = PROGNAME;
	
	Pixel            back_pix;
	Pixel            fore_pix;

	display = XOpenDisplay( args_XDisplayName );
	
	if( display == NULL )
	{
		fprintf(stderr, "Can't open display\n" );
		free_and_exit( ERROR );
	}
	
	screen  = DefaultScreen(display);
	Root    = RootWindow(display, screen);
	d_depth = DefaultDepth(display, screen);
	x_fd    = XConnectionNumber(display);

	
	init_image ( );
	
	/* Create a window to hold the stuff */
	mysizehints.flags = USSize | USPosition;
	mysizehints.x = 0;
	mysizehints.y = 0;
	

	back_pix = WhitePixel( display, screen);
	fore_pix = BlackPixel( display, screen);

	XWMGeometry(display, screen, NULL, NULL, 1, &mysizehints, \
	            &mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy);
	
	mysizehints.width = 64;
	mysizehints.height = 64;
		
	win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y, \
	                          mysizehints.width, mysizehints.height, 1, fore_pix, back_pix);
	
	iconwin = XCreateSimpleWindow(display, win, mysizehints.x, mysizehints.y, \
	                              mysizehints.width, mysizehints.height, 1, fore_pix, back_pix);

	/* Activate hints */
	XSetWMNormalHints(display, win, &mysizehints);
	classHint.res_name = progname;
	classHint.res_class = progname;
	XSetClassHint(display, win, &classHint);

	XSelectInput(display, win, ButtonPressMask | ButtonReleaseMask | ExposureMask | StructureNotifyMask );
	XSelectInput(display, iconwin, ButtonPressMask | ButtonReleaseMask | ExposureMask | StructureNotifyMask );

	if (XStringListToTextProperty(&progname, 1, &name) == 0)
		PRINTQ(stderr, "%s: can't allocate window name\n", PROGNAME);
	

	XSetWMName(display, win, &name);
	
	/* Create GC for drawing */
	
	gcm = GCForeground | GCBackground | GCGraphicsExposures;
	gcv.foreground = fore_pix;
	gcv.background = back_pix;
	gcv.graphics_exposures = 0;
	NormalGC = XCreateGC(display, Root, gcm, &gcv);

	/* ONLYSHAPE ON */
	
	pixmask = XCreateBitmapFromData(display, win, wmlaptop_mask_bits, wmlaptop_mask_width, wmlaptop_mask_height);

	XShapeCombineMask(display, win, ShapeBounding, 0, 0, pixmask, ShapeSet);
	XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet);
	
	/* ONLYSHAPE OFF */

	mywmhints.initial_state = WithdrawnState;
	mywmhints.icon_window = iconwin;
	mywmhints.icon_x = mysizehints.x;
	mywmhints.icon_y = mysizehints.y;
	mywmhints.window_group = win;
	mywmhints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint;

	XSetWMHints(display, win, &mywmhints);
	
	XMapWindow(display, win);
	
	
}
Exemple #4
0
value caml_gr_open_graph(value arg)
{
  char display_name[256], geometry_spec[64];
  char * p, * q;
  XSizeHints hints;
  int ret;
  XEvent event;
  int x, y, w, h;
  XWindowAttributes attributes;

  if (caml_gr_initialized) {
    caml_gr_clear_graph();
  } else {

    /* Parse the argument */
    for (p = String_val(arg), q = display_name; *p != 0 && *p != ' '; p++)
      if (q < display_name + sizeof(display_name) - 1) *q++ = *p;
    *q = 0;
    while (*p == ' ') p++;
    for (q = geometry_spec; *p != 0; p++)
      if (q < geometry_spec + sizeof(geometry_spec) - 1) *q++ = *p;
    *q = 0;

    /* Open the display */
    if (caml_gr_display == NULL) {
      caml_gr_display = XOpenDisplay(display_name);
      if (caml_gr_display == NULL)
        caml_gr_fail("Cannot open display %s", XDisplayName(display_name));
      caml_gr_screen = DefaultScreen(caml_gr_display);
      caml_gr_black = BlackPixel(caml_gr_display, caml_gr_screen);
      caml_gr_white = WhitePixel(caml_gr_display, caml_gr_screen);
      caml_gr_background = caml_gr_white;
      caml_gr_colormap = DefaultColormap(caml_gr_display, caml_gr_screen);
    }

    /* Set up the error handlers */
    XSetErrorHandler(caml_gr_error_handler);
    XSetIOErrorHandler(caml_gr_ioerror_handler);

    /* Parse the geometry specification */
    hints.x = 0;
    hints.y = 0;
    hints.width = DEFAULT_SCREEN_WIDTH;
    hints.height = DEFAULT_SCREEN_HEIGHT;
    hints.flags = PPosition | PSize;
    hints.win_gravity = 0;

    ret = XWMGeometry(caml_gr_display, caml_gr_screen, geometry_spec, "", BORDER_WIDTH,
                      &hints, &x, &y, &w, &h, &hints.win_gravity);
    if (ret & (XValue | YValue)) {
      hints.x = x; hints.y = y; hints.flags |= USPosition;
    }
    if (ret & (WidthValue | HeightValue)) {
      hints.width = w; hints.height = h; hints.flags |= USSize;
    }

    /* Initial drawing color is black */
    caml_gr_color = 0; /* CAML COLOR */

    /* Create the on-screen window */
    caml_gr_window.w = hints.width;
    caml_gr_window.h = hints.height;
    caml_gr_window.win =
      XCreateSimpleWindow(caml_gr_display, DefaultRootWindow(caml_gr_display),
                          hints.x, hints.y, hints.width, hints.height,
                          BORDER_WIDTH, caml_gr_black, caml_gr_background);
    p = window_name;
    if (p == NULL) p = DEFAULT_WINDOW_NAME;
    /* What not use XSetWMProperties? */
    XSetStandardProperties(caml_gr_display, caml_gr_window.win, p, p,
                           None, NULL, 0, &hints);
    caml_gr_window.gc = XCreateGC(caml_gr_display, caml_gr_window.win, 0, NULL);
    XSetBackground(caml_gr_display, caml_gr_window.gc, caml_gr_background);
    XSetForeground(caml_gr_display, caml_gr_window.gc, caml_gr_black);

    /* Require exposure, resize and keyboard events */
    caml_gr_selected_events = DEFAULT_SELECTED_EVENTS;
    XSelectInput(caml_gr_display, caml_gr_window.win, caml_gr_selected_events);

    /* Map the window on the screen and wait for the first Expose event */
    XMapWindow(caml_gr_display, caml_gr_window.win);
    do { XNextEvent(caml_gr_display, &event); } while (event.type != Expose);

    /* Get the actual window dimensions */
    XGetWindowAttributes(caml_gr_display, caml_gr_window.win, &attributes);
    caml_gr_window.w = attributes.width;
    caml_gr_window.h = attributes.height;

    /* Create the pixmap used for backing store */
    caml_gr_bstore.w = caml_gr_window.w;
    caml_gr_bstore.h = caml_gr_window.h;
    caml_gr_bstore.win =
      XCreatePixmap(caml_gr_display, caml_gr_window.win, caml_gr_bstore.w, caml_gr_bstore.h,
                    XDefaultDepth(caml_gr_display, caml_gr_screen));
    caml_gr_bstore.gc = XCreateGC(caml_gr_display, caml_gr_bstore.win, 0, NULL);
    XSetBackground(caml_gr_display, caml_gr_bstore.gc, caml_gr_background);

    /* Clear the pixmap */
    XSetForeground(caml_gr_display, caml_gr_bstore.gc, caml_gr_background);
    XFillRectangle(caml_gr_display, caml_gr_bstore.win, caml_gr_bstore.gc,
                   0, 0, caml_gr_bstore.w, caml_gr_bstore.h);
    XSetForeground(caml_gr_display, caml_gr_bstore.gc, caml_gr_black);

    /* Set the display and remember modes on */
    caml_gr_display_modeflag = True ;
    caml_gr_remember_modeflag = True ;

    /* The global data structures are now correctly initialized.
       In particular, caml_gr_sigio_handler can now handle events safely. */
    caml_gr_initialized = True;

    /* If possible, request that system calls be restarted after
       the EVENT_SIGNAL signal. */
#ifdef POSIX_SIGNALS
#ifdef SA_RESTART
    { struct sigaction action;
      sigaction(EVENT_SIGNAL, NULL, &action);
      action.sa_flags |= SA_RESTART;
      sigaction(EVENT_SIGNAL, &action, NULL);
    }
#endif
#endif

#ifdef USE_ASYNC_IO
    /* If BSD-style asynchronous I/O are supported:
       arrange for I/O on the connection to trigger the SIGIO signal */
    ret = fcntl(ConnectionNumber(caml_gr_display), F_GETFL, 0);
    fcntl(ConnectionNumber(caml_gr_display), F_SETFL, ret | FASYNC);
    fcntl(ConnectionNumber(caml_gr_display), F_SETOWN, getpid());
#endif
  }
#ifdef USE_INTERVAL_TIMER
  /* If BSD-style interval timers are provided, use the real-time timer
     to poll events. */
  { struct itimerval it;
    it.it_interval.tv_sec = 0;
    it.it_interval.tv_usec = 250000;
    it.it_value.tv_sec = 0;
    it.it_value.tv_usec = 250000;
    setitimer(ITIMER_REAL, &it, NULL);
  }
#endif
#ifdef USE_ALARM
  /* The poor man's solution: use alarm to poll events. */
  alarm(1);
#endif
  /* Position the current point at origin */
  caml_gr_x = 0;
  caml_gr_y = 0;
  /* Reset the color cache */
  caml_gr_init_color_cache();
  caml_gr_init_direct_rgb_to_pixel();
  return Val_unit;
}
Exemple #5
0
int main(int argc,char *argv[])
{
  int i;
  unsigned int borderwidth ;
  char *display_name = NULL; 
  char *wname = "asclock";
  XGCValues gcv;
  unsigned long gcm;
  XEvent Event;
  XTextProperty name;
  XClassHint classHint;
  Geometry = "";
  
  /* Parse command line options */
  config();
  parseArgs(argc, argv);

  if(analog_visible || hour_visible || min_visible || sec_visible) {
    fprintf(stderr, "%s does not support analog clocks yet.\n", VERSION);
    fprintf(stderr, "You want the asclock-gtk versions\n");
  }

  /* Open the display */
  if (!(dpy = XOpenDisplay(display_name)))  
    { 
      fprintf(stderr,"asclock: can't open display %s\n", 
	      XDisplayName(display_name)); 
      exit (1); 
    } 
  screen= DefaultScreen(dpy);
  Root = RootWindow(dpy, screen);
  d_depth = DefaultDepth(dpy, screen);
  x_fd = XConnectionNumber(dpy);
  
  /* Icon Daten nach XImage konvertieren */
  GetXPM();
  postconfig();

  /* Create a window to hold the banner */
  mysizehints.flags= USSize|USPosition;
  mysizehints.x = 0;
  mysizehints.y = 0;

  back_pix = GetColor("white");
  fore_pix = GetColor("black");

  XWMGeometry(dpy, screen, Geometry, "64x64+0+0", (borderwidth =1), &mysizehints,
	      &mysizehints.x,&mysizehints.y,&mysizehints.width,&mysizehints.height, &i); 

  mysizehints.width = asclock.attributes.width;
  mysizehints.height= asclock.attributes.height;

  win = XCreateSimpleWindow(dpy,Root,mysizehints.x,mysizehints.y,
			    mysizehints.width,mysizehints.height,
			    borderwidth,fore_pix,back_pix);
  iconwin = XCreateSimpleWindow(dpy,win,mysizehints.x,mysizehints.y,
				mysizehints.width,mysizehints.height,
				borderwidth,fore_pix,back_pix);

  wm_delete_window = XInternAtom (dpy, 
                                  "WM_DELETE_WINDOW",
                                  False);
  (void) XSetWMProtocols (dpy, win,
                          &wm_delete_window, 1);


  /* Hints aktivieren */
  XSetWMNormalHints(dpy, win, &mysizehints);
  classHint.res_name =  "asclock";
  classHint.res_class = "ASClock";
  XSetClassHint(dpy, win, &classHint);

  XSelectInput(dpy,win,MW_EVENTS);
  XSelectInput(dpy,iconwin,MW_EVENTS);

  if (XStringListToTextProperty(&wname, 1, &name) ==0) {
    fprintf(stderr, "asclock: can't allocate window name\n");
    exit(-1);
  }
  XSetWMName(dpy, win, &name);
  
  /* Create a GC for drawing */
  gcm = GCForeground|GCBackground|GCGraphicsExposures;
  gcv.foreground = fore_pix;
  gcv.background = back_pix;
  gcv.graphics_exposures = FALSE;
  NormalGC = XCreateGC(dpy, Root, gcm, &gcv);  

  /* if (ONLYSHAPE) { try to make shaped window here */
    XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, asclock.mask, ShapeSet);
    XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, asclock.mask, ShapeSet);
  
  
  mywmhints.initial_state = (itdocks ? WithdrawnState
			     : (ICONIFIED ? IconicState : NormalState));
  mywmhints.icon_window = iconwin;
  mywmhints.icon_x = mysizehints.x;
  mywmhints.icon_y = mysizehints.y;
  mywmhints.flags = StateHint | IconWindowHint | IconPositionHint;
  if (itdocks) {
    mywmhints.window_group = win;
    mywmhints.flags |= WindowGroupHint;
  }
  XSetWMHints(dpy, win, &mywmhints);
    
  if (itdocks)
    XSetCommand(dpy, win, argv, argc);

  XMapWindow(dpy,win);

  InsertTime();
  RedrawWindow(&visible);
  while(1)
    {
      if (actualtime != mytime())
	  {
	  actualtime = mytime();
	  if(actualmin != actualtime / 60)
	    	{
	      		InsertTime();
	      		if (!itblinks) RedrawWindow(&visible);
	    	}
          if( beats_visible )
          {
            int beats = (int) (( ( actualtime + 60*60) % (24*60*60) ) / 86.4);
            swatch_beats(beats);
	    RedrawWindow(&visible);
          }

	  if (led_visible)
	    if( itblinks )
	      {  
		if (actualtime % 2)
		  XCopyArea(dpy, led.pixmap, visible.pixmap, NormalGC,
			    10*led_elem_width, 0,
			    (led_elem_width+1)/2, led_elem_height, 
			    ((showampm!=0) ? led_12h_colon_x : led_24h_colon_x), 
			    ((showampm!=0) ? led_12h_y : led_24h_y));
	    	else
		  /* Sekunden Doppelpunkt aus */
		  XCopyArea(dpy, asclock.pixmap, visible.pixmap, NormalGC,
			    ((showampm!=0) ? led_12h_colon_x : led_24h_colon_x), 
			    ((showampm!=0) ? led_12h_y : led_24h_y),
			    (led_elem_width+1)/2, led_elem_height, 
			    ((showampm!=0) ? led_12h_colon_x : led_24h_colon_x), 
			    ((showampm!=0) ? led_12h_y : led_24h_y));
	  	RedrawWindow(&visible);
	      }
	  }
      
      /* read a packet */
      while (XPending(dpy))
	{
	  XNextEvent(dpy,&Event);
	  switch(Event.type)
	    {
	    case Expose:
	      if(Event.xexpose.count == 0 )
		RedrawWindow(&visible);
	      break;
	    case ButtonPress:
	      system(exec_str);
	      break;
	    case DestroyNotify:
	      /*
		XFreeGC(dpy, NormalGC);
		XDestroyWindow(dpy, win);
		XDestroyWindow(dpy, iconwin);
	      */
	      XCloseDisplay(dpy);
	      exit(0); 
	    case ClientMessage:
	      {
		if( Event.xclient.data.l[0] == wm_delete_window)
		  {
		    XCloseDisplay(dpy);
		    exit(0);
		  }
	      }
	      break;
	    default:
	      break;      
	    }
	}
      XFlush(dpy);
#ifdef SYSV
	poll((struct poll *) 0, (size_t) 0, 50);
#else
	usleep(50000L);			/* 5/100 sec */
#endif
    }
  return 0;
}
Exemple #6
0
static      vmResult
X_video_init(void)
{
	XWMHints   *wm_hints;
	XClassHint *class_hints;
	XTextProperty windowName, iconName;
	XSetWindowAttributes attributes;
	XGCValues   gcv;
	char       *str_type;
	XrmValue    value;
	int         gravity;
	bool		user_geometry;
	int			flags;
	int			i;

	exposed = false;

	dpy_xsize = DisplayWidth(x11_dpy, x11_screen);
	dpy_ysize = DisplayHeight(x11_dpy, x11_screen);

	/* Set up size hints for resizing and -geometry parsing */

	if ((vwin_size_hints = XAllocSizeHints()) == NULL) {
		module_logger(&X_Video, _L|LOG_ERROR | LOG_USER, _("cannot allocate size hints\n"));
		return vmInternalError;
	}

	vwin_size_hints->flags = PMinSize | PMaxSize | PResizeInc | PAspect | PBaseSize;
	vwin_size_hints->base_width = 0;
	vwin_size_hints->base_height = 0;
	vwin_size_hints->min_width = 256;
	vwin_size_hints->min_height = 192;
	vwin_size_hints->max_width = dpy_xsize;
	vwin_size_hints->max_height = dpy_ysize;
	vwin_size_hints->width_inc = 256;
	vwin_size_hints->height_inc = 192;
	vwin_size_hints->min_aspect.x = vwin_size_hints->max_aspect.x = 4;
	vwin_size_hints->min_aspect.y = vwin_size_hints->max_aspect.y = 3;

	/* Read sizes from resource */

	if (!XrmGetResource(xlib_rDB, "v9t9.geometry", "V9t9.Geometry",
						&str_type, &value)) {
		user_geometry = false;
		value.addr = 0L;
	} else {
		user_geometry = true;
	}

	/*	Parse geometry specification  */

	if ((flags = XWMGeometry(x11_dpy, x11_screen,
					(char *) value.addr,
					"1x1",
					1 /* border width */ , vwin_size_hints,
					&vwxoff, &vwyoff, &vwxsz, &vwysz, &gravity))) {

		if (vwxsz >= 256*256 && vwysz >= 192*192) {
			// assume they misunderstood the geometry and scale down
			vwxsz /= 256;
			vwysz /= 192;
		}

		if (user_geometry) {
			/*	Since user-specified, change position  */
	
			if (flags & (XValue | YValue)) {
				vwin_size_hints->flags |= USPosition;
				vwin_size_hints->x = vwxoff;
				vwin_size_hints->y = vwyoff;
			}
//			XSetWMNormalHints(x11_dpy, vwin, vwin_size_hints);
//			XMoveResizeWindow(x11_dpy, vwin, vwxoff, vwyoff, vwxsz, vwysz);
		}
	}

	vwxm = vwxsz / 256;
	vwym = vwysz / 192;

	vwin = XCreateWindow(x11_dpy, DefaultRootWindow(x11_dpy), 
						 vwxoff, vwyoff, 
						 vwxsz, vwysz, 1	/* border width */,
						 DefaultDepth(x11_dpy, x11_screen),
						 InputOutput, CopyFromParent,
						 CWBorderPixel, &attributes);

	if (!vwin) {
		error(_("failed in XCreateWindow\n"));
		return vmNotAvailable;
	}


	/*	Set window and class properties  */

	if ((wm_hints = XAllocWMHints()) == NULL ||
		(class_hints = XAllocClassHint()) == NULL) {
		return vmNotAvailable;
	}

	/* Set up window hints */
	wm_hints->flags |= StateHint | InputHint;
	wm_hints->initial_state = NormalState;
	wm_hints->input = True;		// yes, want kbd input

	/* Set up resource hints */
	class_hints->res_name = "v9t9";
	class_hints->res_class = "V9t9";

	if (XStringListToTextProperty(&v9t9_windowname, 1, &windowName) == 0 ||
		XStringListToTextProperty(&v9t9_iconname, 1, &iconName) == 0) {
		FAIL("XStringListToTextProperty\n");
		return vmNotAvailable;
	}

	XSetWMProperties(x11_dpy, vwin, &windowName, &iconName,
					 v9t9_argv, v9t9_argc, NULL, wm_hints, class_hints);


	/* Select desired input types */

	XSelectInput(x11_dpy, vwin, ExposureMask | KeyPressMask |
				 KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
				 StructureNotifyMask | ColormapChangeMask | EnterWindowMask |
				 LeaveWindowMask);


	vgc = XCreateGC(x11_dpy, vwin, 0, &gcv);
	if (vgc == NULL)
		module_logger(&X_Video, _L|LOG_FATAL, _("Could not create GC for window\n"));

#if USING_XIMAGE
	x_alloc_image();
#endif

	features |= FE_SHOWVIDEO;
	return vmOk;
}
Exemple #7
0
/*******************************************************************************\
|* openXwindow                                                                 *|
\*******************************************************************************/
void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bits, 
		 int pixmask_width, int pixmask_height, int withdrawn) {

	unsigned int	borderwidth = 0;
	XClassHint     	classHint;
	char	       	*display_name = NULL;
	XTextProperty	name;
	XGCValues      	gcv;
	unsigned long	gcm;
	Status			status;
	int				dummy=0, i;
  
	wname = PACKAGE;
	
	for (i=1; argv[i]; i++) {
		if ((!strcmp(argv[i], "-display")) || (!strcmp(argv[i], "-d")))
			display_name = argv[i+1];
	}
  
  if (!(display = XOpenDisplay(display_name))) {
    fprintf(stderr, "%s: can't open display %s\n", 
	    wname, XDisplayName(display_name));
    exit(1);
  }

  if ( !withdrawn )
	borderwidth = 5;

  screen  = DefaultScreen(display);
  Root    = RootWindow(display, screen);
  d_depth = DefaultDepth(display, screen);
  x_fd    = XConnectionNumber(display);
  
  /* Convert XPM to XImage */
  GetXPM(&wmgen, pixmap_bytes);
  
  /* Create a window to hold the stuff */
  mysizehints.flags = USSize | USPosition;
  mysizehints.x = 0;
  mysizehints.y = 0;
  
  back_pix = GetColor("white");
  fore_pix = GetColor("black");
  
  XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints,
	      &mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy);
  
  mysizehints.min_width = 
    mysizehints.max_width =
    mysizehints.width = 64;
  
  mysizehints.min_height =
    mysizehints.max_height =
    mysizehints.height = 64;
  mysizehints.flags |= PMinSize|PMaxSize;
  
  win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y,
			    mysizehints.width, mysizehints.height, borderwidth, 
			    fore_pix, back_pix);
  
  iconwin = XCreateSimpleWindow(display, win, mysizehints.x, mysizehints.y,
				mysizehints.width, mysizehints.height, borderwidth, 
				fore_pix, back_pix);
  
  /* Activate hints */
  XSetWMNormalHints(display, win, &mysizehints);
  XSetWMNormalHints(display, iconwin, &mysizehints); /* new AQ */
  classHint.res_name = wname;
  classHint.res_class = wname;
  XSetClassHint(display, win, &classHint);
  
  XSelectInput(display, win, 
	       ButtonPressMask | ExposureMask | 
	       ButtonReleaseMask | /*PointerMotionMask |*/ StructureNotifyMask);
  XSelectInput(display, iconwin, 
	       ButtonPressMask | ExposureMask | 
	       ButtonReleaseMask | /*PointerMotionMask |*/ StructureNotifyMask);


/*	if (XStringListToTextProperty(&fullname, 1, &name) == 0) { */  
	if (XStringListToTextProperty(&wname, 1, &name) == 0) {
		fprintf(stderr, "%s: can't allocate window name\n", wname);
		exit(1);
	}

	XSetWMName(display, win, &name);
	if ( !withdrawn ) {
		XSetWMIconName(display, win, &name);
		SetWindowName(wname);
	}

  /* Create GC for drawing */
  
  gcm = GCForeground | GCBackground | GCGraphicsExposures;
  gcv.foreground = fore_pix;
  gcv.background = back_pix;
  gcv.graphics_exposures = 0;
  NormalGC = XCreateGC(display, Root, gcm, &gcv);
  
  /* ONLYSHAPE ON */

  if ( withdrawn ) {
    pixmask = XCreateBitmapFromData(display, win, pixmask_bits, 
				    pixmask_width, pixmask_height);
    XShapeCombineMask(display, win, ShapeBounding, 0, 0, pixmask, ShapeSet);
    XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet);
  }
  /* ONLYSHAPE OFF */
  
  mywmhints.initial_state = withdrawn ? WithdrawnState : NormalState;
  mywmhints.icon_window = iconwin;
  mywmhints.flags = StateHint | IconWindowHint;

  if ( withdrawn ) {
    mywmhints.window_group = win;
    mywmhints.flags |= WindowGroupHint | IconPositionHint;
    mywmhints.icon_x = mysizehints.x;
    mywmhints.icon_y = mysizehints.y;
  }
  
  XSetWMHints(display, win, &mywmhints);
  XSetCommand(display, win, argv, argc);
  
  /* Set up the event for quitting the window */
  wm_delete_window = XInternAtom(display, 
				 "WM_DELETE_WINDOW",	/* atom_name */
				 False);		/* only_if_exists */

  wm_protocols = XInternAtom(display,
			     "WM_PROTOCOLS",		/* atom_name */
			     False);			/* only_if_exists */

  status = XSetWMProtocols(display, win, &wm_delete_window, 1);
  status = XSetWMProtocols(display, iconwin, &wm_delete_window,	1);

  XMapWindow(display, win);

}
Exemple #8
0
/*******************************************************************************
 * New window creation and initialization for a Dockable Application
 ******************************************************************************/
void
InitDockAppWindow( int argc, char *argv[], char *pixmap_data[],
		   char *display_arg, char *geometry_arg )
{
  XGCValues  gcv;
  XSizeHints size_hints;
  XWMHints   wm_hints;
  int status;
  int gravity = 0; /* Used to store the gravity value returned by XWMGeometry,
		      but not used. */

  /* Opening a connection to the X server. */
  dockapp.display = XOpenDisplay( display_arg );
  if( dockapp.display == NULL ) {
    fprintf( stderr, "%s: Can't open display: %s\n", PACKAGE,
	     XDisplayName( display_arg ) );
    ErrorLocation( __FILE__, __LINE__ );
    exit( EXIT_FAILURE );
  }

  dockapp.screen   = DefaultScreen( dockapp.display );
  dockapp.root_win = RootWindow( dockapp.display, dockapp.screen );
  dockapp.d_depth  = DefaultDepth( dockapp.display, dockapp.screen );

  /* Create a window to hold the stuff */
  size_hints.flags = USSize | USPosition;
  size_hints.x = 0;
  size_hints.y = 0;

  /* Constructing window's geometry information. */
  /* XWMGeometry() returns an 'int', but Xlib documentation doesn't explain
     it's meaning. */
  XWMGeometry( dockapp.display, dockapp.screen, geometry_arg, NULL, BWIDTH,
	       &size_hints, &size_hints.x, &size_hints.y, &size_hints.width,
	       &size_hints.height, &gravity );

  size_hints.width  = ICON_SIZE;
  size_hints.height = ICON_SIZE;
  dockapp.back_pix = GetColor("white");
  dockapp.fore_pix = GetColor("black");

  dockapp.win = XCreateSimpleWindow( dockapp.display, dockapp.root_win,
				     size_hints.x, size_hints.y,
				     (unsigned int) size_hints.width,
				     (unsigned int) size_hints.height,
				     BWIDTH, dockapp.fore_pix,
				     dockapp.back_pix );

  dockapp.iconwin = XCreateSimpleWindow( dockapp.display, dockapp.win,
					 size_hints.x, size_hints.y,
					 (unsigned int) size_hints.width,
					 (unsigned int) size_hints.height,
					 BWIDTH, dockapp.fore_pix,
					 dockapp.back_pix );

  /* Configuring Client to Window Manager Communications. */

  /* WM_NORMAL_HINTS property: size hints for a window in it's normal state. */
  /* Replaces the size hints for the WM_NORMAL_HINTS property on the specified
     window. */
  XSetWMNormalHints( dockapp.display, dockapp.win, &size_hints );

  /* Setting the WM_CLASS property. */
  {
    char *app_name = argv[0];
    XClassHint wm_class;

    /* The res_name member contains the application name.
       The res_class member contains the application class. */
    /* The name set in this property may differ from the name set as WM_NAME.
       That is, WM_NAME specifies what should be displayed in the title bar and,
       therefore, can contain temporal information (for example, the name of a
       file currently in an editor's buffer). On the other hand, the name
       specified as part of WM_CLASS is the formal name of the application that
       should be used when retrieving the application's resources from the
       resource database. */
    wm_class.res_name = app_name;
    wm_class.res_class = app_name;
    (void) XSetClassHint( dockapp.display, dockapp.win, &wm_class );
  }

  /* Setting the WM_NAME property.
     This specifies what should be displayed in the title bar (usually the
     application name). */
  {
    XTextProperty text_prop;

    char *app_name = argv[0];
    const int string_count = 1;

    status = XStringListToTextProperty( &app_name, string_count, &text_prop );
    if( status == 0 ) {
      fprintf( stderr, "%s: XStringListToTextProperty() failed\n", PACKAGE );
      ErrorLocation( __FILE__, __LINE__ );
      exit( EXIT_FAILURE );
    }

    XSetWMName( dockapp.display, dockapp.win, &text_prop );

    /* Freing the storage for the value field. */
    (void) XFree( text_prop.value );
  }

  /* WM_HINTS --> Additional hints set by the client for use by the Window
     Manager. */
  /* XWMHints wm_hints; */

  /* WithdrawnState, NormalState or IconicState. Must be set to WithdrawnState
     for DockApp. */
  wm_hints.flags = StateHint | IconWindowHint | IconPositionHint |
    WindowGroupHint;
  wm_hints.initial_state = WithdrawnState; /* Withdrawn, Normal */
  wm_hints.icon_window = dockapp.iconwin;
  wm_hints.icon_x = size_hints.x;
  wm_hints.icon_y = size_hints.y;
  wm_hints.window_group = dockapp.win;
  (void) XSetWMHints( dockapp.display, dockapp.win, &wm_hints );

  /* Sets the WM_COMMAND property. This sets the command and arguments used to
     invoke the application. */
  (void) XSetCommand( dockapp.display, dockapp.win, argv, argc );

  /* ... */
  (void) XSelectInput( dockapp.display, dockapp.win,
		       ButtonPressMask | ExposureMask | ButtonReleaseMask |
		       PointerMotionMask | StructureNotifyMask );

  (void) XSelectInput( dockapp.display, dockapp.iconwin,
		       ButtonPressMask | ExposureMask | ButtonReleaseMask |
		       PointerMotionMask | StructureNotifyMask );

  /* Create GC for drawing */
  gcv.foreground = dockapp.fore_pix;
  gcv.background = dockapp.back_pix;
  gcv.graphics_exposures = 0;
  dockapp.NormalGC = XCreateGC( dockapp.display, dockapp.root_win,
				GCForeground | GCBackground |
				GCGraphicsExposures, &gcv );

  /* Convert XPM data to XImage */
  CreateIconFromXpmData( pixmap_data );

  XShapeCombineMask( dockapp.display, dockapp.win, ShapeBounding, 0, 0,
		     dockapp.xpm_icon.shapemask, ShapeSet );

  XShapeCombineMask( dockapp.display, dockapp.iconwin, ShapeBounding, 0, 0,
		     dockapp.xpm_icon.shapemask, ShapeSet );

  /* Making the new window visible. */
  (void) XMapWindow( dockapp.display, dockapp.win );
}
Exemple #9
0
int main(int argc,char *argv[])
{
  int i;
  unsigned int borderwidth ;
  char *display_name = NULL;
  char *wname = "wmload";
  XGCValues gcv;
  unsigned long gcm;
  XEvent Event;
  XTextProperty name;
  XClassHint classHint;
  Pixmap pixmask;
  Atom _XA_WM_DELETE_WINDOW 	= None;
  Geometry = "";
  mywmhints.initial_state = NormalState;

  /* Parse command line options */
  ProgName = argv[0];

  for(i=1;i<argc;i++) {
    char *arg= argv[i];

    if (arg[0] == '-') {
      switch(arg[1]) {
      case 'u':
	if(++i >=argc) usage();
	sscanf(argv[i], "%d", &updatespeed);
	continue;
      case 'e':
	if(++i >=argc) usage();
	strcpy(&Execute[0], argv[i]);
	strcat(&Execute[0], " &");
	continue;
      case 's':
	ONLYSHAPE=1;
	continue;
      case 'p':
	if(++i >=argc) usage();
	Geometry = argv[i];
	continue;
      case 'i':
	mywmhints.initial_state = IconicState;
	continue;
      case 'w':
	mywmhints.initial_state = WithdrawnState;
	continue;
      case 'l':
	if(++i >=argc) usage();
	LedColor = argv[i];
	continue;
      case 'v':
	fprintf(stdout, "\nwmload version: %i.%i.%i\n", major_VER, minor_VER, patch_VER);
	if(argc == 2) exit(0);
	continue;
      default:
	usage();
      }
    }
    else
      {
        fprintf(stderr, "\nInvalid argument: %s\n", arg);
        usage();
      }
  }

  /* Open the display */
  if (!(dpy = XOpenDisplay(display_name)))
    {
      fprintf(stderr,"wmload: can't open display %s\n",
	      XDisplayName(display_name));
      exit (1);
    }

  screen= DefaultScreen(dpy);
  Root = RootWindow(dpy, screen);
  d_depth = DefaultDepth(dpy, screen);
  x_fd = XConnectionNumber(dpy);
  _XA_WM_DELETE_WINDOW = XInternAtom (dpy, "WM_DELETE_WINDOW", False);

  /* Convert XPM Data to XImage */
  GetXPM();

  /* Create a window to hold the banner */
  mysizehints.flags= USSize|USPosition;
  mysizehints.x = 0;
  mysizehints.y = 0;

  back_pix = GetColor("white");
  fore_pix = GetColor("black");

  XWMGeometry(dpy, screen, Geometry, NULL, (borderwidth =1), &mysizehints,
	      &mysizehints.x,&mysizehints.y,&mysizehints.width,&mysizehints.height, &i);

  mysizehints.width = wmload.attributes.width;
  mysizehints.height= wmload.attributes.height;

  win = XCreateSimpleWindow(dpy,Root,mysizehints.x,mysizehints.y,
			    mysizehints.width,mysizehints.height,
			    borderwidth,fore_pix,back_pix);
  iconwin = XCreateSimpleWindow(dpy,win,mysizehints.x,mysizehints.y,
				mysizehints.width,mysizehints.height,
				borderwidth,fore_pix,back_pix);

  /* activate hints */
  XSetWMNormalHints(dpy, win, &mysizehints);
  classHint.res_name =  "wmload";
  classHint.res_class = "WMLoad";
  XSetClassHint(dpy, win, &classHint);

  XSelectInput(dpy,win,MW_EVENTS);
  XSelectInput(dpy,iconwin,MW_EVENTS);
  XSetCommand(dpy,win,argv,argc);

  if (XStringListToTextProperty(&wname, 1, &name) ==0) {
    fprintf(stderr, "wmload: can't allocate window name\n");
    exit(-1);
  }
  XSetWMName(dpy, win, &name);

  /* Create a GC for drawing */
  gcm = GCForeground|GCBackground|GCGraphicsExposures;
  gcv.foreground = fore_pix;
  gcv.background = back_pix;
  gcv.graphics_exposures = FALSE;
  NormalGC = XCreateGC(dpy, Root, gcm, &gcv);

  if (ONLYSHAPE) { /* try to make shaped window here */
    pixmask = XCreateBitmapFromData(dpy, win, (char *)mask2_bits, mask2_width,
				    mask2_height);
    XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, pixmask, ShapeSet);
    XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet);
  }

  mywmhints.icon_window = iconwin;
  mywmhints.icon_x = mysizehints.x;
  mywmhints.icon_y = mysizehints.y;
  mywmhints.window_group = win;
  mywmhints.flags = StateHint | IconWindowHint | IconPositionHint
      | WindowGroupHint;
  XSetWMHints(dpy, win, &mywmhints);
  XSetWMProtocols (dpy, win, &_XA_WM_DELETE_WINDOW, 1);

  XMapWindow(dpy,win);
  InitLoad();
  InsertLoad();
  RedrawWindow(&visible);
  while(1)
    {
      if (actualtime != time(0))
	{
	  actualtime = time(0);

	  if(actualtime % updatespeed == 0)
	    InsertLoad();

	  RedrawWindow(&visible);
	}

      /* read a packet */
      while (XPending(dpy))
	{
	  XNextEvent(dpy,&Event);
	  switch(Event.type)
	    {
	    case Expose:
	      if(Event.xexpose.count == 0 )
		RedrawWindow(&visible);
	      break;
	    case ButtonPress:
	      ExecuteExternal();
	      break;
	    case ClientMessage:
    	      if ((Event.xclient.format != 32) ||
		  ((Atom)Event.xclient.data.l[0] != _XA_WM_DELETE_WINDOW))
		break;
	    case DestroyNotify:
	      XFreeGC(dpy, NormalGC);
	      XDestroyWindow(dpy, iconwin);
              XDestroyWindow(dpy, win);
              XCloseDisplay(dpy);
	      exit(0);
	      break ;
	    default:
	      break;
	    }
	}
      XFlush(dpy);
#ifdef SYSV
      poll((struct poll *) 0, (size_t) 0, 50);
#else
      {
        struct timespec ts;

        ts.tv_sec = 0;
        ts.tv_nsec = 50000000L;        /* 5/100 sec */
        nanosleep(&ts, NULL);
      }
#endif
    }
  return 0;
}
Exemple #10
0
static int
GTK_get_initial_size(void)
{
	int vwxoff, vwyoff, vwxsz, vwysz;

	int dpy_xsize, dpy_ysize;
	XSizeHints *vwin_size_hints; 
	XrmDatabase cmdlineDB = 0;
	char       *str_type;
	XrmValue    value;
	int         gravity;
	bool		user_geometry;
	int			flags;
	int			i;

	/*  Read command-line args */
	XrmParseCommand(&cmdlineDB, xlib_opTable, SIZEOF_OPS, 
					OS_GetFileNamePtr(v9t9_argv[0]), 
					&v9t9_argc, v9t9_argv);

	/*  Get hints for -display parsing */
	x11_dpy = GDK_DISPLAY();
	x11_screen = DefaultScreen(x11_dpy);

	dpy_xsize = DisplayWidth(x11_dpy, x11_screen);
	dpy_ysize = DisplayHeight(x11_dpy, x11_screen);

	if ((vwin_size_hints = XAllocSizeHints()) == NULL) {
		logger(_L|LOG_ERROR | LOG_USER, _("cannot allocate size hints\n"));
		return 0;
	}

	vwin_size_hints->flags = PMinSize | PMaxSize | PResizeInc | PAspect | PBaseSize;
	vwin_size_hints->base_width = 0;
	vwin_size_hints->base_height = 0;
	vwin_size_hints->min_width = 256;
	vwin_size_hints->min_height = 192;
	vwin_size_hints->max_width = dpy_xsize;
	vwin_size_hints->max_height = dpy_ysize;
	vwin_size_hints->width_inc = 256;
	vwin_size_hints->height_inc = 192;
	vwin_size_hints->min_aspect.x = vwin_size_hints->max_aspect.x = 4;
	vwin_size_hints->min_aspect.y = vwin_size_hints->max_aspect.y = 3;

	/* Read sizes from resource */

	xlib_get_resources(OS_GetFileNamePtr(v9t9_argv[0]), cmdlineDB);

	if (!XrmGetResource(xlib_rDB, "v9t9.geometry", "V9t9.Geometry",
						&str_type, &value)) {
		user_geometry = false;
		value.addr = 0L;
	} else {
		user_geometry = true;
	}

	/*	Parse geometry specification  */

	if ((flags = XWMGeometry(x11_dpy, x11_screen,
					(char *) value.addr,
					"1x1",
					1 /* border width */ , vwin_size_hints,
					&vwxoff, &vwyoff, &vwxsz, &vwysz, &gravity))) {

		if (vwxsz >= 256*256 && vwysz >= 192*192) {
			// assume they misunderstood the geometry and scale down
			vwxsz /= 256;
			vwysz /= 192;
		}
	}

	GTK_x_mult = vwxsz / 256;
	GTK_y_mult = vwysz / 192;
	GTK_user_size_configured = 1;
	
	// on_v9t9_draw_area_size_request uses this info
	return 1;
}
Exemple #11
0
int main(int argc,char *argv[])
{
  int screen;
  int d_depth;
  XWMHints mywmhints;
  Pixel back_pix,fore_pix;

  int i;
  unsigned int borderwidth;
  char *wname="wmswallow";

  int remainarg, remainargc;

  XEvent Event;
  XTextProperty name;
  XClassHint classHint;

  remainarg=parseargs(argc, argv); /* remainarg > 0 afterwards */
  remainargc=argc-remainarg;
#ifdef DEBUG
  fprintf(stderr, "remainarg: %d, remainargc: %d, argc: %d\n", remainarg,
	  remainargc,argc);
  fflush(stderr);
#endif

  if (!(dpy = XOpenDisplay(display_name))) {
    fprintf(stderr,"wmswallow: can't open display %s\n",
	    XDisplayName(display_name));
    exit (1);
  }
  screen=DefaultScreen(dpy);
  Root=RootWindow(dpy, screen);

  /* So, now we've got everything we need to get Events from the XServer */
  if (remainargc>1) {
    winid=startandfind(remainargc-1, argv+remainarg+1, argv[remainarg]);
    if (winid==0) {
      perror("wmswallow: startandfind failed");
      /* Real error handling in execstuff()*/
      exit (1);
    }
  }

  d_depth=DefaultDepth(dpy, screen);
  /*   XConnectionNumber(dpy); */ /* useless */
  mysizehints.flags=USSize|USPosition;
  mysizehints.x=0;
  mysizehints.y=0;
  back_pix=GetColor("white");
  fore_pix=GetColor("black");
  XWMGeometry(dpy, screen, geometry, NULL, (borderwidth =1),
	      &mysizehints, &mysizehints.x, &mysizehints.y,
	      &mysizehints.width, &mysizehints.height, &i);
  mysizehints.width=WIDTH;
  mysizehints.height=HEIGHT;
  if (geometry!=NULL) {
#ifdef DEBUG
    fprintf(stderr,"Setting geometry to: %s\n",geometry);
    fflush(stderr);
#endif
    XParseGeometry(geometry, &mysizehints.x, &mysizehints.y,
		   &mysizehints.width, &mysizehints.height);
  }

  win=XCreateSimpleWindow(dpy, Root, mysizehints.x, mysizehints.y,
			  mysizehints.width, mysizehints.height, borderwidth,
			  fore_pix, back_pix);
  iconwin=XCreateSimpleWindow(dpy, win, mysizehints.x, mysizehints.y,
			      mysizehints.width, mysizehints.height, borderwidth,
			      fore_pix, back_pix);
  XSetWMNormalHints(dpy, win, &mysizehints);
  classHint.res_name="wmswallow";
  classHint.res_class="WMswallow";
  XSetClassHint(dpy, win, &classHint);
  XSelectInput(dpy, win, MW_EVENTS);
  XSelectInput(dpy, iconwin, MW_EVENTS);
  if(XStringListToTextProperty(&wname, 1, &name)==0)
    {
      fprintf(stderr, "wmswallow: can't allocate window name\n");
      exit(-1);
    }
  XSetWMName(dpy, win, &name);
  mywmhints.initial_state = WithdrawnState;
  mywmhints.icon_window = iconwin;
  mywmhints.icon_x = mysizehints.x;
  mywmhints.icon_y = mysizehints.y;
  mywmhints.window_group = win;
  mywmhints.flags = StateHint | IconWindowHint |
    IconPositionHint | WindowGroupHint;
  XSetWMHints(dpy, win, &mywmhints);
  XSetCommand(dpy, win, argv, argc);

  if (winid==0) {
    swallowed=findnamedwindow(argv[remainarg]); /* Find which window to
						   swallow*/
#ifdef DEBUG
    fprintf(stderr,"%s has Window-id 0x%lx\n", argv[remainarg], swallowed);
    fflush(stderr);
#endif
  }
  else
    swallowed=winid;


  /* "Swallow" it */
  XReparentWindow(dpy, swallowed, iconwin, 0, 0);
  if (getclick) {
    /* softenwindow (swallowed); */ /* Change some attributes */
    XSelectInput(dpy, swallowed, SW_EVENTS|ButtonPressMask);
  }
  else {
    XSelectInput(dpy, swallowed, SW_EVENTS); /* Workaround for apps like
						perfmeter that don't let us
						get their mouseclicks :-( */
  }
  XSetWindowBorderWidth(dpy, swallowed,0);
  XMoveResizeWindow(dpy, swallowed, 0, 0,
		    mysizehints.width, mysizehints.height);

  /* Now we do some special juju for shaped windows: */

  /* ...tell the window to repaint itself, please! */
  if (shape) {
    sendexpose(swallowed);

    /* ... ok, window should be repainted and a shaped window should have updated
       its mask accordingly! (-: End of shape-juju :-) */

    /* Now steal the shape of the Window we just swallowed! */
    stealshape(swallowed); }
  XMapWindow(dpy,win);
  XMapSubwindows(dpy,win);
  FlushWindow();

  while(1)
    {
      while (XPending(dpy))
	{
	  XNextEvent(dpy,&Event);
	  switch(Event.type)
	    {
	    case ButtonPress:
#ifdef DEBUG
	      fprintf (stderr, "wmswallow: Got ButtonPress Event\n");
	      fflush(stderr);
#endif
	      if (getclick)
		system(execstring);
	      break;
	    case Expose:
	      if(Event.xexpose.count == 0 ) {
#ifdef DEBUG
		fprintf (stderr, "wmswallow: Got Expose Event, count==0\n");
		fflush(stderr);
#endif
		if (shape)
		  stealshape(swallowed); /* Oclock changes its shape! That's why
					    we have to steal it *again* */
		FlushWindow();
	        XMapRaised(dpy,swallowed);
		/* the following Produces "focus-flicker" */
		/* XMapSubwindows(dpy,win); */
		/* XMapWindow(dpy,win); */
	      }
	      break;
	    case EnterNotify:
	      if (focus)
		XSetInputFocus(dpy, swallowed, RevertToPointerRoot,
		CurrentTime);
	      break;
	    case LeaveNotify:
	      if (focus)
		XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot,
		CurrentTime);
	      break;

	    case DestroyNotify:
	      XCloseDisplay(dpy);
	      exit(0);
	    default:
#ifdef DEBUG
	      /* fprintf (stderr, "wmswallow: Got Some Other Event\n");
			      fflush(stderr); */
#endif
	      break;
	    }
	}
      XFlush(dpy);
      usleep(50000L);
    }
  return 1;
}