コード例 #1
0
ファイル: wmAppKill.c プロジェクト: d-torrance/dockapps
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) ;
}
コード例 #2
0
ファイル: SetHints.c プロジェクト: MttDs/new-rexeno-tindpe
int
XSetStandardProperties (
    	Display *dpy,
    	Window w,		/* window to decorate */
    	_Xconst char *name,	/* name of application */
    	_Xconst char *icon_string,/* name string for icon */
	Pixmap icon_pixmap,	/* pixmap to use as icon, or None */
    	char **argv,		/* command to be used to restart application */
    	int argc,		/* count of arguments */
    	XSizeHints *hints)	/* size hints for window in its normal state */
{
	XWMHints phints;
	phints.flags = 0;

	if (name != NULL) XStoreName (dpy, w, name);

	if (icon_string != NULL) {
	    XChangeProperty (dpy, w, XA_WM_ICON_NAME, XA_STRING, 8,
		PropModeReplace, (unsigned char *)icon_string, safestrlen(icon_string));
		}

	if (icon_pixmap != None) {
		phints.icon_pixmap = icon_pixmap;
		phints.flags |= IconPixmapHint;
		}
	if (argv != NULL) XSetCommand(dpy, w, argv, argc);

	if (hints != NULL) XSetNormalHints(dpy, w, hints);

	if (phints.flags != 0) XSetWMHints(dpy, w, &phints);

	return 1;
}
コード例 #3
0
ファイル: ecore_x_icccm.c プロジェクト: jigpu/efl
/**
 * Sets the WM_COMMAND property for @a win.
 *
 * @param win  The window.
 * @param argc Number of arguments.
 * @param argv Arguments.
 */
EAPI void
ecore_x_icccm_command_set(Ecore_X_Window win,
                          int argc,
                          char **argv)
{
   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   XSetCommand(_ecore_x_disp, win, argv, argc);
   if (_ecore_xlib_sync) ecore_x_sync();
}
コード例 #4
0
ファイル: wind.c プロジェクト: baruch/joes-sandbox
static void sendhints(Window w,struct hints *h)
  {
  if(h->flg&1) XSetWMName(dsp,w,&h->window_name);
  if(h->flg&2) XSetWMIconName(dsp,w,&h->icon_name);
  if(h->flg&4) XSetCommand(dsp,w,h->argv,h->argc);
  if(h->flg&8) XSetClassHint(dsp,w,&h->class_hints);
  if(h->normal_hints.flags) XSetWMNormalHints(dsp,w,&h->normal_hints);  
  if(h->wm_hints.flags) XSetWMHints(dsp,w,&h->wm_hints);
  }
