diff --git a/src/compton.c b/src/compton.c index 6be7330..9fdeb8f 100644 --- a/src/compton.c +++ b/src/compton.c @@ -2491,7 +2491,8 @@ reset_enable(EV_P_ ev_signal *w, int revents) { * @param argv commandline arguments */ static session_t * -session_init(session_t *ps_old, int argc, char **argv) { +session_init(int argc, char **argv, Display *dpy, bool all_xerrors, + const char *config_file) { static const session_t s_def = { .backend_data = NULL, .dpy = NULL, @@ -2513,7 +2514,6 @@ session_init(session_t *ps_old, int argc, char **argv) { .glx_prog_win = GLX_PROG_MAIN_INIT, #endif .o = { - .config_file = NULL, .backend = BKEND_XRENDER, .glx_no_stencil = false, .mark_wmwin_focused = false, @@ -2671,26 +2671,12 @@ session_init(session_t *ps_old, int argc, char **argv) { ps->ignore_tail = &ps->ignore_head; gettimeofday(&ps->time_start, NULL); - int exit_code; - if (get_early_config(argc, argv, &ps->o.config_file, &ps->o.show_all_xerrors, - &exit_code)) { - exit(exit_code); - } + ps->o.show_all_xerrors = all_xerrors; - // Inherit old Display if possible, primarily for resource leak checking - if (ps_old && ps_old->dpy) - ps->dpy = ps_old->dpy; - - // Open Display - if (!ps->dpy) { - ps->dpy = XOpenDisplay(NULL); - if (!ps->dpy) { - log_fatal("Can't open display."); - exit(1); - } - XSetEventQueueOwner(ps->dpy, XCBOwnsEventQueue); - } + // Use the same Display across reset, primarily for resource leak checking + ps->dpy = dpy; ps->c = XGetXCBConnection(ps->dpy); + const xcb_query_extension_reply_t *ext_info; XSetErrorHandler(xerror); @@ -2779,10 +2765,10 @@ session_init(session_t *ps_old, int argc, char **argv) { // Parse configuration file win_option_mask_t winopt_mask[NUM_WINTYPES] = {{0}}; bool shadow_enabled = false, fading_enable = false, hasneg = false; - char *config_file = parse_config(&ps->o, ps->o.config_file, &shadow_enabled, - &fading_enable, &hasneg, winopt_mask); - free(ps->o.config_file); - ps->o.config_file = config_file; + char *config_file_to_free = NULL; + config_file = config_file_to_free = + parse_config(&ps->o, config_file, &shadow_enabled, + &fading_enable, &hasneg, winopt_mask); // Parse all of the rest command line options get_cfg(&ps->o, argc, argv, shadow_enabled, fading_enable, hasneg, winopt_mask); @@ -2909,9 +2895,11 @@ session_init(session_t *ps_old, int argc, char **argv) { } if (ps->o.print_diagnostics) { - print_diagnostics(ps); + print_diagnostics(ps, config_file); + free(config_file_to_free); exit(0); } + free(config_file_to_free); if (bkend_use_glx(ps)) { auto glx_logger = glx_string_marker_logger_new(); @@ -3052,11 +3040,6 @@ session_init(session_t *ps_old, int argc, char **argv) { } write_pid(ps); - - // Free the old session - if (ps_old) - free(ps_old); - return ps; } @@ -3151,7 +3134,6 @@ session_destroy(session_t *ps) { pixman_region32_fini(&ps->screen_reg); free(ps->expose_rects); - free(ps->o.config_file); free(ps->o.write_pid_path); free(ps->o.logpath); for (int i = 0; i < MAX_BLUR_PASS; ++i) { @@ -3248,6 +3230,13 @@ main(int argc, char **argv) { // correctly setlocale(LC_ALL, ""); + int exit_code; + char *config_file = NULL; + bool all_xerrors = 0; + if (get_early_config(argc, argv, &config_file, &all_xerrors, &exit_code)) { + return exit_code; + } + sigset_t sigmask; sigemptyset(&sigmask); const struct sigaction int_action = { @@ -3258,21 +3247,30 @@ main(int argc, char **argv) { sigaction(SIGINT, &int_action, NULL); // Main loop - session_t *ps_old = ps_g; bool quit = false; - while (!quit) { - ps_g = session_init(ps_old, argc, argv); + Display *dpy = XOpenDisplay(NULL); + if (!dpy) { + log_fatal("Can't open display."); + return 1; + } + XSetEventQueueOwner(dpy, XCBOwnsEventQueue); + + do { + ps_g = session_init(argc, argv, dpy, all_xerrors, config_file); if (!ps_g) { log_fatal("Failed to create new compton session."); return 1; } session_run(ps_g); - ps_old = ps_g; quit = ps_g->quit; session_destroy(ps_g); - } + free(ps_g); + } while (!quit); - free(ps_g); + if (dpy) { + XCloseDisplay(dpy); + } + free(config_file); return 0; } diff --git a/src/config.h b/src/config.h index cfe2460..d87a1b5 100644 --- a/src/config.h +++ b/src/config.h @@ -78,8 +78,6 @@ typedef struct options_t { bool monitor_repaint; bool print_diagnostics; // === General === - /// The configuration file we used. - char *config_file; /// Path to write PID to. char *write_pid_path; /// The backend in use. diff --git a/src/dbus.c b/src/dbus.c index 1d36cfb..edc1af8 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -1024,7 +1024,7 @@ cdbus_process_opts_get(session_t *ps, DBusMessage *msg) { return true; } - cdbus_m_opts_get_do(config_file, cdbus_reply_string); + cdbus_m_opts_get_stub(config_file, cdbus_reply_string, "Unknown"); cdbus_m_opts_get_do(write_pid_path, cdbus_reply_string); cdbus_m_opts_get_do(mark_wmwin_focused, cdbus_reply_bool); cdbus_m_opts_get_do(mark_ovredir_focused, cdbus_reply_bool); diff --git a/src/diagnostic.c b/src/diagnostic.c index edb3c53..378575c 100644 --- a/src/diagnostic.c +++ b/src/diagnostic.c @@ -8,7 +8,7 @@ #include "config.h" #include "common.h" -void print_diagnostics(session_t *ps) { +void print_diagnostics(session_t *ps, const char *config_file) { printf("**Version:** " COMPTON_VERSION "\n"); //printf("**CFLAGS:** %s\n", "??"); printf("\n### Extensions:\n\n"); @@ -21,7 +21,7 @@ void print_diagnostics(session_t *ps) { #ifdef __FAST_MATH__ printf("* Fast Math: Yes\n"); #endif - printf("* Config file used: %s\n", ps->o.config_file ?: "None"); + printf("* Config file used: %s\n", config_file ?: "None"); } // vim: set noet sw=8 ts=8 : diff --git a/src/diagnostic.h b/src/diagnostic.h index dd5a964..28db0ee 100644 --- a/src/diagnostic.h +++ b/src/diagnostic.h @@ -5,4 +5,4 @@ typedef struct session session_t; -void print_diagnostics(session_t *); +void print_diagnostics(session_t *, const char *config_file);