X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=i3-config-wizard%2Fmain.c;h=0c8c705a784024429238ff98055f1f945d20d642;hb=d080f58299ebed9300ca6f79d30c955d3e928421;hp=cbea624e330bb0f7ce56dc2a9da23aeb9850a18a;hpb=865bd462b4d71c6e0d5edcae148a5b6a6c208ffb;p=i3%2Fi3 diff --git a/i3-config-wizard/main.c b/i3-config-wizard/main.c index cbea624e..0c8c705a 100644 --- a/i3-config-wizard/main.c +++ b/i3-config-wizard/main.c @@ -48,6 +48,9 @@ #include #include +#define SN_API_NOT_YET_FROZEN 1 +#include + #include #include #include @@ -92,7 +95,7 @@ static xcb_get_modifier_mapping_reply_t *modmap_reply; static i3Font font; static i3Font bold_font; static int char_width; -static char *socket_path; +static char *socket_path = NULL; static xcb_window_t win; static surface_t surface; static xcb_key_symbols_t *symbols; @@ -293,6 +296,7 @@ static char *next_state(const cmdp_token *token) { } sasprintf(&res, "bindsym %s%s%s %s%s\n", (modifiers == NULL ? "" : modrep), (modifiers == NULL ? "" : "+"), str, (release == NULL ? "" : release), get_string("command")); clear_stack(); + free(modrep); return res; } @@ -631,8 +635,6 @@ static void handle_button_press(xcb_button_press_event_t *event) { modifier = MOD_Mod1; handle_expose(); } - - return; } /* @@ -742,14 +744,15 @@ static void finish() { int main(int argc, char *argv[]) { char *xdg_config_home; - socket_path = getenv("I3SOCK"); char *pattern = "pango:monospace 8"; char *patternbold = "pango:monospace bold 8"; int o, option_index = 0; + bool headless_run = false; static struct option long_options[] = { {"socket", required_argument, 0, 's'}, {"version", no_argument, 0, 'v'}, + {"modifier", required_argument, 0, 'm'}, {"limit", required_argument, 0, 'l'}, {"prompt", required_argument, 0, 'P'}, {"prefix", required_argument, 0, 'p'}, @@ -757,7 +760,7 @@ int main(int argc, char *argv[]) { {"help", no_argument, 0, 'h'}, {0, 0, 0, 0}}; - char *options_string = "s:vh"; + char *options_string = "sm:vh"; while ((o = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1) { switch (o) { @@ -768,9 +771,18 @@ int main(int argc, char *argv[]) { case 'v': printf("i3-config-wizard " I3_VERSION "\n"); return 0; + case 'm': + headless_run = true; + if (strcmp(optarg, "alt") == 0) + modifier = MOD_Mod1; + else if (strcmp(optarg, "win") == 0) + modifier = MOD_Mod4; + else + err(EXIT_FAILURE, "Invalid modifier key %s", optarg); + break; case 'h': printf("i3-config-wizard " I3_VERSION "\n"); - printf("i3-config-wizard [-s ] [-v]\n"); + printf("i3-config-wizard [-s ] [-m win|alt] [-v] [-h]\n"); return 0; } } @@ -822,23 +834,27 @@ int main(int argc, char *argv[]) { &xkb_base_error) != 1) errx(EXIT_FAILURE, "Could not setup XKB extension."); - if (socket_path == NULL) - socket_path = root_atom_contents("I3_SOCKET_PATH", conn, screen); - - if (socket_path == NULL) - socket_path = "/tmp/i3-ipc.sock"; - keysyms = xcb_key_symbols_alloc(conn); xcb_get_modifier_mapping_cookie_t modmap_cookie; modmap_cookie = xcb_get_modifier_mapping(conn); symbols = xcb_key_symbols_alloc(conn); + if (headless_run) { + finish(); + return 0; + } + /* Place requests for the atoms we need as soon as possible */ #define xmacro(atom) \ xcb_intern_atom_cookie_t atom##_cookie = xcb_intern_atom(conn, 0, strlen(#atom), #atom); #include "atoms.xmacro" #undef xmacro + /* Init startup notification. */ + SnDisplay *sndisplay = sn_xcb_display_new(conn, NULL, NULL); + SnLauncheeContext *sncontext = sn_launchee_context_new_from_environment(sndisplay, screen); + sn_display_unref(sndisplay); + root_screen = xcb_aux_get_screen(conn, screen); root = root_screen->root; @@ -871,6 +887,9 @@ int main(int argc, char *argv[]) { 0, /* back pixel: black */ XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS}); + if (sncontext) { + sn_launchee_context_setup_window(sncontext, win); + } /* Map the window (make it visible) */ xcb_map_window(conn, win); @@ -932,6 +951,12 @@ int main(int argc, char *argv[]) { exit(-1); } + /* Startup complete. */ + if (sncontext) { + sn_launchee_context_complete(sncontext); + sn_launchee_context_unref(sncontext); + } + xcb_flush(conn); xcb_generic_event_t *event; @@ -944,13 +969,12 @@ int main(int argc, char *argv[]) { /* Strip off the highest bit (set if the event is generated) */ int type = (event->response_type & 0x7F); + /* TODO: handle mappingnotify */ switch (type) { case XCB_KEY_PRESS: handle_key_press(NULL, conn, (xcb_key_press_event_t *)event); break; - /* TODO: handle mappingnotify */ - case XCB_BUTTON_PRESS: handle_button_press((xcb_button_press_event_t *)event); break;