コード例 #5
0
ファイル: wmmixer-alsa.c プロジェクト: bbidulock/dockapps
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);
}
コード例 #6
0
void setWndClass(QWidget *w, const char *name)
{
    Display *dsp = w->x11Display();
    WId win = w->winId();

    XClassHint classhint;
    classhint.res_name  = (char*)"sim";
    classhint.res_class = (char*)name;
    XSetClassHint(dsp, win, &classhint);

    XWMHints *hints;  
    hints = XGetWMHints(dsp, win);  
    hints->window_group = win;  
    hints->flags = WindowGroupHint;  
    XSetWMHints(dsp, win, hints);  
    XFree( hints );

    const char *argv[2];
    argv[0] = name;
    argv[1] = NULL;
    XSetCommand(dsp, win, (char**)argv, 1);
}
コード例 #7
0
ファイル: asclock.c プロジェクト: apritzel/asclock
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;
}
コード例 #8
0
ファイル: wtest.c プロジェクト: crmafra/wmaker
int main(int argc, char **argv)
{
	XClassHint classhint;

	dpy = XOpenDisplay("");
	if (!dpy) {
		puts("could not open display!");
		exit(1);
	}
	delete_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
	miniaturize_win = XInternAtom(dpy, "_GNUSTEP_WM_MINIATURIZE_WINDOW", False);

	leader = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 10, 10, 0, 0, 0);
	/* set class hint */
	classhint.res_name = "test";
	classhint.res_class = "Test";
	XSetClassHint(dpy, leader, &classhint);

	/* set window group leader to self */
	hints = XAllocWMHints();
	hints->window_group = leader;
	hints->flags = WindowGroupHint;
	XSetWMHints(dpy, leader, hints);

	/* create app context */
	app = WMAppCreateWithMain(dpy, DefaultScreen(dpy), leader);
	menu = WMMenuCreate(app, "Test Menu");
	submenu = WMMenuCreate(app, "File");
	WMMenuAddSubmenu(menu, "File", submenu);

	WMMenuAddItem(menu, "Hide", (WMMenuAction) hide, NULL, NULL, NULL);
	WMMenuAddItem(menu, "Quit", (WMMenuAction) quit, NULL, NULL, NULL);
	WMMenuAddItem(submenu, "New", (WMMenuAction) newwin, NULL, NULL, NULL);
	WMMenuAddItem(submenu, "Open", (WMMenuAction) callback, NULL, NULL, NULL);
	WMMenuAddItem(submenu, "Save", (WMMenuAction) callback, NULL, NULL, NULL);
	WMMenuAddItem(submenu, "Save As...", (WMMenuAction) callback, NULL, NULL, NULL);

	WMAppSetMainMenu(app, menu);

	WMRealizeMenus(app);

	/* set command to use to startup this */
	XSetCommand(dpy, leader, argv, argc);

	/* create first window */
	newwin(NULL, 0, 0);

	XFlush(dpy);
	puts("Run xprop on the test window to see the properties defined");
	while (wincount > 0) {
		XEvent ev;
		XNextEvent(dpy, &ev);
		if (ev.type == ClientMessage) {
			if (ev.xclient.data.l[0] == delete_win) {
				XDestroyWindow(dpy, ev.xclient.window);
				wincount--;
			} else if (ev.xclient.data.l[0] == miniaturize_win) {
				puts("You've pushed the maximize window button");
			}
		}
		WMProcessEvent(app, &ev);
	}
	exit(0);
}
コード例 #9
0
ファイル: wmgeneral.c プロジェクト: aquette/wmnut
/*******************************************************************************\
|* 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);

}
コード例 #10
0
ファイル: dockapp.c プロジェクト: bbidulock/dockapps
/*******************************************************************************
 * 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 );
}
コード例 #11
0
ファイル: wmswallow.c プロジェクト: d-torrance/dockapps
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;
}
コード例 #12
0
ファイル: wmgeneral.c プロジェクト: d-torrance/libdockapp
/*******************************************************************************\
|* 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);
}
コード例 #13
0
ファイル: winwidget.c プロジェクト: phrac/feh-browser
void winwidget_create_window(winwidget ret, int w, int h)
{
	XSetWindowAttributes attr;
	XEvent ev;
	XClassHint *xch;
	MWMHints mwmhints;
	Atom prop = None;
	int x = 0;
	int y = 0;
	char *tmpname;

	D(("winwidget_create_window %dx%d\n", w, h));

	if (ret->full_screen) {
		w = scr->width;
		h = scr->height;

#ifdef HAVE_LIBXINERAMA
		if (opt.xinerama && xinerama_screens) {
			w = xinerama_screens[xinerama_screen].width;
			h = xinerama_screens[xinerama_screen].height;
			x = xinerama_screens[xinerama_screen].x_org;
			y = xinerama_screens[xinerama_screen].y_org;
		}
#endif				/* HAVE_LIBXINERAMA */
	} else if (opt.geom_flags) {
		if (opt.geom_flags & WidthValue) {
			w = opt.geom_w;
		}
		if (opt.geom_flags & HeightValue) {
			h = opt.geom_h;
		}
		if (opt.geom_flags & XValue) {
			if (opt.geom_flags & XNegative) {
				x = scr->width - opt.geom_x;
			} else {
				x = opt.geom_x;
			}
		}
		if (opt.geom_flags & YValue) {
			if (opt.geom_flags & YNegative) {
				y = scr->height - opt.geom_y;
			} else {
				y = opt.geom_y;
			}
		}
	} else if (opt.screen_clip) {
		if (w > scr->width)
			w = scr->width;
		if (h > scr->height)
			h = scr->height;

#ifdef HAVE_LIBXINERAMA
		if (opt.xinerama && xinerama_screens) {
			if (w > xinerama_screens[xinerama_screen].width)
				w = xinerama_screens[xinerama_screen].width;
			if (h > xinerama_screens[xinerama_screen].height)
				h = xinerama_screens[xinerama_screen].height;
		}
#endif				/* HAVE_LIBXINERAMA */
	}

	if (opt.paused) {
		printf("name %s\n", ret->name);
		tmpname = estrjoin(" ", ret->name, "[Paused]", NULL);
		free(ret->name);
		ret->name = tmpname;
	}

	ret->x = x;
	ret->y = y;
	ret->w = w;
	ret->h = h;
	ret->visible = False;

	attr.backing_store = NotUseful;
	attr.override_redirect = False;
	attr.colormap = cm;
	attr.border_pixel = 0;
	attr.background_pixel = 0;
	attr.save_under = False;
	attr.event_mask =
	    StructureNotifyMask | ButtonPressMask | ButtonReleaseMask |
	    PointerMotionMask | EnterWindowMask | LeaveWindowMask |
	    KeyPressMask | KeyReleaseMask | ButtonMotionMask | ExposureMask
	    | FocusChangeMask | PropertyChangeMask | VisibilityChangeMask;

	if (opt.borderless || ret->full_screen) {
		prop = XInternAtom(disp, "_MOTIF_WM_HINTS", True);
		if (prop == None) {
			weprintf
			    ("Window Manager does not support MWM hints. "
			     "To get a borderless window I have to bypass your wm.");
			attr.override_redirect = True;
			mwmhints.flags = 0;
		} else {
			mwmhints.flags = MWM_HINTS_DECORATIONS;
			mwmhints.decorations = 0;
		}
	} else
		mwmhints.flags = 0;

	ret->win =
	    XCreateWindow(disp, DefaultRootWindow(disp), x, y, w, h, 0,
			  depth, InputOutput, vis,
			  CWOverrideRedirect | CWSaveUnder | CWBackingStore
			  | CWColormap | CWBackPixel | CWBorderPixel | CWEventMask, &attr);

	if (mwmhints.flags) {
		XChangeProperty(disp, ret->win, prop, prop, 32,
				PropModeReplace, (unsigned char *) &mwmhints, PROP_MWM_HINTS_ELEMENTS);
	}
	if (ret->full_screen) {
		Atom prop_fs = XInternAtom(disp, "_NET_WM_STATE_FULLSCREEN", False);
		Atom prop_state = XInternAtom(disp, "_NET_WM_STATE", False);

		memset(&ev, 0, sizeof(ev));
		ev.xclient.type = ClientMessage;
		ev.xclient.message_type = prop_state;
		ev.xclient.display = disp;
		ev.xclient.window = ret->win;
		ev.xclient.format = 32;
		ev.xclient.data.l[0] = 1;
		ev.xclient.data.l[1] = prop_fs;

		XChangeProperty(disp, ret->win, prop_state, XA_ATOM, 32,
				PropModeReplace, (unsigned char *) &prop_fs, 1);
	}

	XSetWMProtocols(disp, ret->win, &wmDeleteWindow, 1);
	winwidget_update_title(ret);
	xch = XAllocClassHint();
	xch->res_name = "feh";
	xch->res_class = "feh";
	XSetClassHint(disp, ret->win, xch);
	XFree(xch);

	/* Size hints */
	if (ret->full_screen || opt.geom_flags) {
		XSizeHints xsz;

		xsz.flags = USPosition;
		xsz.x = x;
		xsz.y = y;
		XSetWMNormalHints(disp, ret->win, &xsz);
		XMoveWindow(disp, ret->win, x, y);
	}
	if (opt.hide_pointer)
		winwidget_set_pointer(ret, 0);

	/* set the icon name property */
	XSetIconName(disp, ret->win, "feh");
	/* set the command hint */
	XSetCommand(disp, ret->win, cmdargv, cmdargc);

	winwidget_register(ret);
	return;
}
コード例 #14
0
DockWnd::DockWnd(QWidget *main)
        : QWidget(NULL, "dock",  WType_TopLevel | WStyle_Customize | WStyle_NoBorder | WStyle_StaysOnTop)
{
    setMouseTracking(true);
    connect(this, SIGNAL(toggleWin()), main, SLOT(toggleShow()));
    connect(this, SIGNAL(showPopup(QPoint)), main, SLOT(showDockPopup(QPoint)));
    connect(this, SIGNAL(doubleClicked()), main, SLOT(dockDblClicked()));
    connect(pClient, SIGNAL(event(ICQEvent*)), this, SLOT(processEvent(ICQEvent*)));
    connect(pMain, SIGNAL(iconChanged()), this, SLOT(reset()));
    connect(pMain, SIGNAL(msgChanged()), this, SLOT(reset()));
    m_state = 0;
    showIcon = State;
    QTimer *t = new QTimer(this);
    connect(t, SIGNAL(timeout()), this, SLOT(timer()));
    t->start(800);
    bNoToggle = false;
#ifdef WIN32
    QWidget::hide();
    QWidget::setIcon(Pict(pClient->getStatusIcon()));
    gDock = this;
    oldDockProc = (WNDPROC)SetWindowLongW(winId(), GWL_WNDPROC, (LONG)DockWindowProc);
    if (oldDockProc == 0)
        oldDockProc = (WNDPROC)SetWindowLongA(winId(), GWL_WNDPROC, (LONG)DockWindowProc);
    NOTIFYICONDATAA notifyIconData;
    notifyIconData.cbSize = sizeof(notifyIconData);
    notifyIconData.hIcon = topData()->winIcon;
    notifyIconData.hWnd = winId();
    notifyIconData.szTip[0] = 0;
    notifyIconData.uCallbackMessage = WM_DOCK;
    notifyIconData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
    notifyIconData.uID = 0;
    Shell_NotifyIconA(NIM_ADD, &notifyIconData);
#else
    setMinimumSize(22, 22);
    resize(22, 22);
    bInit = false;
    inTray = false;
    inNetTray = false;

    Display *dsp = x11Display();
    WId win = winId();

    if (bEnlightenment){
        wharfIcon = NULL;
        bInit = true;
        resize(48, 48);
        setFocusPolicy(NoFocus);
        move(pMain->getDockX(), pMain->getDockY());
        reset();
        MWMHints mwm;
        mwm.flags = MWM_HINTS_DECORATIONS;
        mwm.functions = 0;
        mwm.decorations = 0;
        mwm.inputMode = 0;
        mwm.status = 0;
        Atom a = XInternAtom(dsp, "_MOTIF_WM_HINTS", False);
        XChangeProperty(dsp, win, a, a, 32, PropModeReplace,
                        (unsigned char *)&mwm, sizeof(MWMHints) / 4);
        XStoreName(dsp, win, "SIM");
        XClassHint *xch = XAllocClassHint();
        xch->res_name  = (char*)"SIM";
        xch->res_class = (char*)"Epplet";
        XSetClassHint(dsp, win, xch);
        XFree(xch);
        XSetIconName(dsp, win, "SIM");
        unsigned long val = (1 << 0) /* | (1 << 9) */ ;
        a = XInternAtom(dsp, "_WIN_STATE", False);
        XChangeProperty(dsp, win, a, XA_CARDINAL, 32, PropModeReplace,
                        (unsigned char *)&val, 1);
        val = 2;
        a = XInternAtom(dsp, "_WIN_LAYER", False);
        XChangeProperty(dsp, win, a, XA_CARDINAL, 32, PropModeReplace,
                        (unsigned char *)&val, 1);
        val = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 5);
        a = XInternAtom(dsp, "_WIN_HINTS", False);
        XChangeProperty(dsp, win, a, XA_CARDINAL, 32, PropModeReplace,
                        (unsigned char *)&val, 1);
        win_name = "SIM";
        win_version = VERSION;
        win_info = "";
        while (!comms_win)
        {
            ECommsSetup(dsp);
            sleep(1);
        }
        char s[256];
        snprintf(s, sizeof(s), "set clientname %s", win_name);
        ECommsSend(s);
        snprintf(s, sizeof(s), "set version %s", win_version);
        ECommsSend(s);
        snprintf(s, sizeof(s), "set info %s", win_info);
        ECommsSend(s);
        ESYNC;

        set_background_properties(this);

        show();
        return;
    }

    wharfIcon = new WharfIcon(this);

    setBackgroundMode(X11ParentRelative);
    const QPixmap &pict = Pict(pClient->getStatusIcon());
    setIcon(pict);

    XClassHint classhint;
    classhint.res_name  = (char*)"sim";
    classhint.res_class = (char*)"Wharf";
    XSetClassHint(dsp, win, &classhint);

    Screen *screen = XDefaultScreenOfDisplay(dsp);
    int screen_id = XScreenNumberOfScreen(screen);
    char buf[32];
    snprintf(buf, sizeof(buf), "_NET_SYSTEM_TRAY_S%d", screen_id);
    Atom selection_atom = XInternAtom(dsp, buf, false);
    XGrabServer(dsp);
    Window manager_window = XGetSelectionOwner(dsp, selection_atom);
    if (manager_window != None)
        XSelectInput(dsp, manager_window, StructureNotifyMask);
    XUngrabServer(dsp);
    XFlush(dsp);
    if (manager_window != None){
        inNetTray = true;
        if (!send_message(dsp, manager_window, SYSTEM_TRAY_REQUEST_DOCK, win, 0, 0)){
            inNetTray = false;
        }
    }

    Atom kde_net_system_tray_window_for_atom = XInternAtom(dsp, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);

    long data[1];
    data[0] = 0;
    XChangeProperty(dsp, win, kde_net_system_tray_window_for_atom, XA_WINDOW,
                    32, PropModeReplace,
                    (unsigned char*)data, 1);

    XWMHints *hints;
    hints = XGetWMHints(dsp, win);
    hints->initial_state = WithdrawnState;
    hints->icon_x = 0;
    hints->icon_y = 0;
    hints->icon_window = wharfIcon->winId();
    hints->window_group = win;
    hints->flags = WindowGroupHint | IconWindowHint | IconPositionHint | StateHint;
    XSetWMHints(dsp, win, hints);
    XFree( hints );
    XSetCommand(dsp, win, _argv, _argc);

    if (!inNetTray){
        move(-21, -21);
        resize(22, 22);
    }
    show();
