Exemple #1
0
/***********************************************************************
 *
 *  Procedure:
 *	main - start of module
 *
 ***********************************************************************/
void main(int argc, char **argv)
{
  char *temp, *s;
  char *display_name = NULL;

  /* Record the program name for error messages */
  temp = argv[0];

  s=strrchr(argv[0], '/');
  if (s != NULL)
    temp = s + 1;

  MyName = safemalloc(strlen(temp)+2);
  strcpy(MyName,"*");
  strcat(MyName, temp);

  if((argc != 6)&&(argc != 7))
    {
      fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName,
	      PACKAGE_VERSION);
      exit(1);
    }

  /* Open the X display */
  if (!(dpy = XOpenDisplay(display_name))) 
    {
      fprintf(stderr,"%s: can't open display %s", MyName,
	      XDisplayName(display_name));
      exit (1);
    }
  screen= DefaultScreen(dpy);
  ScreenHeight = DisplayHeight(dpy,screen);
  ScreenWidth = DisplayWidth(dpy,screen);

  /* We should exit if our fvwm pipes die */
  signal (SIGPIPE, DeadPipe);  
  
  fd[0] = atoi(argv[1]);
  fd[1] = atoi(argv[2]);

  fd_width = GetFdWidth();

  /* Create a list of all windows */
  /* Request a list of all windows,
   * wait for ConfigureWindow packets */
  SendInfo(fd,"Send_WindowList",0);

  Loop(fd);
}
Exemple #2
0
void initModules(void)
{
  int i;

  npipes = GetFdWidth();

  writePipes = (int *) safemalloc(sizeof(int) * npipes);
  readPipes = (int *) safemalloc(sizeof(int) * npipes);
  pipeOn = (int *) safemalloc(sizeof(int) * npipes);
  PipeMask = (unsigned long *) safemalloc(sizeof(unsigned long) * npipes);
  pipeName = (char **) safemalloc(sizeof(char *) * npipes);
  pipeQueue = (struct queue_buff_struct **)
      safemalloc(sizeof(struct queue_buff_struct *) * npipes);

  for (i = 0; i < npipes; i++) {
    writePipes[i] = -1;
    readPipes[i] = -1;
    pipeOn[i] = -1;
    PipeMask[i] = MAX_MASK;
    pipeQueue[i] = (struct queue_buff_struct *) NULL;
    pipeName[i] = NULL;
  }
}
Exemple #3
0
int main(int argc, char **argv)
{
  unsigned long valuemask;		/* mask for create windows */
  XSetWindowAttributes attributes;	/* attributes for create windows */
  void InternUsefulAtoms(void);
  void InitVariables(void);
  int  i, len;
  extern int x_fd;
  char *display_string;
  char message[255];
  Bool single = False;
  Bool option_error = FALSE;
  MenuRoot *mr;

  g_argv = argv;
  g_argc = argc;

  OpenConsole();
  DBUG("main", "Entered, about to parse args");

  for (i = 1; i < argc; i++) {
    if (strncasecmp(argv[i], "-debug", 6) == 0) {
      debugging = True;
    } else if (strncasecmp(argv[i], "-s", 2) == 0) {
      single = True;
    } else if (strncasecmp(argv[i], "-d", 2) == 0) {
      if (++i >= argc)
	usage();
      display_name = argv[i];
    } else if (strncasecmp(argv[i], "-f", 2) == 0) {
      if (++i >= argc)
	usage();
      config_command = (char *) malloc(6 + strlen(argv[i]));
      strcpy(config_command, "Read ");
      strcat(config_command, argv[i]);
      free_config_command = True;
    } else if (strncasecmp(argv[i], "-cmd", 4) == 0) {
      if (++i >= argc)
	usage();
      config_command = argv[i];
    } else if (strncasecmp(argv[i], "-file", 5) == 0) {
      if (++i >= argc)
	usage();
      output_file = argv[i];
    } else if (strncasecmp(argv[i], "-h", 2) == 0) {
      usage();
      exit(0);
    } else if (strncasecmp(argv[i], "-blackout", 9) == 0) {
      Blackout = True;
    } else if (strncasecmp(argv[i], "-version", 8) == 0) {
      fvwm_msg(INFO, "main", "Fvwm95 Version %s compiled on %s at %s\n",
	       VERSION, __DATE__, __TIME__);
    } else {
      fvwm_msg(ERR, "main", "Unknown option: `%s'\n", argv[i]);
      option_error = TRUE;
    }
  }

  DBUG("main", "Done parsing args");

  if (option_error) {
    usage();
  }

  DBUG("main", "Installing signal handlers");

  newhandler(SIGINT);
  newhandler(SIGHUP);
  newhandler(SIGQUIT);
  newhandler(SIGTERM);
  signal(SIGUSR1, Restart);
  signal(SIGPIPE, DeadPipe);

  ReapChildren();

  if (!(dpy = XOpenDisplay(display_name))) {
    fvwm_msg(ERR, "main", "can't open display %s",
	     XDisplayName(display_name));
    exit(1);
  }
  Scr.screen = DefaultScreen(dpy);
  Scr.NumberOfScreens = ScreenCount(dpy);

  master_pid = getpid();

  if (!single) {
    int myscreen = 0;
    char *cp;

    strcpy(message, XDisplayString(dpy));

    XCloseDisplay(dpy);

    for (i = 1; i < Scr.NumberOfScreens; i++) {
      if (fork() == 0) {
	myscreen = i;
	break;
      }
    }
    /*
     * Truncate the string 'whatever:n.n' to 'whatever:n',
     * and then append the screen number.
     */
    cp = strchr(message, ':');
    if (cp != NULL) {
      cp = strchr(cp, '.');
      if (cp != NULL)
	*cp = '\0';		/* truncate at display part */
    }
    sprintf(message + strlen(message), ".%d", myscreen);
    dpy = XOpenDisplay(message);
    Scr.screen = myscreen;
    Scr.NumberOfScreens = ScreenCount(dpy);
  }

  x_fd = XConnectionNumber(dpy);
  fd_width = GetFdWidth();

  if (fcntl(x_fd, F_SETFD, 1) == -1) {
    fvwm_msg(ERR, "main", "close-on-exec failed");
    exit(1);
  }

  /*  Add a DISPLAY entry to the environment, in case we were started
   *  with fvwm -display term:0.0
   */
  len = strlen(XDisplayString(dpy));
  display_string = safemalloc(len + 10);
  sprintf(display_string, "DISPLAY=%s", XDisplayString(dpy));
  putenv(display_string);

  /* Add a HOSTDISPLAY environment variable, which is the same as
   * DISPLAY, unless display = :0.0 or unix:0.0, in which case the full
   * host name will be used for ease in networking . */

  /* Note: Can't free the rdisplay_string after putenv, because it
   * becomes part of the environment! */

  if (strncmp(display_string, "DISPLAY=:", 9) == 0) {
    char client[MAXHOSTNAME], *rdisplay_string;

    mygethostname(client, MAXHOSTNAME);
    rdisplay_string = safemalloc(len + 14 + strlen(client));
    sprintf(rdisplay_string, "HOSTDISPLAY=%s:%s", client,
	    &display_string[9]);
    putenv(rdisplay_string);
  } else if (strncmp(display_string, "DISPLAY=unix:", 13) == 0) {
    char client[MAXHOSTNAME], *rdisplay_string;

    mygethostname(client, MAXHOSTNAME);
    rdisplay_string = safemalloc(len + 14 + strlen(client));
    sprintf(rdisplay_string, "HOSTDISPLAY=%s:%s", client,
	    &display_string[13]);
    putenv(rdisplay_string);
  } else {
    char *rdisplay_string;

    rdisplay_string = safemalloc(len + 14);
    sprintf(rdisplay_string, "HOSTDISPLAY=%s", XDisplayString(dpy));
    putenv(rdisplay_string);
  }

  Scr.Root = RootWindow(dpy, Scr.screen);
  if (Scr.Root == None) {
    fvwm_msg(ERR, "main", "Screen %d is not a valid screen",
	     (char *) Scr.screen);
    exit(1);
  }

#ifdef SHAPE
  ShapesSupported =
      XShapeQueryExtension(dpy, &ShapeEventBase, &ShapeErrorBase);
#endif	/* SHAPE */

  InternUsefulAtoms();

  /* Make sure property priority colors is empty */
  XChangeProperty(dpy, Scr.Root, _XA_MIT_PRIORITY_COLORS,
		  XA_CARDINAL, 32, PropModeReplace, NULL, 0);

  XSetErrorHandler((XErrorHandler) CatchRedirectError);
  XSetIOErrorHandler((XIOErrorHandler) CatchFatal);

  XSelectInput(dpy, Scr.Root,
	       LeaveWindowMask | EnterWindowMask | PropertyChangeMask |
	       SubstructureRedirectMask | KeyPressMask |
	       SubstructureNotifyMask |
	       ButtonPressMask | ButtonReleaseMask);

  XSync(dpy, 0);

  XSetErrorHandler((XErrorHandler) FvwmErrorHandler);

  BlackoutScreen();

  CreateCursors();
  InitVariables();
  InitEventHandlerJumpTable();
  initModules();

  InitPictureCMap(dpy, Scr.Root);	/* for the pixmap cache... */

  Scr.gray_bitmap =
      XCreateBitmapFromData(dpy, Scr.Root, g_bits, g_width, g_height);

  DBUG("main", "Setting up rc file defaults...");
  SetRCDefaults();

  DBUG("main", "Running config_command...");
  ExecuteFunction(config_command, NULL, &Event, C_ROOT, -1);
  DBUG("main", "Done running config_command");

/*
  CaptureAllWindows();
  MakeMenus();
*/

#if 0	/* this seems to cause problems for FvwmCpp/M4 startup actually */
  /* if not a direct 'Read', we'll capture all windows here, in case cmd
     fails we'll still have defaults */
  if (strncasecmp(config_command, "Read", 4) != 0 &&
      strncasecmp(config_command, "PipeRead", 8) != 0) {
    /* so if cmd (FvwmM4/Cpp most likely) fails, we can still have
       borders & stuff... */
    StartupStuff();
  }
#endif	/* 0 */

  if (free_config_command) {
    free(config_command);
  }

  if (Scr.d_depth < 2) {
    Scr.gray_pixmap =
	XCreatePixmapFromBitmapData(dpy, Scr.Root, g_bits, g_width,
				    g_height, Scr.WinColors.fore,
				    Scr.WinColors.back, Scr.d_depth);
    Scr.light_gray_pixmap =
	XCreatePixmapFromBitmapData(dpy, Scr.Root, l_g_bits, l_g_width,
				    l_g_height, Scr.WinColors.fore,
				    Scr.WinColors.back, Scr.d_depth);
  }

  /* create a window which will accept the keyboard focus when no other 
     windows have it */
  attributes.event_mask = KeyPressMask | FocusChangeMask;
  attributes.override_redirect = True;
  Scr.NoFocusWin = XCreateWindow(dpy, Scr.Root, -10, -10, 10, 10, 0, 0,
				 InputOnly, CopyFromParent,
				 CWEventMask | CWOverrideRedirect,
				 &attributes);
  XMapWindow(dpy, Scr.NoFocusWin);

  SetMWM_INFO(Scr.NoFocusWin);

  XSetInputFocus(dpy, Scr.NoFocusWin, RevertToParent, CurrentTime);

  XSync(dpy, 0);
  if (debugging)
    XSynchronize(dpy, 1);

  Scr.SizeStringWidth = XTextWidth(Scr.StdFont.font,
				   " +8888 x +8888 ", 15);
  attributes.border_pixel = Scr.WinColors.fore;
  attributes.background_pixel = Scr.WinColors.back;
  attributes.bit_gravity = NorthWestGravity;
  attributes.save_under = True;
  valuemask = (CWBorderPixel | CWBackPixel | CWBitGravity | CWSaveUnder);

  /* create the window for coordinates */
  Scr.SizeWindow = XCreateWindow(dpy, Scr.Root,
				 Scr.MyDisplayWidth / 2 -
				 (Scr.SizeStringWidth +
				  SIZE_HINDENT * 2) / 2,
				 Scr.MyDisplayHeight / 2 -
				 (Scr.StdFont.height +
				  SIZE_VINDENT * 2) / 2,
				 (unsigned int) (Scr.SizeStringWidth +
						 SIZE_HINDENT * 2),
				 (unsigned int) (Scr.StdFont.height +
						 SIZE_VINDENT * 2),
				 (unsigned int) 0, 0,
				 (unsigned int) CopyFromParent,
				 (Visual *) CopyFromParent,
				 valuemask, &attributes);

#ifndef NON_VIRTUAL
  initPanFrames();
#endif

  XGrabServer(dpy);

#ifndef NON_VIRTUAL
  checkPanFrames();
#endif
  XUngrabServer(dpy);
  UnBlackoutScreen();
  DBUG("main", "Entering HandleEvents loop...");
  HandleEvents();
  DBUG("main", "Back from HandleEvents loop?  Exiting...");

  return 0;
}
Exemple #4
0
/*
 *
 *  Procedure:
 *      main - start of module
 *
 */
