diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/bemenu.h | 26 | ||||
| -rw-r--r-- | lib/internal.h | 4 | ||||
| -rw-r--r-- | lib/library.c | 8 | ||||
| -rw-r--r-- | lib/menu.c | 18 | ||||
| -rw-r--r-- | lib/renderers/curses/curses.c | 2 | ||||
| -rw-r--r-- | lib/renderers/wayland/wayland.c | 2 | ||||
| -rw-r--r-- | lib/renderers/x11/x11.c | 2 | 
7 files changed, 35 insertions, 27 deletions
diff --git a/lib/bemenu.h b/lib/bemenu.h index 63cf634..54d82f9 100644 --- a/lib/bemenu.h +++ b/lib/bemenu.h @@ -44,8 +44,10 @@ struct bm_item;   * @{ */  /** - * Init bemenu. - * Loads up the renderers. + * Init bemenu, loads up the renderers. + * + * You can force single renderer with BEMENU_RENDERER env variable, + * and directory containing renderers with BEMENU_RENDERERS env variable.   *   * @return true on success, false on failure.   */ @@ -85,13 +87,7 @@ const char* bm_version(void);  /**   * Prioritories for renderer plugins.   */ -enum bm_prioritory { -    /** -     * Do not use this in renderers. -     * This flag is for bm_menu_new, if any renderer is fine. -     */ -    BM_PRIO_ANY, - +enum bm_priorty {      /**       * Renderer runs in terminal.       */ @@ -112,12 +108,12 @@ enum bm_prioritory {  const char* bm_renderer_get_name(const struct bm_renderer *renderer);  /** - * Get prioritory of the renderer. + * Get priorty of the renderer.   *   * @param renderer bm_renderer instance. - * @return bm_prioritory enum value. + * @return bm_priorty enum value.   */ -enum bm_prioritory bm_renderer_get_prioritory(const struct bm_renderer *renderer); +enum bm_priorty bm_renderer_get_priorty(const struct bm_renderer *renderer);  /**   * @} Renderer */ @@ -210,11 +206,13 @@ enum bm_color {  /**   * Create new bm_menu instance.   * + * If **NULL** is used as renderer, auto-detection will be used or the renderer with the name pointed by BEMENU_BACKEND env variable. + * It's good idea to use NULL, if you want user to have control over the renderer with this env variable. + *   * @param renderer Name of renderer to be used for this instance, pass **NULL** for auto-detection. - * @param prioritory @link ::bm_prioritory @endlink enum for which kind of renderer is wanted. Pass BM_PRIO_ANY, for anything.   * @return bm_menu for new menu instance, **NULL** if creation failed.   */ -struct bm_menu* bm_menu_new(const char *renderer, enum bm_prioritory prioritory); +struct bm_menu* bm_menu_new(const char *renderer);  /**   * Release bm_menu instance. diff --git a/lib/internal.h b/lib/internal.h index 112e7bd..7b71eb4 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -93,10 +93,10 @@ struct render_api {      const char *version;      /** -     * Prioritory of the plugin. +     * Priorty of the plugin.       * Terminal renderers should be first, then graphicals.       */ -    enum bm_prioritory prioritory; +    enum bm_priorty priorty;  };  /** diff --git a/lib/library.c b/lib/library.c index 2dc59fc..02c2af8 100644 --- a/lib/library.c +++ b/lib/library.c @@ -67,7 +67,7 @@ static int  compare(const void *a, const void *b)  {      const struct bm_renderer *ra = *(struct bm_renderer**)a, *rb = *(struct bm_renderer**)b; -    return (ra->api.prioritory > rb->api.prioritory); +    return (ra->api.priorty > rb->api.priorty);  }  static bool @@ -180,11 +180,11 @@ bm_renderer_get_name(const struct bm_renderer *renderer)      return renderer->name;  } -enum bm_prioritory -bm_renderer_get_prioritory(const struct bm_renderer *renderer) +enum bm_priorty +bm_renderer_get_priorty(const struct bm_renderer *renderer)  {      assert(renderer); -    return renderer->api.prioritory; +    return renderer->api.priorty;  }  /* vim: set ts=8 sw=4 tw=0 :*/ @@ -49,7 +49,7 @@ bm_menu_item_is_selected(const struct bm_menu *menu, const struct bm_item *item)  }  struct bm_menu* -bm_menu_new(const char *renderer, enum bm_prioritory prioritory) +bm_menu_new(const char *renderer)  {      struct bm_menu *menu;      if (!(menu = calloc(1, sizeof(struct bm_menu)))) @@ -58,14 +58,24 @@ bm_menu_new(const char *renderer, enum bm_prioritory prioritory)      uint32_t count;      const struct bm_renderer **renderers = bm_get_renderers(&count); +    const char *name = secure_getenv("BEMENU_BACKEND"); +    name = (name && strlen(name) > 0 ? name : NULL); +      for (uint32_t i = 0; i < count; ++i) { -        if (prioritory != BM_PRIO_ANY && renderers[i]->api.prioritory != prioritory) +        if (!name && !renderer && renderers[i]->api.priorty != BM_PRIO_GUI)              continue; -        if (renderer && strcmp(renderer, renderers[i]->name)) +        if ((renderer && strcmp(renderer, renderers[i]->name)) || (name && strcmp(name, renderers[i]->name)))              continue; -        if (renderers[i]->api.prioritory == BM_PRIO_TERMINAL) { +        if (renderers[i]->api.priorty == BM_PRIO_TERMINAL) { +            /** +             * Some sanity checks that we are in terminal. +             * These however are not reliable, thus we don't auto-detect terminal based renderers. +             * These will be only used when explicitly requested. +             * +             * Launching terminal based menu instance at background is not a good idea. +             */              const char *term = getenv("TERM");              if (!term || !strlen(term) || getppid() == 1)                  continue; diff --git a/lib/renderers/curses/curses.c b/lib/renderers/curses/curses.c index 78449ac..af54846 100644 --- a/lib/renderers/curses/curses.c +++ b/lib/renderers/curses/curses.c @@ -358,7 +358,7 @@ register_renderer(struct render_api *api)      api->get_displayed_count = get_displayed_count;      api->poll_key = poll_key;      api->render = render; -    api->prioritory = BM_PRIO_TERMINAL; +    api->priorty = BM_PRIO_TERMINAL;      api->version = BM_PLUGIN_VERSION;      return "curses";  } diff --git a/lib/renderers/wayland/wayland.c b/lib/renderers/wayland/wayland.c index a3866c6..252d86f 100644 --- a/lib/renderers/wayland/wayland.c +++ b/lib/renderers/wayland/wayland.c @@ -234,7 +234,7 @@ register_renderer(struct render_api *api)      api->get_displayed_count = get_displayed_count;      api->poll_key = poll_key;      api->render = render; -    api->prioritory = BM_PRIO_GUI; +    api->priorty = BM_PRIO_GUI;      api->version = BM_PLUGIN_VERSION;      return "wayland";  } diff --git a/lib/renderers/x11/x11.c b/lib/renderers/x11/x11.c index 3e29efe..81ccc5d 100644 --- a/lib/renderers/x11/x11.c +++ b/lib/renderers/x11/x11.c @@ -226,7 +226,7 @@ register_renderer(struct render_api *api)      api->set_bottom = set_bottom;      api->set_monitor = set_monitor;      api->grab_keyboard = grab_keyboard; -    api->prioritory = BM_PRIO_GUI; +    api->priorty = BM_PRIO_GUI;      api->version = BM_PLUGIN_VERSION;      return "x11";  }  | 