#endif
    reset();
}
コード例 #15
0
DockWnd::DockWnd(DockPlugin *plugin, const char *icon, const char *text)
        : QWidget(NULL, "dock",  WType_TopLevel | WStyle_Customize | WStyle_NoBorder | WStyle_StaysOnTop),
        EventReceiver(LowPriority)
{
#ifndef WIN32
#if !defined(QT_MACOSX_VERSION) && !defined(QT_MAC)
    wharfIcon = NULL;
#endif
#endif
    m_plugin = plugin;
    setMouseTracking(true);
    bNoToggle = false;
    bBlink = false;
    m_state = icon;
    blinkTimer = new QTimer(this);
    connect(blinkTimer, SIGNAL(timeout()), this, SLOT(blink()));
#ifdef WIN32
    m_bBalloon = false;
    hShell = NULL;
    setIcon(icon);
    QWidget::hide();
    gDock = this;
    WM_DOCK = RegisterWindowMessageA("SIM dock");
    if (IsWindowUnicode(winId())){
        oldDockProc = (WNDPROC)SetWindowLongW(winId(), GWL_WNDPROC, (LONG)DockWindowProc);
/*
        OSVERSIONINFOA osvi;
        osvi.dwOSVersionInfoSize = sizeof(osvi);
        GetVersionExA(&osvi);
        if ((osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) && (osvi.dwMajorVersion > 4))
            m_bBalloon = true;
*/
        __NOTIFYICONDATAW notifyIconData;
        if (m_bBalloon){
            memset(&notifyIconData, 0, sizeof(notifyIconData));
            notifyIconData.cbSize = sizeof(notifyIconData);
            notifyIconData.uVersion = NOTIFYICON_VERSION;
            Shell_NotifyIconW(NIM_SETVERSION, (NOTIFYICONDATAW*)&notifyIconData);
        }
        memset(&notifyIconData, 0, sizeof(notifyIconData));
        notifyIconData.cbSize = sizeof(notifyIconData);
        notifyIconData.hIcon = topData()->winIcon;
        notifyIconData.hWnd = winId();
        notifyIconData.uCallbackMessage = WM_DOCK;
        notifyIconData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
        Shell_NotifyIconW(NIM_ADD, (NOTIFYICONDATAW*)&notifyIconData);
    }else{
        oldDockProc = (WNDPROC)SetWindowLongA(winId(), GWL_WNDPROC, (LONG)DockWindowProc);
        __NOTIFYICONDATAA notifyIconData;
        memset(&notifyIconData, 0, sizeof(notifyIconData));
        notifyIconData.cbSize = sizeof(notifyIconData);
        notifyIconData.hIcon = topData()->winIcon;
        notifyIconData.hWnd = winId();
        notifyIconData.uCallbackMessage = WM_DOCK;
        notifyIconData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
        Shell_NotifyIconA(NIM_ADD, (NOTIFYICONDATAA*)&notifyIconData);
    }
#else
    setMinimumSize(22, 22);
    resize(22, 22);
#if !defined(QT_MACOSX_VERSION) && !defined(QT_MAC)
    bInit = false;
    inTray = false;
    inNetTray = false;

    Display *dsp = x11Display();
    WId win = winId();

    bool bEnlightenment = false;
    QWidget tmp;
    Atom enlightenment_desktop = XInternAtom(dsp, "ENLIGHTENMENT_DESKTOP", false);
    WId w = tmp.winId();
    Window p, r;
    Window *c;
    unsigned int nc;
    while (XQueryTree(dsp, w, &r, &p, &c, &nc)){
        if (c && nc > 0)
            XFree(c);
        if (! p) {
            log(L_WARN, "No parent");
            break;
        }
        unsigned char *data_ret = NULL;
        Atom type_ret;
        int i_unused;
        unsigned long l_unused;
        if ((XGetWindowProperty(dsp, p, enlightenment_desktop, 0, 1, False, XA_CARDINAL,
                                &type_ret, &i_unused, &l_unused, &l_unused,
                                &data_ret) == Success) && (type_ret == XA_CARDINAL)) {
            if (data_ret)
                XFree(data_ret);
            bEnlightenment = true;
            log(L_DEBUG, "Detect Enlightenment");
            break;
        }
        if (p == r) break;
        w = p;
    }

    if (bEnlightenment){
        bInit = true;
        resize(48, 48);
        setFocusPolicy(NoFocus);
        move(m_plugin->getDockX(), m_plugin->getDockY());
        MWMHints mwm;
        mwm.flags = MWM_HINTS_DECORATIONS;
        mwm.functions = 0;
        mwm.decorations = 0;
        mwm.inputMode = 0;
        mwm.status = 0;
        Atom a = XInternAtom(dsp, "_MOTIF_WM_HINTS", False);
        XChangeProperty(dsp, win, a, a, 32, PropModeReplace,
                        (unsigned char *)&mwm, sizeof(MWMHints) / 4);
        XStoreName(dsp, win, "SIM");
        XClassHint *xch = XAllocClassHint();
        xch->res_name  = (char*)"SIM";
        xch->res_class = (char*)"Epplet";
        XSetClassHint(dsp, win, xch);
        XFree(xch);
        XSetIconName(dsp, win, "SIM");
        unsigned long val = (1 << 0) /* | (1 << 9) */ ;
        a = XInternAtom(dsp, "_WIN_STATE", False);
        XChangeProperty(dsp, win, a, XA_CARDINAL, 32, PropModeReplace,
                        (unsigned char *)&val, 1);
        val = 2;
        a = XInternAtom(dsp, "_WIN_LAYER", False);
        XChangeProperty(dsp, win, a, XA_CARDINAL, 32, PropModeReplace,
                        (unsigned char *)&val, 1);
        val = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 5);
        a = XInternAtom(dsp, "_WIN_HINTS", False);
        XChangeProperty(dsp, win, a, XA_CARDINAL, 32, PropModeReplace,
                        (unsigned char *)&val, 1);
        win_name = "SIM";
        win_version = VERSION;
        win_info = "";
        while (!comms_win)
        {
            ECommsSetup(dsp);
            sleep(1);
        }
        char s[256];
        snprintf(s, sizeof(s), "set clientname %s", win_name);
        ECommsSend(s);
        snprintf(s, sizeof(s), "set version %s", win_version);
        ECommsSend(s);
        snprintf(s, sizeof(s), "set info %s", win_info);
        ECommsSend(s);
        ESYNC;

        set_background_properties(this);

        setIcon(icon);
        show();
        return;
    }

    wharfIcon = new WharfIcon(this);