int main(int argc, char **argv)
{
  char *tline;

  module = ParseModuleArgs(argc,argv,0); /* no alias allowed */
  if (module==NULL)
  {
    fprintf(stderr,"FvwmScroll Version %s should only be executed by fvwm!\n",
	    VERSION);
    exit(1);
  }

  if(module->user_argc >= 1)
  {
    extern int Reduction_H;
    extern int Percent_H;
    int len;
    len = strlen(module->user_argv[0])-1;
    if (len >= 0 && module->user_argv[0][len] == 'p')
    {
      module->user_argv[0][len] = '\0';
      Percent_H = atoi(module->user_argv[0]);
    }
    else
    {
      Reduction_H = atoi(module->user_argv[0]);
    }
  }

  if(module->user_argc >= 2)
  {
    extern int Reduction_V;
    extern int Percent_V;
    int len;
    len = strlen(module->user_argv[1])-1;
    if (len >= 0 && module->user_argv[1][len] == 'p')
    {
      module->user_argv[1][len] = '\0';
      Percent_V = atoi(module->user_argv[1]);
    }
    else
    {
      Reduction_V = atoi(module->user_argv[1]);
    }
  }

  /* Dead pipe == dead fvwm */
  signal (SIGPIPE, DeadPipe);

  fd[0] = module->to_fvwm;
  fd[1] = module->from_fvwm;

  /* Open the Display */
  if (!(dpy = XOpenDisplay(NULL)))
  {
    fprintf(stderr,"%s: can't open display\n", module->name);
    exit (1);
  }
  x_fd = XConnectionNumber(dpy);
  screen= DefaultScreen(dpy);
  Root = RootWindow(dpy, screen);

  ScreenHeight = DisplayHeight(dpy,screen);
  ScreenWidth = DisplayWidth(dpy,screen);

  SetMessageMask(fd, M_CONFIG_INFO | M_END_CONFIG_INFO | M_SENDCONFIG);
  SetMessageMask(fd, MX_PROPERTY_CHANGE);
  flib_init_graphics(dpy);

  /* scan config file for set-up parameters */
  /* Colors and fonts */
  InitGetConfigLine(fd,CatString3("*",module->name,0));
  GetConfigLine(fd,&tline);

  while(tline != (char *)0)
  {
    if(strlen(tline)>1)
    {
      if(strncasecmp(tline,CatString3("*",module->name, "Back"),
		     module->namelen+4)==0)
      {
	CopyString(&BackColor,&tline[module->namelen+4]);
	colorset = -1;
      }
      else if(strncasecmp(tline,CatString3("*",module->name,"Colorset"),
                          module->namelen+8)==0)
      {
	sscanf(&tline[module->namelen+8], "%d", &colorset);
	AllocColorset(colorset);
      }
      else if(strncasecmp(tline, "Colorset", 8) == 0)
      {
	LoadColorset(&tline[8]);
      }
    }
    GetConfigLine(fd,&tline);
  }

  XSetErrorHandler(ErrorHandler);

  if(module->window == 0)
    GetTargetWindow(&module->window);

  if(module->window == 0)
    return 0;

  fd_width = GetFdWidth();

  GrabWindow(module->window);

  /* tell fvwm we're running */
  SendFinishedStartupNotification(fd);

  Loop(module->window);
  return 0;
}
Exemple #5
0
/******************************************************************************
  Main - Setup the XConnection,request the window list and loop forever
    Based on main() from FvwmIdent:
      Copyright 1994, Robert Nation and Nobutaka Suzuki.
******************************************************************************/
int main(int argc, char **argv)
{
  char *temp, *s;

  /* Save the program name for error messages and config parsing */
  temp = argv[0];
  s=strrchr(argv[0], '/');
  if (s != NULL)
    temp = s + 1;
  
  /* Setup my name */
  Module = safemalloc(strlen(temp)+2);
  strcpy(Module,"*");
  strcat(Module, temp);
  Clength = strlen(Module);

  /* Open the console for messages */
  OpenConsole();

  if((argc != 6)&&(argc != 7)) {
    fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",Module,
      VERSION);
    ConsoleMessage("%s Version %s should only be executed by fvwm!\n",Module,
      VERSION);
   exit(1);
  }


  if ((argc==7)&&(!strcasecmp(argv[6],"Transient"))) Transient=1;

  Fvwm_fd[0] = atoi(argv[1]);
  Fvwm_fd[1] = atoi(argv[2]);

  signal (SIGPIPE, DeadPipe);  

  /* Parse the config file */
  ParseConfig();

  /* Setup the XConnection */
  StartMeUp();
  XSetErrorHandler((XErrorHandler) ErrorHandler);

  InitPictureCMap(dpy, Root);

  InitArray(&buttons,0,0,win_width, fontheight+6);
  InitList(&windows);

  fd_width = GetFdWidth();

  /* Request a list of all windows,
   * wait for ConfigureWindow packets */
  SendFvwmPipe("Send_WindowList",0);

