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; }
/****************************************************************************** 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; }
/****************************************************************************** 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; }
/*********************************************************************** * * 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; }