#endif
    setBackgroundMode(X11ParentRelative);
    setIcon(icon);

#if !defined(QT_MACOSX_VERSION) && !defined(QT_MAC)
    XClassHint classhint;
    classhint.res_name  = (char*)"sim";
    classhint.res_class = (char*)"Wharf";
    XSetClassHint(dsp, win, &classhint);

    Screen *screen = XDefaultScreenOfDisplay(dsp);
    int screen_id = XScreenNumberOfScreen(screen);
    char buf[32];
    snprintf(buf, sizeof(buf), "_NET_SYSTEM_TRAY_S%d", screen_id);
    Atom selection_atom = XInternAtom(dsp, buf, false);
    XGrabServer(dsp);
    Window manager_window = XGetSelectionOwner(dsp, selection_atom);
    if (manager_window != None)
        XSelectInput(dsp, manager_window, StructureNotifyMask);
    XUngrabServer(dsp);
    XFlush(dsp);
    if (manager_window != None){
        inNetTray = true;
        if (!send_message(dsp, manager_window, SYSTEM_TRAY_REQUEST_DOCK, win, 0, 0)){
            inNetTray = false;
        }
    }

    Atom kde_net_system_tray_window_for_atom = XInternAtom(dsp, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);

    long data[1];
    data[0] = 0;
    XChangeProperty(dsp, win, kde_net_system_tray_window_for_atom, XA_WINDOW,
                    32, PropModeReplace,
                    (unsigned char*)data, 1);

    XWMHints *hints;
    hints = XGetWMHints(dsp, win);
    hints->initial_state = WithdrawnState;
    hints->icon_x = 0;
    hints->icon_y = 0;
    hints->icon_window = wharfIcon->winId();
    hints->window_group = win;
    hints->flags = WindowGroupHint | IconWindowHint | IconPositionHint | StateHint;
    XSetWMHints(dsp, win, hints);
    XFree( hints );

    Event eArgc(EventArgc);
    int argc = (int)eArgc.process();
    Event eArgv(EventArgv);
    char **argv = (char**)eArgv.process();
    XSetCommand(dsp, win, argv, argc);

    if (!inNetTray){
        move(-21, -21);
        resize(22, 22);
    }
#endif
    show();
