Exemple #1
0
// --- Main Function ------------------------------------------------------
int main(int argc, char* argv[]) {

   if(argc == 2 && !strcmp("-v", argv[1]))
      die("INFO", "FusionWM-"VERSION);
   else if (argc != 1)
      die("INFO", "Usage: fusionwm [-v]");

   if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
      say("WARNING", "No locale support");

   if(!(gDisplay = XOpenDisplay(NULL)))
      die("ERROR", "Cannot open display");
   checkotherwm();

   // Setup
   setup();
   scan();
   all_monitors_apply_layout();

   // Main loop
   XEvent event;
   XSync(gDisplay, False);
   while (!gAboutToQuit && !XNextEvent(gDisplay, &event))
      if(handler[event.type])
         handler[event.type](&event); // call handler

   // Cleanup
   cleanup();
   XCloseDisplay(gDisplay);

   return EXIT_SUCCESS;
}
Exemple #2
0
void
init(const char *_cmd)
{
	x11_init();

	checkotherwm();

	cmd = _cmd;

	/* Setup the motion struct */
	motion = xcalloc(1, sizeof(struct motion));
	motion->type = NoMotion;

	sysinfo_init();

	clients_init();
	bars_init(settings()->barfont);
	launcher_init();

	/* Select wvents to handle */
	XSelectInput(dpy, root, WM_EVENT_MASK);

	/* Setup cursors */
	cursors_init();
	cursor_set(root, NormalCursor);

	/* Setup key bindings */
	keys = settings()->keys;
	key_init();
	key_grab_all(keys);

	/* Init atoms and EWMH */
	atoms_init();
	ewmh_init(wm_name);

	/* Init program lists */
	program_init(getenv("PATH"));

	/* Create monitors */
	create_monitors();

	/* Init ewmh desktop functionality */
	ewmh_root_set_number_of_desktops(
			monitor_count(mons) * N_WORKSPACES);
	ewmh_root_set_current_desktop(0);

	get_windows();

	set_environment();
}
Exemple #3
0
Fichier : main.c Projet : xiaq/hlwm
int main(int argc, char* argv[]) {
    parse_arguments(argc, argv);
    if(!(g_display = XOpenDisplay(NULL)))
        die("herbstluftwm: cannot open display\n");
    checkotherwm();
    // remove zombies on SIGCHLD
    sigaction_signal(SIGCHLD, remove_zombies);
    sigaction_signal(SIGINT,  handle_signal);
    sigaction_signal(SIGQUIT, handle_signal);
    sigaction_signal(SIGTERM, handle_signal);
    // set some globals
    g_screen = DefaultScreen(g_display);
    g_screen_width = DisplayWidth(g_display, g_screen);
    g_screen_height = DisplayHeight(g_display, g_screen);
    g_root = RootWindow(g_display, g_screen);
    XSelectInput(g_display, g_root, ROOT_EVENT_MASK);

    // initialize subsystems
    for (int i = 0; i < LENGTH(g_modules); i++) {
        g_modules[i].init();
    }
    fetch_settings();

    // setup
    ensure_monitors_are_available();
    scan();
    tag_force_update_flags();
    all_monitors_apply_layout();
    ewmh_update_all();
    execute_autostart_file();

    // main loop
    XEvent event;
    int x11_fd;
    fd_set in_fds;
    x11_fd = ConnectionNumber(g_display);
    while (!g_aboutToQuit) {
        FD_ZERO(&in_fds);
        FD_SET(x11_fd, &in_fds);
        // wait for an event or a signal
        select(x11_fd + 1, &in_fds, 0, 0, NULL);
        if (g_aboutToQuit) {
            break;
        }
        while (XPending(g_display)) {
            XNextEvent(g_display, &event);
            void (*handler) (XEvent*) = g_default_handler[event.type];
            if (handler != NULL) {
                handler(&event);
            }
        }
    }

    // destroy all subsystems
    for (int i = LENGTH(g_modules); i --> 0;) {
        g_modules[i].destroy();
    }
    XCloseDisplay(g_display);
    // check if we shall restart an other window manager
    if (g_exec_before_quit) {
        if (g_exec_args) {
            // do actual exec
            HSDebug("==> Doing wmexec to %s\n", g_exec_args[0]);
            execvp(g_exec_args[0], g_exec_args);
            fprintf(stderr, "herbstluftwm: execvp \"%s\"", g_exec_args[0]);
            perror(" failed");
        }
        // on failure or if no other wm given, then fall back
        HSDebug("==> Doing wmexec to %s\n", argv[0]);
        execvp(argv[0], argv);
        fprintf(stderr, "herbstluftwm: execvp \"%s\"", argv[1]);
        perror(" failed");
        return EXIT_FAILURE;
    }
    return EXIT_SUCCESS;
}