/*  SetMessageMask(Fvwm_fd,M_ADD_WINDOW|M_CONFIGURE_WINDOW| M_DESTROY_WINDOW|
	      M_WINDOW_NAME|M_ICON_NAME|M_DEICONIFY|M_ICONIFY|M_END_WINDOWLIST|
	      M_NEW_DESK| M_NEW_PAGE);*/
  /* Recieve all messages from Fvwm */
  EndLessLoop();

  return 0;
}
/******************************************************************************
  Main - Setup the XConnection,request the window list and loop forever
    Based on main() from FvwmIdent:
      Copyright 1994, Robert Nation and Nobutaka Suzuki.
******************************************************************************/
int main(int argc, char **argv)
{
    char *temp, *s;
#ifdef HAVE_SIGACTION
    struct sigaction  sigact;
#endif

    /* Save the program name for error messages and config parsing */
    temp = argv[0];
    s=strrchr(argv[0], '/');
    if (s != NULL)
        temp = s + 1;

    /* Setup my name */
    Module = safemalloc(strlen(temp)+2);
    strcpy(Module,"*");
    strcat(Module, temp);
    Clength = strlen(Module);

    /* Open the console for messages */
    OpenConsole();

    if((argc != 6)&&(argc != 7)) {
        fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",Module,
                VERSION);
        ConsoleMessage("%s Version %s should only be executed by fvwm!\n",Module,
                       VERSION);
        exit(1);
    }


    if ((argc==7)&&(!strcasecmp(argv[6],"Transient"))) Transient=1;

    Fvwm_fd[0] = atoi(argv[1]);
    Fvwm_fd[1] = atoi(argv[2]);

#ifdef HAVE_SIGACTION
#ifdef SA_INTERRUPT
    sigact.sa_flags = SA_INTERRUPT;
#else
    sigact.sa_flags = 0;
#endif
    sigemptyset(&sigact.sa_mask);
    sigact.sa_handler = TerminateHandler;
    sigaction(SIGPIPE, &sigact, NULL);
    sigaction(SIGTERM, &sigact, NULL);
#else
    signal(SIGPIPE, TerminateHandler);
    signal(SIGTERM, TerminateHandler);
#ifdef HAVE_SIGINTERRUPT
    siginterrupt(SIGPIPE, True);
    siginterrupt(SIGTERM, True);
#endif
#endif

    /* Parse the config file */
    ParseConfig();

    /* Setup the XConnection */
    StartMeUp();
    XSetErrorHandler(ErrorHandler);

    InitPictureCMap(dpy, Root);

    InitArray(&buttons,0,0,win_width, fontheight+6);
    InitList(&windows);

    fd_width = GetFdWidth();

    /* Request a list of all windows,
     * wait for ConfigureWindow packets */

    SetMessageMask(Fvwm_fd,M_CONFIGURE_WINDOW | M_RES_CLASS | M_RES_NAME |
                   M_ADD_WINDOW | M_DESTROY_WINDOW | M_ICON_NAME |
                   M_DEICONIFY | M_ICONIFY | M_END_WINDOWLIST |
                   M_NEW_DESK | M_NEW_PAGE | M_FOCUS_CHANGE | M_WINDOW_NAME |
#ifdef MINI_ICONS
                   M_MINI_ICON |
#endif
                   M_STRING);

    SendFvwmPipe("Send_WindowList",0);

    /* Recieve all messages from Fvwm */
    atexit(ShutMeDown);
    MainEventLoop();
    return 0;
}
Exemple #7
0
/***********************************************************************
 *
 *  Procedure:
 *	main - start of module
 *
 ***********************************************************************/
int main(int argc, char **argv)
{
  char *display_name = NULL;
  int itemp,i;
  char line[100];
  short opt_num;
  Window JunkRoot, JunkChild;
  int JunkX, JunkY;
  unsigned JunkMask;

#ifdef I18N_MB
  setlocale(LC_CTYPE, "");
#endif
  /* Save our program  name - for error messages */
  MyName = GetFileNameFromPath(argv[0]);

  if(argc  < 6)
    {
      fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName,
	      VERSION);
      exit(1);
    }