#endif
    setTip(text);
    reset();
}
コード例 #16
0
ファイル: dockapp.c プロジェクト: d-torrance/dockapps
void make_window()
{
 Window                rootwindow;
 XpmAttributes         xpmattributes;
 XSetWindowAttributes  windowattributes;
 int                   shapeevent, shapeerror;
 XWMHints             *wmhints;
 XClassHint           *classhint;
 XSizeHints           *sizehints;
 XGCValues             gcvalues;
 unsigned int          depth;
 struct
 {
  long flags;
  long functions;
  long decorations;
  long input_mode;
  long unknown;
 } mwmhints;
 

 display = XOpenDisplay(opt_display);
 if(!display)
 {
  fprintf(stderr, "Could not open display %s\n", opt_display);
  exit(1);
 }
 screen = DefaultScreen(display);
 screenwidth = DisplayWidth(display, screen);
 screenheight = DisplayHeight(display, screen);
 rootwindow = RootWindow(display, screen);
 colormap = DefaultColormap(display, screen);
 depth = DefaultDepth(display, screen);
 xpmattributes.valuemask = XpmColormap | XpmCloseness;
 xpmattributes.colormap = colormap;
 xpmattributes.closeness = 40000;
 XpmCreatePixmapFromData(display, rootwindow, bg_xpm,
                         &background, &backgroundmask, &xpmattributes);
 XpmCreatePixmapFromData(display, rootwindow, on_xpm,
                         &on, None, &xpmattributes);
 XpmCreatePixmapFromData(display, rootwindow, off_xpm,
                         &off, None, &xpmattributes);
 XpmCreatePixmapFromData(display, rootwindow, numbers_xpm,
                         &numbers, None, &xpmattributes);
 buffer = XCreatePixmap(display, rootwindow,
                        WINDOW_WIDTH, WINDOW_HEIGHT, depth);
 windowattributes.background_pixmap = background;
 windowattributes.event_mask = ExposureMask |
                               ButtonPressMask |
			       ButtonReleaseMask |
			       PointerMotionMask |
			       PropertyChangeMask;
 windowattributes.colormap = colormap;
 window = XCreateWindow(display, rootwindow,
                        0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 0,
			CopyFromParent,
			InputOutput,
			CopyFromParent,
			CWBackPixmap | CWEventMask | CWColormap,
			&windowattributes);
 iconwindow = XCreateWindow(display, rootwindow,
                            0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 0,
			    CopyFromParent,
			    InputOutput,
			    CopyFromParent,
			    CWBackPixmap | CWEventMask,
			    &windowattributes);
 fleur = XCreateFontCursor(display, XC_fleur);
 if(XShapeQueryExtension(display, &shapeevent, &shapeerror) && opt_shape)
 {
  XShapeCombineMask(display, window, ShapeBounding,
                    0, 0, backgroundmask, ShapeSet);
  XShapeCombineMask(display, iconwindow, ShapeBounding,
                    0, 0, backgroundmask, ShapeSet);
 }
 else
 {  
  XpmCreatePixmapFromData(display, rootwindow, panel_xpm,
                          &panel, None, &xpmattributes);
  gcvalues.function = GXcopy;
  gcvalues.graphics_exposures = False;
  gcvalues.clip_mask = backgroundmask;
  gcvalues.clip_x_origin = 0;
  gcvalues.clip_y_origin = 0;
  gc = XCreateGC(display, rootwindow,
                 GCFunction |
                 GCGraphicsExposures |
                 GCClipMask |
		 GCClipXOrigin |
		 GCClipYOrigin,
		 &gcvalues);
  XCopyArea(display, background, panel, gc, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0);
  gcvalues.clip_mask = None;
  XChangeGC(display, gc, GCClipMask, &gcvalues);
  XCopyArea(display, panel, background, gc, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0);
  XFreeGC(display, gc);
  XFreePixmap(display, panel);
 }

 mapwindow = opt_window ? iconwindow : window;
 wmhints = XAllocWMHints();
 wmhints -> flags = InputHint | WindowGroupHint | IconWindowHint | StateHint;
 wmhints -> input = True;
 wmhints -> window_group = window;
 wmhints -> icon_window = iconwindow;
 wmhints -> initial_state = WithdrawnState;
 XSetWMHints(display, window, wmhints);
 XFree(wmhints);

 classhint = XAllocClassHint();
 classhint -> res_name = OPT_CLASS_NAME;
 classhint -> res_class = OPT_CLASS_CLASS;
 XSetClassHint(display, mapwindow, classhint);
 XFree(classhint);

 sizehints = XAllocSizeHints();
 sizehints -> flags = USSize | PSize | PMinSize | PMaxSize | PBaseSize;
 sizehints -> width = WINDOW_WIDTH;
 sizehints -> height = WINDOW_HEIGHT;
 sizehints -> min_width = WINDOW_WIDTH;
 sizehints -> min_height = WINDOW_HEIGHT;
 sizehints -> max_width = WINDOW_WIDTH;
 sizehints -> max_height = WINDOW_HEIGHT;
 sizehints -> base_width = WINDOW_WIDTH;
 sizehints -> base_height = WINDOW_HEIGHT;
 XSetWMNormalHints(display, mapwindow, sizehints);
 XFree(sizehints);

 XStoreName(display, window, OPT_WINDOW_NAME);
 XStoreName(display, iconwindow, OPT_WINDOW_NAME); /* For other wms */

 gcvalues.graphics_exposures = False;
 gcvalues.function = GXcopy;
 gc = XCreateGC(display, rootwindow,
                GCGraphicsExposures | GCFunction,
		&gcvalues);
 XCopyArea(display, background, buffer, gc, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0);
 XSetCommand(display, window, argv, argc);
 wm_delete_window = XInternAtom(display, "WM_DELETE_WINDOW", 0);
 XSetWMProtocols(display, mapwindow, &wm_delete_window, 1);
 if(opt_window)
 {
  _motif_wm_hints = XInternAtom(display, "_MOTIF_WM_HINTS", 0);
  mwmhints.flags = 2;
  mwmhints.functions = 0x71; /* WTF IS THIS ? */
  mwmhints.decorations = 0;
  XChangeProperty(display, mapwindow,
                  _motif_wm_hints, _motif_wm_hints,
                  32, PropModeReplace, (unsigned char *)&mwmhints, 5);
 }
 XMapWindow(display, mapwindow);
 signal(SIGINT, handle_signal);
 signal(SIGQUIT, handle_signal);
 signal(SIGTERM, handle_signal);
}
コード例 #17
0
ファイル: dockapp.c プロジェクト: yogsothoth/wmmp
void
dockapp_open_window(char *display_specified, char *appname,
		    unsigned w, unsigned h, int argc, char **argv)
{
    XClassHint	    *classhint;
    XWMHints	    *wmhints;
    Status	    stat;
    XTextProperty   title;
    XSizeHints	    sizehints;
    Window	    root;
    int		    ww, wh;

    /* Open Connection to X Server */
    display = XOpenDisplay(display_specified);
    if (!display) {
	fprintf(stderr, "%s: could not open display %s!\n", argv[0],
		XDisplayName(display_specified));
	exit(1);
    }
    root = DefaultRootWindow(display);

    width = w;
    height = h;

    if (dockapp_iswindowed) {
	offset_w = (WINDOWED_SIZE_W - w) / 2;
	offset_h = (WINDOWED_SIZE_H - h) / 2;
	ww = WINDOWED_SIZE_W;
	wh = WINDOWED_SIZE_H;
    } else {
	offset_w = offset_h = 0;
	ww = w;
	wh = h;
    }

    /* Create Windows */
    icon_window = XCreateSimpleWindow(display, root, 0, 0, ww, wh, 0, 0, 0);
    if (dockapp_isbrokenwm) {
	window = XCreateSimpleWindow(display, root, 0, 0, ww, wh, 0, 0, 0);
    } else {
	window = XCreateSimpleWindow(display, root, 0, 0, 1, 1, 0, 0, 0);
    }

    /* Set ClassHint */
    classhint = XAllocClassHint();
    if (classhint == NULL) {
	fprintf(stderr, "%s: can't allocate memory for wm hints!\n", argv[0]);
	exit(1);
    }
    classhint->res_class = "DockApp";
    classhint->res_name = appname;
    XSetClassHint(display, window, classhint);
    XFree(classhint);

    /* Set WMHints */
    wmhints = XAllocWMHints();
    if (wmhints == NULL) {
	fprintf(stderr, "%s: can't allocate memory for wm hints!\n", argv[0]);
	exit(1);
    }
    wmhints->flags = IconWindowHint | WindowGroupHint;
    if (!dockapp_iswindowed) {
	wmhints->flags |= StateHint;
	wmhints->initial_state = WithdrawnState;
    }
    wmhints->window_group = window;
    wmhints->icon_window = icon_window;
    XSetWMHints(display, window, wmhints);
    XFree(wmhints);

    /* Set WM Protocols */
    delete_win = XInternAtom(display, "WM_DELETE_WINDOW", False);
    XSetWMProtocols (display, icon_window, &delete_win, 1);

    /* Set Size Hints */
    sizehints.flags = USSize;
    if (!dockapp_iswindowed) {
	sizehints.flags |= USPosition;
	sizehints.x = sizehints.y = 0;
    } else {
	sizehints.flags |= PMinSize | PMaxSize;
	sizehints.min_width = sizehints.max_width = WINDOWED_SIZE_W;
	sizehints.min_height = sizehints.max_height = WINDOWED_SIZE_H;
    }
    sizehints.width = ww;
    sizehints.height = wh;
    XSetWMNormalHints(display, icon_window, &sizehints);

    /* Set WindowTitle for AfterStep Wharf */
    stat = XStringListToTextProperty(&appname, 1, &title);
    if(stat == 0) {
      // Not enough memory
      fprintf(stderr, "%s: can't allocate memory for the window title!\n", argv[0]);
      exit(1);
    }
    XSetWMName(display, window, &title);
    XSetWMName(display, icon_window, &title);

    /* Set Command to start the app so it can be docked properly */
    XSetCommand(display, window, argv, argc);

    depth = DefaultDepth(display, DefaultScreen(display));
    gc = DefaultGC(display, DefaultScreen(display));

    XFlush(display);
}
コード例 #18
0
ファイル: newcrt.c プロジェクト: oslcixug/metapackages.soxug
static void WindowInitialize()
{
  Window root;
  XEvent event;
  int screennum;
  Cursor newcursor;

  screennum = DefaultScreen(m_display);
  root = DefaultRootWindow(m_display);
  
  if (BlackAndWhite) {
    WinAttr.background_pixel = BlackPixel(m_display, DefaultScreen(m_display));
    WinAttr.border_pixel = WhitePixel(m_display, DefaultScreen(m_display));
  } else {
    WinAttr.background_pixel = m_colors[0][m_black].pixel;
    WinAttr.border_pixel = m_colors[0][m_black].pixel;
  }
#if 0   /* simple cleanup ***mdg*** */
  WinAttr.background_pixel = m_colors[0][m_black].pixel;
  WinAttr.border_pixel = m_colors[m_black]->pixel;
#endif
  WinAttr.event_mask = WindowEventMask;
  WinAttr.cursor = XCreateFontCursor(m_display, XC_tcross);
  XRecolorCursor(m_display, WinAttr.cursor, &m_colors[0][15], 
		                            &m_colors[0][m_black]);
  WinSizeHints.max_width = XDisplayWidth(m_display, screennum);
  WinSizeHints.max_height = XDisplayHeight(m_display, screennum);

  /* This next section allows entries in .Xdefaults to set initial
     size and position of the newcrt window. 
     Jim Clark 7/13/92 */

  usrgeo = XGetDefault (m_display, "newcrt", "geometry");
   
  if (usrgeo == NULL)
    WinSizeHints.flags |= PPosition;
  else
    WinSizeHints.flags |= USPosition;

  x_pad = 0;
  y_pad = 0;


  XGeometry(m_display,screennum, usrgeo, defgeo, WinBorder, nc_fontwidth,
	    nc_fontheight, x_pad, y_pad, &jc_winX, &jc_winY,
	    &jc_winW, &jc_winH);

  nc_window = XCreateWindow(m_display, root, jc_winX, jc_winY,
			    jc_winW, jc_winH, WinBorder,
			    CopyFromParent, InputOutput, 
			    DefaultVisual(m_display, screennum),
			    WinAttrMask, &WinAttr);
 
  /* End of revised section. */

  XStoreName(m_display, nc_window, "newcrt");
  XSetIconName(m_display, nc_window, "newcrt");
  XSetCommand(m_display, nc_window, &progname, 1);
  XSetWMHints(m_display, nc_window, &WinWMHints);
  XSetNormalHints(m_display, nc_window, &WinSizeHints);

  XMapWindow(m_display, nc_window);

/*  nc_gc = XCreateGC(m_display, nc_window, 0, NULL);  */

  XWindowEvent(m_display, nc_window, ExposureMask, &event);
}
コード例 #19
0
/* ARGSUSED */
void 
SaveSessionCB(
        Widget w,			/* widget id */
        caddr_t client_data,		/* data from application  */
        caddr_t call_data )		/* data from widget class */
{
    char *longpath, *fileName;
    int fd, numPadsToSave;
    char *xa_CommandStr[10];
    char *tmpStr, bufr[1024];
    Editor *pPad;
    int i;

    /* Xt may not pass a widget as advertised (??? is this needed? - hp) */
    if(!XtIsShell(w))
	w = XtParent(w);

    for(pPad = pPadList, numPadsToSave = 0; pPad != (Editor *)NULL; 
	pPad = pPad->pNextPad)
    {
	if(pPad->inUse == True)
	    numPadsToSave++;
    }
    if(numPadsToSave < 1)
    {
        xa_CommandStr[0] = (char *)NULL;
        XSetCommand(XtDisplay(w), XtWindow(w), xa_CommandStr, 1);
	return;
    }

    DtSessionSavePath(w, &longpath, &fileName);

    /*  Create the session file  */
    if ((fd = creat (longpath, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP)) == -1)
    {
        tmpStr = (char *)malloc(strlen(MSG2) + strlen(longpath)+ 1);
        sprintf(tmpStr, MSG2, longpath);
        _DtSimpleErrnoError(pPad->progname, DtError, MSG1, tmpStr, NULL);
        free(tmpStr);
        XtFree ((char *)longpath);
        return;
    }

    sprintf(bufr, "*pads.numActivePads: %d\n", numPadsToSave);
    write (fd, bufr, strlen(bufr));

    for(pPad = pPadList, i = 0; pPad != (Editor *)NULL; 
	pPad = pPad->pNextPad, i++)
    {
	if(pPad->inUse == True)
	    SaveMain(pPad, i, fd);
    }

    close(fd);

    i = 0;
    xa_CommandStr[i] = pPadList->progname; i++;
    xa_CommandStr[i] =  "-session"; i++;
    xa_CommandStr[i] =  fileName; i++;

    XSetCommand(XtDisplay(topLevelWithWmCommand), 
		XtWindow(topLevelWithWmCommand), xa_CommandStr, i);

    XtFree ((char *)fileName);
}
コード例 #20
0
int main(int argc, char **argv)
{
    XClassHint classhint;

    dpy = XOpenDisplay("");
    if (!dpy) {
        puts("could not open display!");
        exit(1);
    }
    delete_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False);

    leader = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 10, 10,
                                 0, 0, 0);
    /* set class hint */
    classhint.res_name = "notest";
    classhint.res_class = "Notest";
    XSetClassHint(dpy, leader, &classhint);

    /* set window group leader to self */
    hints = XAllocWMHints();
    hints->window_group = leader;
    hints->flags = WindowGroupHint;
    XSetWMHints(dpy, leader, hints);

    /* create app context */
    app = WMAppCreateWithMain(dpy, DefaultScreen(dpy), leader);
    menu = WMMenuCreate(app, "Notify Test Menu");
    WMMenuAddItem(menu, "Hide", (WMMenuAction)hide, NULL, NULL, NULL);
    WMMenuAddItem(menu, "Quit", (WMMenuAction)quit, NULL, NULL, NULL);

    WMAppSetMainMenu(app, menu);
    WMRealizeMenus(app);

    /* Get some WindowMaker notifications */
    WMNotifySet( app, WMN_APP_START, notify_print, (void *) "App start" );
    WMNotifySet( app, WMN_APP_EXIT,  notify_print, (void *) "App end" );
    WMNotifySet( app, WMN_WIN_FOCUS,  notify_print, (void *) "Focus in" );
    WMNotifySet( app, WMN_WIN_UNFOCUS,  notify_print, (void *) "Focus out" );
    WMNotifySet( app, WMN_NOTIFY_ALL,  notify_print, (void *) "Unknown type" );
    WMNotifyMaskUpdate( app );	/* Mask isn't actually set till we do this */

    /* set command to use to startup this */
    XSetCommand(dpy, leader, argv, argc);

    /* create first window */
    newwin(NULL, 0, 0);


    XFlush(dpy);
    while( 1 ) {
        XEvent ev;
        XNextEvent(dpy, &ev);
        if (ev.type==ClientMessage) {
            if (ev.xclient.data.l[0]==delete_win) {
                XDestroyWindow(dpy,ev.xclient.window);
                break;
            }
        }
        WMProcessEvent(app, &ev);
    }
    exit(0);
}
コード例 #21
0
ファイル: buttons.c プロジェクト: LambdaCalculus379/SLS-1.02
void
MakeTopBox()
{
  Widget form, command, label; /* widgets. */
  Arg arglist[TOPARGS];		/* An argument list */
  Cardinal num_args = 0;	/* The number of arguments. */
  ManpageGlobals * man_globals;
  static char * full_size[] = {
    "topLabel", MANPAGE_BUTTON, NULL
  };
  static char * half_size[] = {
    HELP_BUTTON, QUIT_BUTTON, NULL
  };
  
/* create the top icon. */

  num_args = 0;
  XtSetArg(arglist[num_args], XtNiconPixmap,
	   XCreateBitmapFromData( XtDisplay(initial_widget), 
				 XtScreen(initial_widget)->root,
				 (char *)iconclosed_bits, iconclosed_width,
				 iconclosed_height));
  num_args++;
  XtSetArg(arglist[num_args], XtNtitle, resources.title);
  num_args++;
  XtSetArg(arglist[num_args], XtNiconic, resources.iconic);
  num_args++;
  top = XtCreatePopupShell(TOPBOXNAME, topLevelShellWidgetClass, 
			   initial_widget, arglist, num_args);

  form = XtCreateManagedWidget("form", formWidgetClass, top, 
			       NULL, (Cardinal) 0);

  label = XtCreateManagedWidget("topLabel", labelWidgetClass, form, 
			       NULL, (Cardinal) 0);

  num_args = 0;
  XtSetArg(arglist[num_args], XtNfromVert, label); num_args++;
  command = XtCreateManagedWidget(HELP_BUTTON, commandWidgetClass, form, 
				  arglist, num_args);

  /* use same vertical as help widget. */
  XtSetArg(arglist[num_args], XtNfromHoriz, command); num_args++;
  command = XtCreateManagedWidget(QUIT_BUTTON, commandWidgetClass, form, 
				  arglist, num_args);

  num_args = 0;
  XtSetArg(arglist[num_args], XtNfromVert, command); num_args++;
  command = XtCreateManagedWidget(MANPAGE_BUTTON, commandWidgetClass, form, 
				  arglist, num_args);

  help_widget = NULL;		/* We have not seen the help yet. */

  FormUpWidgets(form, full_size, half_size);

  XtRealizeWidget(top);
				/* add WM_COMMAND property */
  XSetCommand(XtDisplay(top), XtWindow(top), saved_argv, saved_argc);

  man_globals = (ManpageGlobals*) XtMalloc( (Cardinal) sizeof(ManpageGlobals));
  man_globals->label = NULL;
  man_globals->manpagewidgets.directory = NULL;
  man_globals->manpagewidgets.manpage = NULL;
  man_globals->manpagewidgets.box = NULL;
  man_globals->current_directory = 0;
  MakeSearchWidget(man_globals, top);
  MakeSaveWidgets(man_globals, top);

  SaveGlobals( (man_globals->This_Manpage = top), man_globals);
  XtMapWidget(top);
  AddCursor(top, resources.cursors.top);

/*
 * Set up ICCCM delete window.
 */
  wm_delete_window = XInternAtom(XtDisplay(top), "WM_DELETE_WINDOW",
				 False);
  XtOverrideTranslations
      (top, XtParseTranslationTable ("<Message>WM_PROTOCOLS: Quit()"));
  (void) XSetWMProtocols (XtDisplay(top), XtWindow(top),
			  &wm_delete_window, 1);
  

}
コード例 #22
0
ファイル: wmload.c プロジェクト: bbidulock/dockapps
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;
}
コード例 #23
0
QApplication* MDeclarativeCachePrivate::qApplication(int &argc, char **argv)
{
    if (qApplicationInstance == 0) 
    {
        qApplicationInstance = new QApplication(argc, argv);
    } 
    else 
    {
        if (argc > ARGV_LIMIT) 
        {
            qWarning("MDeclarativeCache: QCoreApplication::arguments() will not contain all arguments.");
        }
        
        // Copy arguments to QCoreApplication 
        for (int i = 0; i < qMin(argc, ARGV_LIMIT); i++) 
        {
            qApp->argv()[i] = argv[i];
        }
        
        // This changes argc in QCoreApplication
        initialArgc = qMin(argc, ARGV_LIMIT);

        // Take application name from argv
        QString appName = QFileInfo(argv[0]).fileName();

        // Set object name
        qApp->setObjectName(appName);

        bool loadTestabilityArg = false;
        const char* testabilityArg = "-testability";
        for (int i = 0; i < argc; i++) 
        {
            if (strcmp(argv[i], testabilityArg) == 0)
            {
                loadTestabilityArg = true;
                break;
            }
        }
        
        bool loadTestabilityEnv = !qgetenv("QT_LOAD_TESTABILITY").isNull();
        if (loadTestabilityEnv || loadTestabilityArg)
            testabilityInit();

#ifdef Q_WS_X11
        // Currently QDeclarativeView is "Alien" widget and doesn't have it's XWindow. The procedure below is not needed.
        // Call to winId() converts the widget to "Native" and makes it slow.
        // If things get changed to use the procedure need to define QDV_USE_NATIVE_WIDGETS
        // In this case it should be considered to add XErrorHandler around XSetCommand and XSetClassHint
        // because those can generate BadAlloc and BadWindow errors.
#ifdef QDV_USE_NATIVE_WIDGETS
        // reinit WM_COMMAND X11 property
        if (qDeclarativeViewInstance) 
        {
            Display *display = QX11Info::display();
            if (display) 
            {
                qDeclarativeViewInstance->winId();
                XSetCommand(display, qDeclarativeViewInstance->effectiveWinId(), argv, argc);

                // set correct WM_CLASS properties
                QString appClass = appName.left(1).toUpper();
                if (appName.length() > 1)
                    appClass += appName.right(appName.length() - 1);

                // reserve memory for C strings
                QByteArray arrName(appName.toLatin1());
                QByteArray arrClass(appClass.toLatin1());

                XClassHint class_hint;
                class_hint.res_name = arrName.data();
                class_hint.res_class = arrClass.data();

                XSetClassHint(display, qDeclarativeViewInstance->effectiveWinId(), &class_hint);
            }
        }
#endif
#endif
        if (cachePopulated) 
        {
            // In Qt 4.7, QCoreApplication::applicationDirPath() and
            // QCoreApplication::applicationFilePath() look up the paths in /proc,
            // which does not work when the booster is used. As a workaround, we
            // use argv[0] to provide the correct values in the cache class.
            appFilePath = QString(argv[0]);
            appDirPath = QString(argv[0]);
            appDirPath.chop(appDirPath.size() - appDirPath.lastIndexOf("/"));
        }

    }

#ifdef HAVE_PATH_REINIT
    // Set the magic attribute so that paths are reinitialized
    qApplicationInstance->setAttribute(Qt::AA_LinuxReinitPathsFromArgv0, true);
#endif

    return qApplicationInstance;
}
コード例 #24
0
DockWnd::DockWnd(QWidget *main)
        : QWidget(NULL)
{
#ifndef WIN32
    wharfIcon = NULL;
#endif
    connect(this, SIGNAL(toggleWin()), main, SLOT(toggleShow()));
    connect(this, SIGNAL(showPopup(QPoint)), main, SLOT(showPopup(QPoint)));
    connect(pClient, SIGNAL(event(ICQEvent*)), this, SLOT(processEvent(ICQEvent*)));
    connect(pClient, SIGNAL(messageRead(ICQMessage*)), this, SLOT(messageRead(ICQMessage*)));
    connect(pClient, SIGNAL(messageReceived(ICQMessage*)), this, SLOT(messageReceived(ICQMessage*)));
    connect(pMain, SIGNAL(iconChanged()), this, SLOT(reset()));
    m_state = 0;
    showIcon = State;
    QTimer *t = new QTimer(this);
    connect(t, SIGNAL(timeout()), this, SLOT(timer()));
    t->start(800);
    bool bWMDock = false;
#ifndef WIN32
    Atom r_type;
    int r_format;
    unsigned long count, bytes_remain;
    unsigned char *prop = NULL, *prop2 = NULL;
    Atom _XA_WIN_SUPPORTING_WM_CHECK = XInternAtom(qt_xdisplay(), XA_WIN_SUPPORTING_WM_CHECK, False);
    int p = XGetWindowProperty(qt_xdisplay(), qt_xrootwin(), _XA_WIN_SUPPORTING_WM_CHECK,
                               0, 1, False, XA_CARDINAL, &r_type, &r_format,
                               &count, &bytes_remain, &prop);

    if (p == Success && prop && r_type == XA_CARDINAL &&
            r_format == 32 && count == 1)
    {
        Window n = *(long *) prop;

        p = XGetWindowProperty(qt_xdisplay(), n, _XA_WIN_SUPPORTING_WM_CHECK, 0, 1,
                               False, XA_CARDINAL, &r_type, &r_format,
                               &count, &bytes_remain, &prop2);

        if (p == Success && prop2 && r_type == XA_CARDINAL &&
                r_format == 32 && count == 1)
            bWMDock = true;
    }

    if (prop)
        XFree(prop);
    if (prop2)
        XFree(prop2);

#endif
#ifdef USE_KDE
    log(L_DEBUG, "WM props? %u", bWMDock);
    if (!bWMDock)
        KWin::setSystemTrayWindowFor( winId(), main->topLevelWidget()->winId());
#endif
    needToggle = false;
#ifdef WIN32
    QWidget::hide();
    QWidget::setIcon(Pict(pClient->getStatusIcon()));
    gDock = this;
    oldDockProc = (WNDPROC)SetWindowLongW(winId(), GWL_WNDPROC, (LONG)DockWindowProc);
    if (oldDockProc == 0)
        oldDockProc = (WNDPROC)SetWindowLongA(winId(), GWL_WNDPROC, (LONG)DockWindowProc);
    NOTIFYICONDATAA notifyIconData;
    notifyIconData.cbSize = sizeof(notifyIconData);
    notifyIconData.hIcon = topData()->winIcon;
    notifyIconData.hWnd = winId();
    notifyIconData.szTip[0] = 0;
    notifyIconData.uCallbackMessage = WM_DOCK;
    notifyIconData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
    notifyIconData.uID = 0;
    Shell_NotifyIconA(NIM_ADD, &notifyIconData);
#else
    if (!bWMDock){
        setBackgroundMode(X11ParentRelative);
        setIcon(Pict(pClient->getStatusIcon()));
#ifdef USE_KDE
        show();
#else
    hide();
#endif
    }else{
        wharfIcon = new WharfIcon(this);
        Display *dsp = x11Display();
        WId win = winId();
        XWMHints *hints;
        XClassHint classhint;
        classhint.res_name  = (char*)"sim";
        classhint.res_class = (char*)"sim";
        XSetClassHint(dsp, win, &classhint);
        hints = XGetWMHints(dsp, win);
        hints->initial_state = WithdrawnState;
        hints->icon_x = 0;
        hints->icon_y = 0;
        hints->icon_window = wharfIcon->winId();
        hints->window_group = win;
        hints->flags = WindowGroupHint | IconWindowHint | IconPositionHint | StateHint;
        XSetWMHints(dsp, win, hints);
        XFree( hints );
        XSetCommand(dsp, winId(), _argv, _argc);
        resize(64, 64);
        show();
    }
#endif
    loadUnread();
    reset();
}