void
context_callback ( MBTrayApp *app )
{
#ifdef USE_LIBSN
  if (CONTEXT_APP_WANT_SN)
    {
      sn_activate(CONTEXT_APP, CONTEXT_APP " " CONTEXT_APP_ARGS);      
      return;
    }
#endif

  fork_exec(CONTEXT_APP " " CONTEXT_APP_ARGS);
}
static void 
si_activate(char *name, char *exec_str)
{
  Window win_found;

  if (mb_single_instance_is_starting(dpy, exec_str))
    return;

  win_found = mb_single_instance_get_window(dpy, exec_str);

  if (win_found != None)
    {
      mb_util_window_activate(dpy, win_found);
    }
  else sn_activate(name, exec_str);

}
示例#3
0
static int
sn_isa_attach (device_t dev)
{
 	struct sn_softc *sc = device_get_softc(dev);
	int err;

	sc->dev = dev;
	err = sn_activate(dev);
	if (err) {
		sn_deactivate(dev);
		return (err);
	}
	err = sn_attach(dev);
	if (err)
		sn_deactivate(dev);
	return (err);
}
int 
main(int argc, char **argv)
{
  int i, x, y;

  /* Config Parameters */
  int switch_count      = 1;
  char *img_file        = NULL;
  char *dotdesktop_file = NULL;
  MBDotDesktop *dd      = NULL;
  Bool start_app        = False;
  char png_path[256]    = { 0 };

  TrayApp = mb_tray_app_new ( "mb-applet-launcher",
			      resize_callback,
			      paint_callback,
			      &argc,
			      &argv );  

  for (i = 1; i < argc; i++) {
    if (argv[i][0] == '-')
      {

	if (!strcmp ("--title", argv[i]) || !strcmp ("-n", argv[i])) {
	  if (++i>=argc) usage (argv[0]);
	  win_panel_title = argv[i];
	  switch_count += 2;
	  continue;
	}

	if (!strcmp ("--kill", argv[i]) || !strcmp ("-k", argv[i])) {
	  action = ACTION_KILL;
	  switch_count++;
	  continue;
	}

	if (!strcmp ("--start", argv[i]) || !strcmp ("-s", argv[i])) {
	  start_app = True;
	  switch_count++;
	  continue;
	}
	
	if (!strcmp ("--kill", argv[i]) || !strcmp ("-k", argv[i])) {
	  action = ACTION_KILL;
	  switch_count++;
	  continue;
	}
	
	if (!strcmp ("--relaunch", argv[i]) || !strcmp ("-l", argv[i])) {
	  action = ACTION_NONE;
	  switch_count++;
	  continue;
	}
	
	if (!strcmp ("--message", argv[i]) || !strcmp ("-m", argv[i])) {
	  action = ACTION_MESSAGE_DOCK;
	  switch_count++;
	  continue;
	}

	if (!strcmp ("--no-animation", argv[i]) || !strcmp ("-na", argv[i])) {
	  DoAnimation = False;
	  switch_count++;
	  continue;
	}

	if (!strcmp ("--desktop", argv[i])) {
	  if (++i>=argc) usage (argv[0]);
	  dotdesktop_file = argv[i];
	  switch_count += 2;
	  continue;
	}
	usage(argv[0]);
      }
    else break;
  }

  if (argc-switch_count < 2 && dotdesktop_file == NULL) usage(argv[0]);

  dpy    = mb_tray_app_xdisplay(TrayApp);
  screen = mb_tray_app_xscreen(TrayApp);

  atom_wm_state  = XInternAtom(dpy, "WM_STATE", False);
  atom_wm_delete = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
  atom_wm_protos = XInternAtom(dpy, "WM_PROTOCOLS", False);

  pb = mb_pixbuf_new(dpy, mb_tray_app_xscreen(TrayApp));

  if (dotdesktop_file != NULL)
    {
      if ((dd = mb_dotdesktop_new_from_file(dotdesktop_file)) != NULL
	  && mb_dotdesktop_get(dd, "Name")
	  && mb_dotdesktop_get(dd, "Icon")
	  && mb_dotdesktop_get(dd, "Exec") )
	{

	  img_file = mb_dotdesktop_get(dd, "Icon");

	  if (img_file[0] != '/')
	    {
	      snprintf(png_path, 256, "%s/pixmaps/%s", DATADIR,  
		       mb_dotdesktop_get(dd, "Icon") );
	      img_file = strdup(png_path);
	    }

	  cmd_str  = mb_dotdesktop_get_exec(dd);
	  if (!win_panel_title) 
	    win_panel_title = mb_dotdesktop_get(dd, "Name");
#ifdef USE_LIBSN

	  if (mb_dotdesktop_get(dd, "SingleInstance")
	      && !strcasecmp(mb_dotdesktop_get(dd, "SingleInstance"), 
			     "true"))
	    {
	      action = ACTION_SI;
	    }
	  else if (mb_dotdesktop_get(dd, "StartupNotify")
		   && !strcasecmp(mb_dotdesktop_get(dd, "StartupNotify"), 
				  "true"))
	    {
	      action = ACTION_SN;
	    }
	  else   
#endif
	    if (mb_dotdesktop_get(dd, "X-MB-NoWindow")
		&& !strcasecmp(mb_dotdesktop_get(dd, "X-MB-NoWindow"), 
			       "true"))
	      {
		DoAnimation = False;
		action = ACTION_NONE;
	      }	
	}
      else
	{
	  fprintf(stderr,"%s: failed to parse %s\n", 
		  argv[0], dotdesktop_file); 
	  exit(1);
	}

    } else {
      img_file = argv[switch_count];

      if (img_file[0] != '/')
	{
	  /* FIXME: should really get from theme */
	  snprintf(png_path, 256, "%s/pixmaps/%s", DATADIR, img_file);
	  img_file = strdup(png_path);
	}

      cmd_str  = arr_to_str(&argv[switch_count+1], argc - switch_count - 1);
    }

  if (!(img_icon = mb_pixbuf_img_new_from_file(pb, img_file)))
    {
      fprintf(stderr, "%s: failed to load image %s \n", 
	      argv[0], img_file );
      exit(1);
    }

  /* make active button image */
  img_icon_active = mb_pixbuf_img_clone(pb, img_icon);

  for (x=0; x<mb_pixbuf_img_get_width(img_icon); x++)
    for (y=0; y<mb_pixbuf_img_get_height(img_icon); y++)
      {
	int aa;
	unsigned char r,g,b,a;
	mb_pixbuf_img_get_pixel (pb, img_icon_active, x, y, &r, &g, &b, &a);

	aa = (int)a;
	aa -=  0x80; if (aa < 0) aa = 0;

	mb_pixbuf_img_set_pixel_alpha(img_icon_active, x, y, aa);
      }


#ifdef USE_LIBSN
  if (action == ACTION_SN || action == ACTION_SI)
    sn_dpy = sn_display_new (dpy, NULL, NULL);
#endif

  mb_tray_app_set_xevent_callback (TrayApp, xevent_callback );

  mb_tray_app_set_button_callback (TrayApp, button_callback );


  if (win_panel_title == NULL) 	/* XXX UTF8 naming */
    {
      win_panel_title = malloc( strlen(argv[1+switch_count]) +
				strlen(" Launcher") + 1 ); 
      strcpy(win_panel_title, argv[1+switch_count]);
      strcat(win_panel_title, " Launcher");
    }
  
  mb_tray_app_set_name (TrayApp, win_panel_title);

  XSelectInput(dpy, mb_tray_app_xrootwin(TrayApp), SubstructureNotifyMask);

  signal(SIGCHLD, SIG_IGN);

  mb_tray_app_set_icon(TrayApp, pb, img_icon);

  /* make sure we always end up on the left of the panel */
  mb_tray_app_request_offset (TrayApp, -1); 

  if (start_app)
    {
      switch(action)
	{
#ifdef USE_LIBSN
	case ACTION_SN:
	  sn_activate(win_panel_title, cmd_str);
	  break;
	case ACTION_SI:
	  si_activate(win_panel_title, cmd_str);
	  break;
#endif
	case ACTION_NONE:
	  fork_exec(cmd_str);
	  break;
	case ACTION_KILL:
	case ACTION_TOGGLE_WIN_STATE:
	  fork_exec(cmd_str);
	  win_launched = get_launch_window();
	  break;
	}
    }

  mb_tray_app_main (TrayApp);

  XCloseDisplay(dpy);
  exit(0);
}
void
button_callback (MBTrayApp *app, int x, int y, Bool is_released )
{
  int abs_x, abs_y;
  Bool do_anim = False;

  ButtonIsDown = True;
  if (is_released)
    {
      ButtonIsDown = False;
      mb_tray_app_repaint (app);
      switch (action)
	{
	case ACTION_NONE:
	  fork_exec(cmd_str);
	  do_anim = DoAnimation;
	  break;
	case ACTION_KILL:
	  if (win_launched && win_exists(win_launched, mb_tray_app_xrootwin(app)))
	    {
	      kill_launched_win(win_launched);
	      win_launched = None;
	    } else {
	      fork_exec(cmd_str);
	      win_launched = get_launch_window();
	    }
	  break;
	case ACTION_TOGGLE_WIN_STATE:
	  if (win_launched && win_exists(win_launched, mb_tray_app_xrootwin(app)))
	    {
	      XWindowAttributes win_attrib;
	      XGetWindowAttributes(dpy, win_launched, &win_attrib);
	      
	      if (win_attrib.map_state == IsUnmapped ||
		  get_win_state(win_launched) != NormalState)
		XMapRaised(dpy, win_launched);
	      else
		XIconifyWindow(dpy, win_launched, screen);
	    }
	  else
	    {
	      fork_exec(cmd_str);
	      win_launched = get_launch_window();
	    }
	  break;
	case ACTION_MESSAGE_DOCK:
	  send_panel_message(cmd_str);
	  break;
#ifdef USE_LIBSN
	case ACTION_SN:
	  do_anim = DoAnimation;
	  sn_activate(win_panel_title, cmd_str);
	  break;
	case ACTION_SI:
	  do_anim = DoAnimation;
	  si_activate(win_panel_title, cmd_str);
	  break;
#endif
	}

      if (do_anim)
	{
	  mb_tray_app_get_absolute_coords (app, &abs_x, &abs_y); 

	  mb_util_animate_startup(mb_tray_app_xdisplay (app), 
				  abs_x,
				  abs_y,
				  mb_tray_app_width (app),
				  mb_tray_app_height (app));
	}
    } else mb_tray_app_repaint (app);


}
示例#6
0
int
sn_attach(device_t dev)
{
	struct sn_softc *sc = device_get_softc(dev);
	struct ifnet   *ifp = &sc->arpcom.ac_if;
	u_short         i;
	u_char         *p;
	int             rev;
	u_short         address;
	int		j;
	int		error;

	sn_activate(dev);

	snstop(sc);

	sc->dev = dev;
	sc->pages_wanted = -1;

	device_printf(dev, " ");

	SMC_SELECT_BANK(3);
	rev = inw(BASE + REVISION_REG_W);
	if (chip_ids[(rev >> 4) & 0xF])
		kprintf("%s ", chip_ids[(rev >> 4) & 0xF]);

	SMC_SELECT_BANK(1);
	i = inw(BASE + CONFIG_REG_W);
	kprintf("%s\n", i & CR_AUI_SELECT ? "AUI" : "UTP");

	if (sc->pccard_enaddr)
		for (j = 0; j < 3; j++) {
			u_short	w;

			w = (u_short)sc->arpcom.ac_enaddr[j * 2] | 
				(((u_short)sc->arpcom.ac_enaddr[j * 2 + 1]) << 8);
			outw(BASE + IAR_ADDR0_REG_W + j * 2, w);
		}

	/*
	 * Read the station address from the chip. The MAC address is bank 1,
	 * regs 4 - 9
	 */
	SMC_SELECT_BANK(1);
	p = (u_char *) & sc->arpcom.ac_enaddr;
	for (i = 0; i < 6; i += 2) {
		address = inw(BASE + IAR_ADDR0_REG_W + i);
		p[i + 1] = address >> 8;
		p[i] = address & 0xFF;
	}
	ifp->if_softc = sc;
	if_initname(ifp, "sn", device_get_unit(dev));
	ifp->if_mtu = ETHERMTU;
	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
	ifp->if_start = snstart;
	ifp->if_ioctl = snioctl;
	ifp->if_watchdog = snwatchdog;
	ifp->if_init = sninit;
	ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN);
	ifq_set_ready(&ifp->if_snd);
	ifp->if_timer = 0;

	ether_ifattach(ifp, sc->arpcom.ac_enaddr, NULL);

	ifq_set_cpuid(&ifp->if_snd, rman_get_cpuid(sc->irq_res));

	error = bus_setup_intr(dev, sc->irq_res, INTR_MPSAFE,
			       sn_intr, sc, &sc->intrhand,
			       ifp->if_serializer);
	if (error) {
		ether_ifdetach(ifp);
		sn_deactivate(dev);
		return error;
	}

	return 0;
}