Skip to content
Myr

main: --no-run-if-empty: display window as soon as we see _some_ input

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This allows us to have 'exit-immediately-if-empty' enabled at all times, while still displaying a window immediately once there's anything in STDIN. That is, we no longer hold off displaying the window until STDIN has been closed, even with --no-run-if-empty. This is implemented by always loading dmenu entries in a thread. This is better, since we now use a single code path for dmenu loading.

authored by Daniel Eklöf · committed by Daniel Eklöf · parent 6a340e5 · Browse files · 1 file+34 added−50 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+34 added−50 removed

  • other:+34 added−50 removed

1 file+34 added−50 removed

modified:main.c+34 added-50 removed
588 unmodified lines
589 case EVENT_APPS_ALL_LOADED: {590 /* Update matches list, then refresh the GUI */591 matches_set_applications(matches, apps);592593 if (event == EVENT_APPS_ALL_LOADED)593 if (event == EVENT_APPS_ALL_LOADED) {594 if (ctx->conf->dmenu.exit_immediately_if_empty && apps->count == 0)595 return false;596 matches_all_applications_loaded(matches);597 }598599#define UPDATE_MATCHES 1600601#if !UPDATE_MATCHES
41 unmodified lines
643644 while (true) {645 ssize_t bytes = read(fd, &event, sizeof(event));646 if (bytes == 0) {644 if (event != EVENT_INVALID)645 process_event(ctx, event);647 if (event != EVENT_INVALID) {648 if (!process_event(ctx, event))649 return false;650 }651 break;652 }653654 if (bytes != (ssize_t)sizeof(event)) {655 if (bytes < 0) {656 if (errno == EAGAIN) {652 if (event != EVENT_INVALID)653 process_event(ctx, event);657 if (event != EVENT_INVALID) {658 if (!process_event(ctx, event))659 return false;660 }661 break;662 }663 LOG_ERRNO("failed to read event FD");664 } else
2 unmodified lines
667 }668669 /* Coalesce multiple, identical events */670 if (last_event != EVENT_INVALID) {664 if (event != last_event)665 process_event(ctx, last_event);671 if (event != last_event) {672 if (!process_event(ctx, last_event))673 return false;674 }675 }676677 last_event = event;678 }
1155 unmodified lines
18341835 matches_set_applications(matches, apps);18361837 if (conf.dmenu.enabled) {1829 if (conf.dmenu.exit_immediately_if_empty) {1830 /*1831 * If no_run_if_empty is set, we *must* load the entries1832 * *before displaying the window.1833 */1834 dmenu_load_entries(apps, conf.dmenu.delim, -1, -1);1835 if (apps->count == 0)1836 goto out;18371838 if (conf.icons_enabled) {1839 themes = icon_load_theme(conf.icon_theme);1840 if (tll_length(themes) > 0)1841 LOG_INFO("theme: %s", tll_front(themes).name);1842 else1843 LOG_WARN("%s: icon theme not found", conf.icon_theme);1844 }18451846 matches_set_applications(matches, apps);1847 matches_update_no_delay(matches);1848 matches_selected_select(matches, select);1838 dmenu_abort_fd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);1839 if (dmenu_abort_fd < 0) {1840 LOG_ERRNO("failed to create event FD for dmenu mode");1841 goto out;1842 }18501851 else {1852 dmenu_abort_fd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);1853 if (dmenu_abort_fd < 0) {1854 LOG_ERRNO("failed to create event FD for dmenu mode");1855 goto out;1856 }1857 }1843 }18441845 struct context ctx = {1846 .conf = &conf,
19 unmodified lines
1866 matches_set_wayland(matches, wayl);1867 ctx.wayl = wayl;18681869 /* Create thread that will populate the application list */1885 if (!conf.dmenu.enabled || !conf.dmenu.exit_immediately_if_empty) {1886 if (pipe2(event_pipe, O_CLOEXEC | O_NONBLOCK) < 0) {1887 LOG_ERRNO("failed to create event pipe");1888 goto out;1889 }1870 if (pipe2(event_pipe, O_CLOEXEC | O_NONBLOCK) < 0) {1871 LOG_ERRNO("failed to create event pipe");1872 goto out;1873 }18741891 ctx.event_fd = event_pipe[1];1875 ctx.event_fd = event_pipe[1];18761893 if (!fdm_add(fdm, event_pipe[0], EPOLLIN, &fdm_apps_populated, &ctx))1894 goto out;1877 if (!fdm_add(fdm, event_pipe[0], EPOLLIN, &fdm_apps_populated, &ctx))1878 goto out;18791896 if (thrd_create(&app_thread_id, &populate_apps, &ctx) != thrd_success) {1897 LOG_ERR("failed to create thread");1898 goto out;1899 }19001901 join_app_thread = true;1880 if (thrd_create(&app_thread_id, &populate_apps, &ctx) != thrd_success) {1881 LOG_ERR("failed to create thread");1882 goto out;1883 }18841904 wayl_refresh(wayl);1885 join_app_thread = true;18861887 if (!conf.dmenu.exit_immediately_if_empty)1888 wayl_refresh(wayl);18891890 while (true) {1891 wayl_flush(wayl);1892 if (!fdm_poll(fdm))1893 break;
65 unmodified lines