#ifdef HAVE_SIGACTION
  {
    struct sigaction  sigact;

    sigemptyset(&sigact.sa_mask);
    sigaddset(&sigact.sa_mask, SIGPIPE);
    sigaddset(&sigact.sa_mask, SIGTERM);
    sigaddset(&sigact.sa_mask, SIGQUIT);
    sigaddset(&sigact.sa_mask, SIGINT);
    sigaddset(&sigact.sa_mask, SIGHUP);
# ifdef SA_INTERRUPT
    sigact.sa_flags = SA_INTERRUPT;
# else
    sigact.sa_flags = 0;
# endif
    sigact.sa_handler = TerminateHandler;

    sigaction(SIGPIPE, &sigact, NULL);
    sigaction(SIGTERM, &sigact, NULL);
    sigaction(SIGQUIT, &sigact, NULL);
    sigaction(SIGINT,  &sigact, NULL);
    sigaction(SIGHUP,  &sigact, NULL);
  }
#else
  /* We don't have sigaction(), so fall back to less robust methods.  */
#ifdef USE_BSD_SIGNALS
  fvwmSetSignalMask( sigmask(SIGPIPE) |
                     sigmask(SIGTERM) |
                     sigmask(SIGQUIT) |
                     sigmask(SIGINT) |
                     sigmask(SIGHUP) );
#endif
  signal(SIGPIPE, TerminateHandler);
  signal(SIGTERM, TerminateHandler);
  signal(SIGQUIT, TerminateHandler);
  signal(SIGINT,  TerminateHandler);
  signal(SIGHUP,  TerminateHandler);
#ifdef HAVE_SIGINTERRUPT
  siginterrupt(SIGPIPE, 1);
  siginterrupt(SIGTERM, 1);
  siginterrupt(SIGQUIT, 1);
  siginterrupt(SIGINT, 1);
  siginterrupt(SIGHUP, 1);
#endif
#endif

  fd[0] = atoi(argv[1]);
  fd[1] = atoi(argv[2]);

  fd_width = GetFdWidth();

  opt_num = 6;
  if (argc >= 7 && (StrEquals(argv[opt_num], "-transient") ||
		    StrEquals(argv[opt_num], "transient")))
  {
    opt_num++;
    is_transient = True;
      do_ignore_next_button_release = True;
  }

  /* Check for an alias */
  if (argc >= opt_num + 1)
    {
      char *s;

      if (!StrEquals(argv[opt_num], "*"))
      {
	for (s = argv[opt_num]; *s; s++)
	{
	  if (!isdigit(*s) &&
	      (*s != '-' || s != argv[opt_num] || *(s+1) == 0))
	  {
	    free(MyName);
	    MyName=safestrdup(argv[opt_num]);
	    opt_num++;
	    break;
	  }
	}
      }
    }

  if (argc < opt_num + 1)
    {
      desk1 = Scr.CurrentDesk;
      desk2 = Scr.CurrentDesk;
    }
  else if (StrEquals(argv[opt_num], "*"))
    {
      desk1 = Scr.CurrentDesk;
      desk2 = Scr.CurrentDesk;
      fAlwaysCurrentDesk = 1;
    }
  else
    {
      desk1 = atoi(argv[opt_num]);
      if (argc == opt_num+1)
	desk2 = desk1;
      else
	desk2 = atoi(argv[opt_num+1]);
      if(desk2 < desk1)
	{
	  itemp = desk1;
	  desk1 = desk2;
	  desk2 = itemp;
	}
    }
  ndesks = desk2 - desk1 + 1;

  Desks = (DeskInfo *)safemalloc(ndesks*sizeof(DeskInfo));
  memset(Desks, 0, ndesks * sizeof(DeskInfo));
  for(i=0;i<ndesks;i++)
    {
      sprintf(line,"Desk %d",i+desk1);
      CopyString(&Desks[i].label,line);
      Desks[i].colorset = -1;
      Desks[i].highcolorset = -1;
      Desks[i].ballooncolorset = -1;
    }

  /* Initialize X connection */
  if (!(dpy = XOpenDisplay(display_name)))
    {
      fprintf(stderr,"%s: can't open display %s", MyName,
	      XDisplayName(display_name));
      exit (1);
    }
  x_fd = XConnectionNumber(dpy);
  InitPictureCMap(dpy);
  FScreenInit(dpy);
  AllocColorset(0);
  FShapeInit(dpy);

  Scr.screen = DefaultScreen(dpy);
  Scr.Root = RootWindow(dpy, Scr.screen);
  /* make a temp window for any pixmaps, deleted later */
  initialize_viz_pager();

#ifdef DEBUG
  fprintf(stderr,"[main]: Connection to X server established.\n");
#endif

  SetMessageMask(fd,
                 M_ADD_WINDOW|
                 M_CONFIGURE_WINDOW|
                 M_DESTROY_WINDOW|
                 M_FOCUS_CHANGE|
                 M_NEW_PAGE|
                 M_NEW_DESK|
                 M_RAISE_WINDOW|
                 M_LOWER_WINDOW|
                 M_ICONIFY|
		 M_ICON_LOCATION|
		 M_DEICONIFY|
		 M_RES_NAME|
		 M_RES_CLASS|
		 M_WINDOW_NAME|
		 M_ICON_NAME|
		 M_CONFIG_INFO|
		 M_END_CONFIG_INFO|
		 M_MINI_ICON|
		 M_END_WINDOWLIST|
		 M_RESTACK);
#ifdef DEBUG
  fprintf(stderr,"[main]: calling ParseOptions\n");
#endif
  ParseOptions();
  if (is_transient)
    {
      XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild,
		    &window_x, &window_y, &JunkX, &JunkY, &JunkMask);
      usposition = 1;
      xneg = 0;
      yneg = 0;
    }
#ifdef DEBUG
  fprintf(stderr,
	  "[main]: back from calling ParseOptions, calling init pager\n");
#endif

  if (PagerFore == NULL)
    PagerFore = safestrdup("black");

  if (PagerBack == NULL)
    PagerBack = safestrdup("white");

  if (HilightC == NULL)
    HilightC = safestrdup(PagerFore);

  if (WindowLabelFormat == NULL)
    WindowLabelFormat = safestrdup("%i");

  if (font_string == NULL)
    font_string = safestrdup("fixed");

  if ((HilightC == NULL) && (HilightPixmap == NULL))
    HilightDesks = 0;

  if (BalloonFont == NULL)
    BalloonFont = safestrdup("fixed");

  if (BalloonBorderColor == NULL)
    BalloonBorderColor = safestrdup("black");

  if (BalloonTypeString == NULL)
    BalloonTypeString = safestrdup("%i");

  if (BalloonFormatString == NULL)
    BalloonFormatString = safestrdup("%i");

  /* open a pager window */
  initialize_pager();
#ifdef DEBUG
  fprintf(stderr,"[main]: back from init pager, getting window list\n");
#endif

  /* Create a list of all windows */
  /* Request a list of all windows,
   * wait for ConfigureWindow packets */
  SendInfo(fd,"Send_WindowList",0);
#ifdef DEBUG
  fprintf(stderr,"[main]: back from getting window list, looping\n");
