diff options
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 28 |
1 files changed, 10 insertions, 18 deletions
| @@ -35,15 +35,6 @@ typedef struct { | |||
| 35 | GList *cached_apps; | 35 | GList *cached_apps; |
| 36 | } State; | 36 | } State; |
| 37 | 37 | ||
| 38 | void draw_text(int x, int y, uint16_t fg, uint16_t bg, const char *str) { | ||
| 39 | while (*str) { | ||
| 40 | uint32_t uni; | ||
| 41 | tb_utf8_char_to_unicode(&uni, str); | ||
| 42 | tb_set_cell(x++, y, uni, fg, bg); | ||
| 43 | str += tb_utf8_char_length(*str); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | GList *get_apps_for_category(int category_idx) { | 38 | GList *get_apps_for_category(int category_idx) { |
| 48 | GList *apps = NULL; | 39 | GList *apps = NULL; |
| 49 | for (int m = 0; categories[category_idx].mimetypes[m] != NULL; ++m) { | 40 | for (int m = 0; categories[category_idx].mimetypes[m] != NULL; ++m) { |
| @@ -75,9 +66,9 @@ void update_cached_apps(State *state) { | |||
| 75 | } | 66 | } |
| 76 | 67 | ||
| 77 | void draw_titles() { | 68 | void draw_titles() { |
| 78 | draw_text(X_OFF_CATEGORIES, Y_OFF_TITLES, COLOR_TITLE, TB_DEFAULT, "CATEGORIES"); | 69 | tb_print(X_OFF_CATEGORIES, Y_OFF_TITLES, COLOR_TITLE, TB_DEFAULT, "CATEGORIES"); |
| 79 | draw_text(X_OFF_APPS, Y_OFF_TITLES, COLOR_TITLE, TB_DEFAULT, "APPLICATIONS"); | 70 | tb_print(X_OFF_APPS, Y_OFF_TITLES, COLOR_TITLE, TB_DEFAULT, "APPLICATIONS"); |
| 80 | draw_text(X_OFF_FILE, Y_OFF_TITLES, COLOR_TITLE, TB_DEFAULT, "FILE"); | 71 | tb_print(X_OFF_FILE, Y_OFF_TITLES, COLOR_TITLE, TB_DEFAULT, "FILE"); |
| 81 | } | 72 | } |
| 82 | 73 | ||
| 83 | void draw_categories(State *state) { | 74 | void draw_categories(State *state) { |
| @@ -90,7 +81,7 @@ void draw_categories(State *state) { | |||
| 90 | fg = COLOR_SELECTED; | 81 | fg = COLOR_SELECTED; |
| 91 | bg = COLOR_DEFAULT; | 82 | bg = COLOR_DEFAULT; |
| 92 | } | 83 | } |
| 93 | draw_text(X_OFF_CATEGORIES, Y_OFF_START + i, fg, bg, categories[i].name); | 84 | tb_print(X_OFF_CATEGORIES, Y_OFF_START + i, fg, bg, categories[i].name); |
| 94 | } | 85 | } |
| 95 | } | 86 | } |
| 96 | 87 | ||
| @@ -106,10 +97,11 @@ void draw_apps_list(State *state) { | |||
| 106 | break; | 97 | break; |
| 107 | } | 98 | } |
| 108 | } | 99 | } |
| 109 | if (!found) | 100 | if (!found) { |
| 110 | defaults = g_list_append(defaults, d); | 101 | defaults = g_list_append(defaults, d); |
| 111 | else | 102 | } else { |
| 112 | g_object_unref(d); | 103 | g_object_unref(d); |
| 104 | } | ||
| 113 | } | 105 | } |
| 114 | } | 106 | } |
| 115 | 107 | ||
| @@ -132,12 +124,12 @@ void draw_apps_list(State *state) { | |||
| 132 | 124 | ||
| 133 | char name[256]; | 125 | char name[256]; |
| 134 | snprintf(name, sizeof(name), "%s %s", is_default ? "*" : " ", g_app_info_get_name(app)); | 126 | snprintf(name, sizeof(name), "%s %s", is_default ? "*" : " ", g_app_info_get_name(app)); |
| 135 | draw_text(X_OFF_APPS, Y_OFF_START + i, fg, bg, name); | 127 | tb_print(X_OFF_APPS, Y_OFF_START + i, fg, bg, name); |
| 136 | 128 | ||
| 137 | if (G_IS_DESKTOP_APP_INFO(app)) { | 129 | if (G_IS_DESKTOP_APP_INFO(app)) { |
| 138 | const char *filename = g_desktop_app_info_get_filename(G_DESKTOP_APP_INFO(app)); | 130 | const char *filename = g_desktop_app_info_get_filename(G_DESKTOP_APP_INFO(app)); |
| 139 | if (filename) { | 131 | if (filename) { |
| 140 | draw_text(X_OFF_FILE, Y_OFF_START + i, COLOR_DIM, bg, filename); | 132 | tb_print(X_OFF_FILE, Y_OFF_START + i, COLOR_DIM, bg, filename); |
| 141 | } | 133 | } |
| 142 | } | 134 | } |
| 143 | } | 135 | } |
| @@ -155,7 +147,7 @@ void draw(State *state) { | |||
| 155 | if (strncmp(state->message, "Failed", 6) == 0) { | 147 | if (strncmp(state->message, "Failed", 6) == 0) { |
| 156 | msg_col = COLOR_ERROR; | 148 | msg_col = COLOR_ERROR; |
| 157 | } | 149 | } |
| 158 | draw_text(X_OFF_CATEGORIES, tb_height() - 1, msg_col, TB_DEFAULT, state->message); | 150 | tb_print(X_OFF_CATEGORIES, tb_height() - 1, msg_col, TB_DEFAULT, state->message); |
| 159 | } | 151 | } |
| 160 | 152 | ||
| 161 | tb_present(); | 153 | tb_present(); |