#endif

  if (is_transient)
  {
    Bool is_pointer_grabbed = False;
    Bool is_keyboard_grabbed = False;
    XSync(dpy,0);
    for (i = 0; i < 50 && !(is_pointer_grabbed && is_keyboard_grabbed); i++)
    {
      if (!is_pointer_grabbed &&
	  XGrabPointer(
	    dpy, Scr.Root, True,
	    ButtonPressMask|ButtonReleaseMask|ButtonMotionMask|
	    PointerMotionMask|EnterWindowMask|LeaveWindowMask, GrabModeAsync,
	    GrabModeAsync, None, None, CurrentTime) == GrabSuccess)
      {
	is_pointer_grabbed = True;
      }
      if (!is_keyboard_grabbed &&
	  XGrabKeyboard(
	    dpy, Scr.Root, True, GrabModeAsync, GrabModeAsync, CurrentTime) ==
	  GrabSuccess)
      {
	is_keyboard_grabbed = True;
      }
      /* If you go too fast, other windows may not get a change to release
       * any grab that they have. */
      usleep(20000);
    }
    if (!is_pointer_grabbed)
    {
      XBell(dpy, 0);
      fprintf(stderr,
	      "%s: could not grab pointer in transient mode. exiting.\n",
	      MyName);
      exit(1);
    }

    XSync(dpy,0);
  }

  /* tell fvwm we're running */
  SendFinishedStartupNotification(fd);

  Loop(fd);
#ifdef DEBUG
  if (debug_term_signal)
  {
    fprintf(stderr,"[main]: Terminated due to signal %d\n",
                   debug_term_signal);
  }
#endif
  return 0;
}
Exemple #8
0
int
main (int argc, char **argv)
{
  char *temp;
  int i;
  char *global_config_file = NULL;
  char tmp[128];
  FILE *fp = NULL;

  /* Save our program name - for error messages */
  temp = strrchr (argv[0], '/');
  MyName = temp ? temp + 1 : argv[0];

  for (i = 1; i < argc && *argv[i] == '-'; i++)
    {
      if (!strcmp (argv[i], "-h") || !strcmp (argv[i], "--help"))
	usage ();
      else if (!strcmp (argv[i], "-v") || !strcmp (argv[i], "--version"))
	version ();
      else if (!strcmp (argv[i], "-w") || !strcmp (argv[i], "--window"))
	i++;
      else if (!strcmp (argv[i], "-c") || !strcmp (argv[i], "--context"))
	i++;
      else if (!strcmp (argv[i], "-f") && i + 1 < argc)
	global_config_file = argv[++i];
    }

  /* Dead pipe == dead AfterStep */
  signal (SIGPIPE, DeadPipe);
  signal (SIGSEGV, DeadPipe);
  signal (SIGINT, DeadPipe);

  if ((dpy = XOpenDisplay ("")) == NULL)
    {
      fprintf (stderr, "%s: couldn't open display %s\n",
	       MyName, XDisplayName (""));
      exit (1);
    }
  set_current_X_display (dpy);
  screen = DefaultScreen (dpy);

  /* connect to AfterStep */
  temp = module_get_socket_property (RootWindow (dpy, screen));
  fd[0] = fd[1] = module_connect (temp);
  XFree (temp);
  if (fd[0] < 0)
    {
      fprintf (stderr, "%s: unable to establish connection to AfterStep\n", MyName);
      exit (1);
    }
  temp = safemalloc (9 + strlen (MyName) + 1);
  sprintf (temp, "SET_NAME %s", MyName);
  SendInfo (fd, temp, None);
  free (temp);

  x_fd = XConnectionNumber (dpy);
  fd_width = GetFdWidth ();

  XSetErrorHandler (error_handler);

  if (global_config_file != NULL)
    temp = PutHome (global_config_file);
  else
    {
      memset (tmp, 128, '\0');
      sprintf (tmp, "%s/Gnome", AFTER_DIR);
      temp = PutHome (tmp);
      if ((fp = fopen (temp, "r")) == NULL)
	{
	  sprintf (tmp, "%s/Gnome", AFTER_SHAREDIR);
	  free (temp);
	  temp = PutHome (tmp);
	}
    }

  if (fp)
    fclose (fp);

  parse_config (temp);
  free (temp);

  gnome_compliance_init ();

  window_list = s_list_new ();


  set_as_mask ((long unsigned) mask_reg);
  SendInfo (fd, "Send_WindowList\n", 0);

  XSelectInput (dpy, root_win, PropertyChangeMask | SubstructureNotifyMask);
  XSelectInput (dpy, gnome_win, PropertyChangeMask);

  EndLessLoop ();
  return 0;
}
Exemple #9
0
int main(int argc, char *argv[])
{
  char match[128];
  char *config_line;
  int scr;

  console = fopen("/dev/console","w");
  if (!console) console = stderr;

  module = ParseModuleArgs(argc,argv,0);
  if (module == NULL)
  {
    fprintf(stderr,"FvwmRearrange: module should be executed by fvwm only\n");
    exit(-1);
  }

  fd[0] = module->to_fvwm;
  fd[1] = module->from_fvwm;

  if (!(dpy = XOpenDisplay(NULL))) {
    fprintf(console, "%s: couldn't open display %s\n",
	    module->name,
	    XDisplayName(NULL));
    exit(-1);
  }
  signal (SIGPIPE, DeadPipe);

  FScreenInit(dpy);
  scr = DefaultScreen(dpy);
  fd_width = GetFdWidth();

  strcpy(match, "*");
  strcat(match, module->name);
  InitGetConfigLine(fd,match);
  GetConfigLine(fd, &config_line);
  while (config_line != NULL)
  {
    if (strncasecmp(config_line, XINERAMA_CONFIG_STRING,
		    sizeof(XINERAMA_CONFIG_STRING) - 1) == 0)
    {
      FScreenConfigureModule(
	config_line + sizeof(XINERAMA_CONFIG_STRING) - 1);
    }
    GetConfigLine(fd, &config_line);
  }
  FScreenGetScrRect(NULL, FSCREEN_CURRENT, &dx, &dy, &dwidth, &dheight);

  if (strcmp(module->name, "FvwmCascade") &&
      (!strcmp(module->name, "FvwmTile") ||
       (argc >= 7 && !strcmp(argv[6], "-tile")))) {
    FvwmTile = 1;
    FvwmCascade = 0;
    resize = 1;
  } else {
    FvwmCascade = 1;
    FvwmTile = 0;
    resize = 0;
  }
  parse_args("module args", module->user_argc, module->user_argv, 0);

  SetMessageMask(fd,
		 M_CONFIGURE_WINDOW |
		 M_END_WINDOWLIST);
  SetMessageMask(fd,
		 M_EXTENDED_MSG);

  if (FvwmTile) {
    if (maxx == dx)
      maxx = dx + dwidth;
    if (maxy == dy)
      maxy = dy + dheight;
  }

  SendText(fd, "Send_WindowList", 0);

  /* tell fvwm we're running */
  SendFinishedStartupNotification(fd);

  while (get_window()) /* */;
  if (wins_count) {
    if (FvwmCascade)
      cascade_windows();
    else /* FvwmTile */
      tile_windows();
  }
  free_window_list(wins);

  if (console != stderr)
    fclose(console);

  return 0;
}
Exemple #10
0
/****************************************************************************
 *
 * Creates an icon window as needed
 *
 ****************************************************************************/
int main(int argc, char **argv)
{
  char *display_name = NULL, *string = NULL;
  int retval = 0;
  XEvent Event;
  fd_set in_fdset;
  int fd_width ;
  struct timeval value;
  int fd[2];

  fd_width = GetFdWidth();

  /* Save our program  name - for error messages */
  string = strrchr (argv[0], '/');
  if (string != (char *) 0) string++;

  myName = safemalloc (strlen (string) + 1);
  strcpy (myName, string);

  if(argc>=3)
  {
      /* sever our connection with fvwm, if we have one. */
      fd[0] = atoi(argv[1]);
      fd[1] = atoi(argv[2]);

#if 0
      if(fd[0]>0)close(fd[0]);
      if(fd[1]>0)close(fd[1]);
#endif /* 0 */
  }
  else
  {
    fprintf (stderr,
	     "%s version %s should only be executed by fvwm!\n",
	     myName,
	     VERSION);
    exit(1);
  }

  if (argc > 6) {
    pixmapName = safemalloc (strlen (argv[6]) + 1);
    strcpy (pixmapName, argv[6]);
  }

  /* Open the display */
  if (!(dpy = XOpenDisplay(display_name)))
    {
      fprintf(stderr,"FvwmBanner: can't open display %s",
	      XDisplayName(display_name));
      exit (1);
    }
  screen= DefaultScreen(dpy);
  Root = RootWindow(dpy, screen);
  colormap = XDefaultColormap(dpy,screen);
  d_depth = DefaultDepth(dpy, screen);
  x_fd = XConnectionNumber(dpy);

  ScreenHeight = DisplayHeight(dpy,screen);
  ScreenWidth = DisplayWidth(dpy,screen);

  parseOptions(fd);

  /* Get the xpm banner */
  if (pixmapName)
    GetXPMFile(pixmapName,pixmapPath);
  else
#if 0
    if(d_depth > 4)
      GetXPMData(k2_xpm);
    else
#endif /* 0 */
      GetXPMData(fvwm2_big_xpm);

  /* Create a window to hold the banner */
  mysizehints.flags=
    USSize|USPosition|PWinGravity|PResizeInc|PBaseSize|PMinSize|PMaxSize;
  /* subtract one for the right/bottom border */
  mysizehints.width = view.attributes.width;
  mysizehints.height=view.attributes.height;
  mysizehints.width_inc = 1;
  mysizehints.height_inc = 1;
  mysizehints.base_height = mysizehints.height;
  mysizehints.base_width = mysizehints.width;
  mysizehints.min_height = mysizehints.height;
  mysizehints.min_width = mysizehints.width;
  mysizehints.max_height = mysizehints.height;
  mysizehints.max_width = mysizehints.width;
  mysizehints.win_gravity = NorthWestGravity;

  mysizehints.x = (ScreenWidth - view.attributes.width)/2;
  mysizehints.y = (ScreenHeight - view.attributes.height)/2;

  win = XCreateSimpleWindow(dpy,Root,mysizehints.x,mysizehints.y,
				 mysizehints.width,mysizehints.height,
				 0,fore_pix ,None);


  /* Set assorted info for the window */
  XSetTransientForHint(dpy,win,Root);
  wm_del_win = XInternAtom(dpy,"WM_DELETE_WINDOW",False);
  XSetWMProtocols(dpy,win,&wm_del_win,1);

  XSetWMNormalHints(dpy,win,&mysizehints);
  change_window_name("FvwmBanner");

  XSetWindowBackgroundPixmap(dpy,win,view.pixmap);
#ifdef SHAPE
  if(view.mask != None)
    XShapeCombineMask(dpy, win, ShapeBounding,0,0,view.mask, ShapeSet);
#endif
  XMapWindow(dpy,win);
  XSync(dpy,0);
#if 0
  usleep(timeout);
#else
  XSelectInput(dpy,win,ButtonReleaseMask);
  /* Display the window */
  value.tv_usec = timeout % 1000000;
  value.tv_sec = timeout / 1000000;
  while(1)
  {
    FD_ZERO(&in_fdset);
    FD_SET(x_fd,&in_fdset);

    if(!XPending(dpy))

      retval=select(fd_width,SELECT_TYPE_ARG234 &in_fdset, 0, 0, &value);

    if (retval==0)
    {
      XDestroyWindow(dpy,win);
      XSync(dpy,0);
      exit(0);
    }

    if(FD_ISSET(x_fd, &in_fdset))
    {
      /* read a packet */
      XNextEvent(dpy,&Event);
      switch(Event.type)
      {
        case ButtonRelease:
          XDestroyWindow(dpy,win);
          XSync(dpy,0);
          exit(0);
        case ClientMessage:
          if (Event.xclient.format==32 && Event.xclient.data.l[0]==wm_del_win)
          {
            XDestroyWindow(dpy,win);
            XSync(dpy,0);
            exit(0);
          }
        default:
          break;
      }
    }
  }
#endif /* 0 */
  return 0;
}
Exemple #11
0
/*
 *
 *  Procedure:
 *      main - start of module
 *
 */
int main(int argc, char **argv)
{
	char *display_name = NULL;
	char *tline;

	FlocaleInit(LC_CTYPE, "", "", "MvwmIdent");

	module = ParseModuleArgs(argc,argv,0); /* no alias */
	if (module == NULL)
	{
		fprintf(
			stderr, "MvwmIdent Version %s should only be executed"
			" by mvwm!\n", VERSION);
		exit(1);
	}

#ifdef HAVE_SIGACTION
	{
		struct sigaction  sigact;

		sigemptyset(&sigact.sa_mask);
		sigaddset(&sigact.sa_mask, SIGPIPE);
		sigaddset(&sigact.sa_mask, SIGTERM);
		sigaddset(&sigact.sa_mask, SIGQUIT);
		sigaddset(&sigact.sa_mask, SIGINT);
		sigaddset(&sigact.sa_mask, SIGHUP);
# ifdef SA_INTERRUPT
		sigact.sa_flags = SA_INTERRUPT;
# else
		sigact.sa_flags = 0;
# endif
		sigact.sa_handler = TerminateHandler;

		sigaction(SIGPIPE, &sigact, NULL);
		sigaction(SIGTERM, &sigact, NULL);
		sigaction(SIGQUIT, &sigact, NULL);
		sigaction(SIGINT,  &sigact, NULL);
		sigaction(SIGHUP,  &sigact, NULL);
	}
#else
	/* We don't have sigaction(), so fall back to less robust methods.  */
#ifdef USE_BSD_SIGNALS
	mvwmSetSignalMask( sigmask(SIGPIPE) |
			   sigmask(SIGTERM) |
			   sigmask(SIGQUIT) |
			   sigmask(SIGINT) |
			   sigmask(SIGHUP) );
#endif
	signal(SIGPIPE, TerminateHandler);
	signal(SIGTERM, TerminateHandler);
	signal(SIGQUIT, TerminateHandler);
	signal(SIGINT,  TerminateHandler);
	signal(SIGHUP,  TerminateHandler);
#ifdef HAVE_SIGINTERRUPT
	siginterrupt(SIGPIPE, 1);
	siginterrupt(SIGTERM, 1);
	siginterrupt(SIGQUIT, 1);
	siginterrupt(SIGINT, 1);
	siginterrupt(SIGHUP, 1);
#endif
#endif

	fd[0] = module->to_mvwm;
	fd[1] = module->from_mvwm;

	/* Open the Display */
	if (!(dpy = XOpenDisplay(display_name)))
	{
		fprintf(stderr,"%s: can't open display %s", module->name,
			XDisplayName(display_name));
		exit (1);
	}
	x_fd = XConnectionNumber(dpy);
	screen= DefaultScreen(dpy);
	Root = RootWindow(dpy, screen);
	XSetErrorHandler(ErrorHandler);

	flib_init_graphics(dpy);
	FlocaleAllocateWinString(&FwinString);

	SetMessageMask(fd, M_CONFIGURE_WINDOW | M_WINDOW_NAME | M_ICON_NAME
		       | M_RES_CLASS | M_RES_NAME | M_END_WINDOWLIST |
		       M_CONFIG_INFO | M_END_CONFIG_INFO | M_SENDCONFIG);
	SetMessageMask(fd, MX_PROPERTY_CHANGE);
	/* scan config file for set-up parameters */
	/* Colors and fonts */

	InitGetConfigLine(fd,CatString3("*",module->name,0));
	GetConfigLine(fd,&tline);

	while (tline != (char *)0)
	{
		if (strlen(tline) <= 1)
		{
			continue;
		}
		if (strncasecmp(tline,
				CatString3("*",module->name,0),
				module->namelen+1) == 0)
		{
			tline += (module->namelen +1);
			if (strncasecmp(tline, "Font", 4) == 0)
			{
				CopyStringWithQuotes(&font_string, &tline[4]);
			}
			else if (strncasecmp(tline, "Fore", 4) == 0)
			{
				CopyString(&ForeColor, &tline[4]);
				colorset = -1;
			}
			else if (strncasecmp(tline, "Back", 4) == 0)
			{
				CopyString(&BackColor, &tline[4]);
				colorset = -1;
			}
			else if (strncasecmp(tline, "Colorset", 8) == 0)
			{
				sscanf(&tline[8], "%d", &colorset);
				AllocColorset(colorset);
			}
			else if (strncasecmp(tline, "MinimalLayer", 12) == 0)
			{
				char *layer_str = PeekToken(&tline[12], NULL);
				if (layer_str == NULL)
				{
					minimal_layer = default_layer;
				}
				else if (sscanf(
					layer_str, "%d", &minimal_layer) != 1)
				{
					if (strncasecmp(
						layer_str, "none", 4) == 0)
					{
						minimal_layer = -1;
					}
					else
					{
						minimal_layer = default_layer;
					}
				}
			}
		}
		else if (strncasecmp(tline, "Colorset", 8) == 0)
		{
			LoadColorset(&tline[8]);
		}
		GetConfigLine(fd, &tline);
	}

	if(module->window == 0)
	{
		mvwmlib_get_target_window(
			dpy, screen, module->name, &(module->window), True);
	}

	fd_width = GetFdWidth();

	/* Create a list of all windows */
	/* Request a list of all windows,
	 * wait for ConfigureWindow packets */
	SendText(fd, "Send_WindowList", 0);

	/* tell mvwm we're running */
	SendFinishedStartupNotification(fd);
	if (module->window == Root)
	{
		exit(0);
	}

	Loop(fd);
	return 0;
}
Exemple #12
0
/***********************************************************************
 *
 *  Procedure:
 *	main - start of module
 *
 ***********************************************************************/
int main(int argc, char **argv)
{
  char *temp, *s;
  FILE *file;
  char *display_name = NULL;
  int Clength;
  char *tline;

  /* Save the program name for error messages and config parsing */
  temp = argv[0];
  s=strrchr(argv[0], '/');
  if (s != NULL)
    temp = s + 1;
  
  MyName = safemalloc(strlen(temp)+2);
  strcpy(MyName,"*");
  strcat(MyName, temp);
  Clength = strlen(MyName);

  if((argc != 6)&&(argc != 7))
    {
      fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName,
	      VERSION);
      exit(1);
    }

  /* Dead pipe == dead fvwm */
  signal (SIGPIPE, DeadPipe);  

  fd[0] = atoi(argv[1]);
  fd[1] = atoi(argv[2]);

  /* An application window may have already been selected - look for it */
  sscanf(argv[4],"%x",(unsigned int *)&app_win);

  /* Open the Display */
  if (!(dpy = XOpenDisplay(display_name))) 
    {
      fprintf(stderr,"%s: can't open display %s", MyName,
	      XDisplayName(display_name));
      exit (1);
    }
  x_fd = XConnectionNumber(dpy);
  screen= DefaultScreen(dpy);
  Root = RootWindow(dpy, screen);
  d_depth = DefaultDepth(dpy, screen);

  ScreenHeight = DisplayHeight(dpy,screen);
  ScreenWidth = DisplayWidth(dpy,screen);
  
  SetMessageMask(fd,M_CONFIGURE_WINDOW|M_WINDOW_NAME|M_ICON_NAME|
		 M_RES_CLASS| M_RES_NAME| M_END_WINDOWLIST|M_CONFIG_INFO|
		 M_END_CONFIG_INFO);
  /* scan config file for set-up parameters */
  /* Colors and fonts */

  GetConfigLine(fd,&tline);
  
  while(tline != (char *)0)
    {
      if(strlen(tline)>1)
	{
	  if(strncasecmp(tline, CatString3(MyName,"Font",""),Clength+4)==0)
	    {
	      CopyString(&font_string,&tline[Clength+4]);
	    }
	  else if(strncasecmp(tline,CatString3(MyName,"Fore",""),
				Clength+4)==0)
	    {
	      CopyString(&ForeColor,&tline[Clength+4]);
	    }
	  else if(strncasecmp(tline,CatString3(MyName, "Back",""),
				Clength+4)==0)
	    {
	      CopyString(&BackColor,&tline[Clength+4]);
	    }	
	}
      GetConfigLine(fd,&tline);
    }

  if(app_win == 0)
    GetTargetWindow(&app_win);

  fd_width = GetFdWidth();

  /* Create a list of all windows */
  /* Request a list of all windows,
   * wait for ConfigureWindow packets */
  SendInfo(fd,"Send_WindowList",0);

  Loop(fd);

  return 0;
}
int main(int argc, char *argv[])
{
#ifdef USERC
    char match[128];
    int config_line_count, len;
    char *config_line;
#endif

    console = fopen("/dev/console","w");
    if (!console) console = stderr;

    if (!(argv0 = strrchr(argv[0],'/')))
	argv0 = argv[0];
    else 
	++argv0;

    if (argc < 6) {
	fprintf(stderr,
#ifdef FVWM1
		"%s: module should be executed by fvwm only\n",
#else
		"%s: module should be executed by fvwm2 only\n",
#endif
		argv0);
	exit(-1);
    }

    fd[0] = atoi(argv[1]);
    fd[1] = atoi(argv[2]);

    if (!(dpy = XOpenDisplay(NULL))) {
	fprintf(console, "%s: couldn't open display %s\n",
		argv0,
		XDisplayName(NULL));
	exit(-1);
    }
    signal (SIGPIPE, DeadPipe);

    {
	int s = DefaultScreen(dpy);
	dwidth = DisplayWidth(dpy, s);
	dheight = DisplayHeight(dpy, s);
    }

    fd_width = GetFdWidth();
    
#ifdef USERC
    strcpy(match, "*");
    strcat(match, argv0);
    len = strlen(match);
#ifdef FVWM1
    if ((config_line = GetConfigLine(argv[3], match))) {
	char **args = NULL;
	config_line_count = parse_line(config_line, &args);
	parse_args("config args", 
		   config_line_count, args, 0);
	free(config_line);
	free(args);
    }
#else
    GetConfigLine(fd, &config_line);
    while (config_line != NULL) {
	if (strncmp(match,config_line,len)==0) {
	    char **args = NULL;
	    int cllen = strlen(config_line);
	    if (config_line[cllen - 1] == '\n')
		config_line[cllen - 1] = 0;
	    config_line_count = parse_line(config_line, &args);
	    parse_args("config args", 
		       config_line_count, args, 0);
	    free(args);
	}
	GetConfigLine(fd, &config_line);
    }
#endif /* FVWM1 */
#endif /* USERC */

    if (strcmp(argv0, "FvwmCascade") && (!strcmp(argv0, "FvwmTile") ||
	(argc >= 7 && !strcmp(argv[6], "-tile"))))
      {
	FvwmTile = 1;
	FvwmCascade = 0;
	resize = 1;
      }
    else
      {
	FvwmCascade = 1;
	FvwmTile = 0;
	resize = 0;
      }
    parse_args("module args", argc, argv, 6);

#ifdef FVWM1
    {
	char msg[256];
	sprintf(msg, "SET_MASK %lu\n",(unsigned long)(
	    M_CONFIGURE_WINDOW|
	    M_END_WINDOWLIST
	    ));
	SendInfo(fd,msg,0);
	
#ifdef FVWM1_MOVENULL
	/* avoid interactive placement in fvwm version 1 */
	if (!ofsx) ++ofsx;
	if (!ofsy) ++ofsy;
#endif
    }
#else
    SetMessageMask(fd,
		   M_CONFIGURE_WINDOW 
		   | M_END_WINDOWLIST
	);
#endif

    if (FvwmTile)
    {
      if (!maxx) maxx = dwidth;
      if (!maxy) maxy = dheight;
    }

    SendInfo(fd,"Send_WindowList",0);
    while (get_window());
    if (wins_count)
    {
      if (FvwmCascade)
	cascade_windows();
      else /* FvwmTile */
	tile_windows();
    }
    free_window_list(&wins);
    if (console != stderr)
	fclose(console);
    return 0;
}
Exemple #14
0
/***********************************************************************
 *
 *  Procedure:
 *	main - start of module
 *
 ***********************************************************************/
void main(int argc, char **argv)
{
  char *temp, *s, *cptr;
  char *display_name = NULL;
  int itemp,i;
  char line[100];
  char mask_mesg[50];

  /* Save our program  name - for error messages */
  temp = argv[0];
  s=strrchr(argv[0], '/');
  if (s != NULL)
    temp = s + 1;
  
  MyName = safemalloc(strlen(temp)+2);
  strcpy(MyName, temp);
  
  if((argc != 7)&&(argc != 6))
    {
      fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName,
	      PACKAGE_VERSION);
      exit(1);
    }
  if(argc != 7)
    { 
      fprintf(stderr,"%s Version %s requires an argument: %s n m\n",
	      MyName,PACKAGE_VERSION,MyName);
      fprintf(stderr,"   where desktops n through m are displayed\n");
      exit(1);
    }
  
  /* Dead pipe == Fvwm died */
  signal (SIGPIPE, DeadPipe);  
  
  fd[0] = atoi(argv[1]);
  fd[1] = atoi(argv[2]);
  
  fd_width = GetFdWidth();
  
  cptr = argv[6];
  while((isspace(*cptr))&&(*cptr != 0))cptr++;
  desk1 = atoi(cptr);
  while(!(isspace(*cptr))&&(*cptr != 0))cptr++;
  while((isspace(*cptr))&&(*cptr != 0))cptr++;
  desk2 = atoi(cptr);
  if(desk2 < desk1)
    {
      itemp = desk1;
      desk1 = desk2;
      desk2 = itemp;
    }
  ndesks = desk2 - desk1 + 1;
  
  Desks = (DeskInfo *)malloc(ndesks*sizeof(DeskInfo));
  for(i=0;i<ndesks;i++)
    {
      sprintf(line,"Desk %d",i+desk1);
      CopyString(&Desks[i].label,line);
    }
  
  /* Initialize X connection */
  if (!(dpy = XOpenDisplay(display_name))) 
    {
      fprintf(stderr,"%s: can't open display %s", MyName,
	      XDisplayName(display_name));
      exit (1);
    }
  x_fd = XConnectionNumber(dpy);
  
  Scr.screen= DefaultScreen(dpy);
  Scr.Root = RootWindow(dpy, Scr.screen);
  if(Scr.Root == None) 
    {
      fprintf(stderr,"%s: Screen %d is not valid ", MyName, (int)Scr.screen);
      exit(1);
    }
  Scr.d_depth = DefaultDepth(dpy, Scr.screen);

  sprintf(mask_mesg,"SET_MASK %lu\n",(unsigned long)(M_ADD_WINDOW|
    M_CONFIGURE_WINDOW|
    M_DESTROY_WINDOW|
    M_FOCUS_CHANGE|
    M_NEW_PAGE|
    M_NEW_DESK|
    M_RAISE_WINDOW|
    M_LOWER_WINDOW|
    M_ICONIFY|
    M_ICON_LOCATION|
    M_DEICONIFY|
    M_ICON_NAME|
    M_END_WINDOWLIST));
  SendInfo(fd,mask_mesg,0);

  ParseOptions(argv[3]);
  
  /* open a pager window */
  initialize_pager();
  
  /* Create a list of all windows */
  /* Request a list of all windows,
   * wait for ConfigureWindow packets */
  SendInfo(fd,"Send_WindowList",0);
  
  Loop(fd);
}
Exemple #15
0
int main(int argc, char **argv)
{
char *temp, *s;
	char*	displayName = NULL;

  commands=NULL;

  /* Save the program name for error messages and config parsing */
  temp = argv[0];
  s=strrchr(argv[0], '/');
  if (s != NULL)
    temp = s + 1;

  Module=temp;

  if((argc != 6)&&(argc != 7)) {
    fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",Module,
      VERSION);
   exit(1);
  }

  Fvwm_fd[0] = atoi(argv[1]);
  Fvwm_fd[1] = atoi(argv[2]);

  /* Grab the X display information now. */

	dpy = XOpenDisplay(displayName);
	if (!dpy)
	{
		fprintf(stderr, "%s:  unable to open display '%s'\n",
			Module, XDisplayName (displayName));
		exit (2);
	}
	screen = DefaultScreen(dpy);
	root = RootWindow(dpy, screen);

	/* Open a log file if necessary */
#	ifdef LOGFILE
		logFile = fopen(LOGFILE,"a");
		fprintf(logFile,"Initialising FvwmBacker\n");
#	endif

  signal (SIGPIPE, DeadPipe);

  /* Parse the config file */
  ParseConfig();

  fd_width = GetFdWidth();

  SetMessageMask(Fvwm_fd,M_NEW_DESK|M_CONFIG_INFO|M_END_CONFIG_INFO);

  /*
  ** we really only want the current desk, and window list sends it
  */
  SendInfo(Fvwm_fd,"Send_WindowList",0);


  /* Recieve all messages from Fvwm */
  EndLessLoop();

  /* Should never get here! */
  return 1;
}