2 #include <stdio.h> /* for FILE etc */
3 #include <stdlib.h> /* for malloc */
4 #include <unistd.h> /* for unlink */
5 #include <limits.h> /* for PATH_MAX */
8 #define __USE_GNU /* for strcasestr */
9 #include <string.h> /* for making ftw.h happy */
15 #include "SDL_audio.h"
16 #include "SDL_image.h"
18 #include "SDL_gfxPrimitives.h"
19 #include "SDL_rotozoom.h"
20 #include "SDL_thread.h"
24 #include "pnd_logger.h"
26 #include "pnd_container.h"
27 #include "pnd_discovery.h"
29 #include "pnd_device.h"
30 #include "../lib/pnd_pathiter.h"
31 #include "pnd_utility.h"
32 #include "pnd_pndfiles.h"
33 #include "pnd_notify.h"
34 #include "pnd_dbusnotify.h"
40 #include "mmwrapcmd.h"
42 #include "mmui_context.h"
43 #include "freedesktop_cats.h"
44 #include "mmcustom_cats.h"
46 #define CHANGED_NOTHING (0)
47 #define CHANGED_CATEGORY (1<<0) /* changed to different category */
48 #define CHANGED_SELECTION (1<<1) /* changed app selection */
49 #define CHANGED_DATAUPDATE (1<<2) /* deferred preview pic or icon came in */
50 #define CHANGED_APPRELOAD (1<<3) /* new set of applications entirely */
51 #define CHANGED_EVERYTHING (1<<4) /* redraw it all! */
52 unsigned int render_mask = CHANGED_EVERYTHING;
54 SDL_Thread *g_icon_thread = NULL;
55 unsigned char g_icon_thread_stop = 0; /* if !0 means thread should stop and maim app may block until it goes back to 0.. */
56 unsigned char g_icon_thread_busy = 0; /* if !0 means thread is running right now */
58 #define MIMETYPE_EXE "/usr/bin/file" /* check for file type prior to invocation */
62 SDL_Surface *sdl_realscreen = NULL;
63 unsigned int sdl_ticks = 0;
64 SDL_Thread *g_preview_thread = NULL;
65 SDL_Thread *g_timer_thread = NULL;
67 enum { sdl_user_ticker = 0,
68 sdl_user_finishedpreview = 1,
69 sdl_user_finishedicon = 2,
75 unsigned short int g_scale = 1; // 1 == noscale
77 SDL_Surface *g_imgcache [ IMG_MAX ];
79 TTF_Font *g_big_font = NULL;
80 TTF_Font *g_grid_font = NULL;
81 TTF_Font *g_detailtext_font = NULL;
82 TTF_Font *g_tab_font = NULL;
84 extern pnd_conf_handle g_conf;
86 /* current display state
88 int ui_rows_scrolled_down = 0; // number of rows that should be missing from top of the display
89 mm_appref_t *ui_selected = NULL;
90 unsigned char ui_category = 0; // current category
91 unsigned char ui_catshift = 0; // how many cats are offscreen to the left
92 ui_context_t ui_display_context; // display paramaters: see mmui_context.h
93 unsigned char ui_detail_hidden = 0; // if >0, detail panel is hidden
94 // FUTURE: If multiple panels can be shown/hidden, convert ui_detail_hidden to a bitmask
96 static SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ); // height -1 means ignore
97 static int ui_selected_index ( void );
98 static void ui_start_defered_icon_thread ( void );
99 static void ui_stop_defered_icon_thread ( void );
101 unsigned char ui_setup ( void ) {
106 SDL_Init ( SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE );
108 SDL_JoystickOpen ( 0 ); // turn on joy-0
110 SDL_WM_SetCaption ( "mmenu", "mmenu" );
112 // hide the mouse cursor if we can
113 if ( SDL_ShowCursor ( -1 ) == 1 ) {
114 SDL_ShowCursor ( 0 );
120 unsigned int svm = SDL_SWSURFACE /*| SDL_FULLSCREEN*/ /* 0*/;
121 if ( pnd_conf_get_as_int_d ( g_conf, "display.fullscreen", 0 ) > 0 ) {
122 svm |= SDL_FULLSCREEN;
126 SDL_SetVideoMode ( 800 * g_scale, 480 * g_scale, 16 /*bpp*/, svm );
128 if ( ! sdl_realscreen ) {
129 pnd_log ( pndn_error, "ERROR: Couldn't open SDL real screen; dieing." );
133 pnd_log ( pndn_debug, "Pixel format:" );
134 pnd_log ( pndn_debug, "bpp b: %u\n", sdl_realscreen -> format -> BitsPerPixel );
135 pnd_log ( pndn_debug, "bpp B: %u\n", sdl_realscreen -> format -> BytesPerPixel );
136 pnd_log ( pndn_debug, "R mask: %08x\n", sdl_realscreen -> format -> Rmask );
137 pnd_log ( pndn_debug, "G mask: %08x\n", sdl_realscreen -> format -> Gmask );
138 pnd_log ( pndn_debug, "B mask: %08x\n", sdl_realscreen -> format -> Bmask );
144 /* Set 16-bit stereo audio at 22Khz */
145 fmt.freq = 44100; //22050;
146 fmt.format = AUDIO_S16; //AUDIO_S16;
148 fmt.samples = 2048; /* A good value for games */
149 fmt.callback = mixaudio;
152 /* Open the audio device and start playing sound! */
153 if ( SDL_OpenAudio ( &fmt, NULL ) < 0 ) {
154 zotlog ( "Unable to open audio: %s\n", SDL_GetError() );
158 SDL_PauseAudio ( 0 );
163 SDL_EnableKeyRepeat ( 500, 125 /* 150 */ );
166 //IMG_Init ( IMG_INIT_JPG | IMG_INIT_PNG );
172 if ( TTF_Init() == -1 ) {
173 pnd_log ( pndn_error, "ERROR: Couldn't set up SDL TTF lib\n" );
174 return ( 0 ); // couldn't set up SDL TTF
177 char fullpath [ PATH_MAX ];
179 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "minimenu.font" ) );
180 g_big_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
181 if ( ! g_big_font ) {
182 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
183 pnd_conf_get_as_char ( g_conf, "minimenu.font" ), pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
184 return ( 0 ); // couldn't set up SDL TTF
188 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "grid.font" ) );
189 g_grid_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
190 if ( ! g_grid_font ) {
191 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
192 pnd_conf_get_as_char ( g_conf, "grid.font" ), pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
193 return ( 0 ); // couldn't set up SDL TTF
197 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "detailtext.font" ) );
198 g_detailtext_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
199 if ( ! g_detailtext_font ) {
200 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
201 pnd_conf_get_as_char ( g_conf, "detailtext.font" ), pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
202 return ( 0 ); // couldn't set up SDL TTF
206 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "tabs.font" ) );
207 g_tab_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
208 if ( ! g_tab_font ) {
209 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
210 pnd_conf_get_as_char ( g_conf, "tabs.font" ), pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
211 return ( 0 ); // couldn't set up SDL TTF
214 // determine display context
215 if ( pnd_conf_get_as_int_d ( g_conf, "display.show_detail_pane", 1 ) > 0 ) {
216 ui_detail_hidden = 0;
218 ui_detail_hidden = 1;
220 ui_recache_context ( &ui_display_context );
225 mm_imgcache_t g_imagecache [ IMG_TRUEMAX ] = {
226 { IMG_BACKGROUND_800480, "graphics.IMG_BACKGROUND_800480" },
227 { IMG_BACKGROUND_TABMASK, "graphics.IMG_BACKGROUND_TABMASK" },
228 { IMG_DETAIL_PANEL, "graphics.IMG_DETAIL_PANEL" },
229 { IMG_DETAIL_BG, "graphics.IMG_DETAIL_BG" },
230 { IMG_SELECTED_ALPHAMASK, "graphics.IMG_SELECTED_ALPHAMASK" },
231 { IMG_TAB_SEL, "graphics.IMG_TAB_SEL" },
232 { IMG_TAB_SEL_L, "graphics.IMG_TAB_SEL_L" },
233 { IMG_TAB_SEL_R, "graphics.IMG_TAB_SEL_R" },
234 { IMG_TAB_UNSEL, "graphics.IMG_TAB_UNSEL" },
235 { IMG_TAB_UNSEL_L, "graphics.IMG_TAB_UNSEL_L" },
236 { IMG_TAB_UNSEL_R, "graphics.IMG_TAB_UNSEL_R" },
237 { IMG_TAB_LINE, "graphics.IMG_TAB_LINE" },
238 { IMG_TAB_LINEL, "graphics.IMG_TAB_LINEL" },
239 { IMG_TAB_LINER, "graphics.IMG_TAB_LINER" },
240 { IMG_ICON_MISSING, "graphics.IMG_ICON_MISSING" },
241 { IMG_SELECTED_HILITE, "graphics.IMG_SELECTED_HILITE" },
242 { IMG_PREVIEW_MISSING, "graphics.IMG_PREVIEW_MISSING" },
243 { IMG_ARROW_UP, "graphics.IMG_ARROW_UP", },
244 { IMG_ARROW_DOWN, "graphics.IMG_ARROW_DOWN", },
245 { IMG_ARROW_SCROLLBAR, "graphics.IMG_ARROW_SCROLLBAR", },
246 { IMG_HOURGLASS, "graphics.IMG_HOURGLASS", },
247 { IMG_FOLDER, "graphics.IMG_FOLDER", },
248 { IMG_EXECBIN, "graphics.IMG_EXECBIN", },
249 { IMG_SUBCATFOLDER, "graphics.IMG_SUBCATFOLDER", "graphics.IMG_FOLDER", },
250 { IMG_DOTDOTFOLDER, "graphics.IMG_DOTDOTFOLDER", "graphics.IMG_FOLDER", },
254 unsigned char ui_imagecache ( char *basepath ) {
256 char fullpath [ PATH_MAX ];
261 for ( i = 0; i < IMG_MAX; i++ ) {
263 if ( g_imagecache [ i ].id != i ) {
264 pnd_log ( pndn_error, "ERROR: Internal table mismatch during caching [%u]\n", i );
268 for ( try = 0; try < 2; try++ ) {
273 filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].confname );
275 if ( g_imagecache [ i ].alt_confname ) {
276 filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].alt_confname );
283 pnd_log ( pndn_error, "ERROR: (Try %u) Missing filename in conf for key: %s\n", try + 1, g_imagecache [ i ].confname );
284 if ( try == 0 ) { continue; } else { return ( 0 ); }
287 if ( filename [ 0 ] == '/' ) {
288 strncpy ( fullpath, filename, PATH_MAX );
290 sprintf ( fullpath, "%s/%s", basepath, filename );
293 if ( ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
294 break; // no retry needed
296 pnd_log ( pndn_error, "ERROR: (Try %u) Couldn't load static cache image: %s\n", try + 1, fullpath );
297 if ( try == 0 ) { continue; } else { return ( 0 ); }
305 //g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = SDL_CreateRGBSurface ( SDL_SWSURFACE, 60, 60, 32, 0xFF0000, 0x00FF00, 0xFF, 0xFF000000 );
306 //boxRGBA ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, 0, 0, 60, 60, 100, 100, 100, 250 );
312 g_imagecache [ IMG_ICON_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_ICON_MISSING ].i, pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 ), -1 );
313 // scale text hilight
314 g_imagecache [ IMG_SELECTED_HILITE ].i = ui_scale_image ( g_imagecache [ IMG_SELECTED_HILITE ].i, pnd_conf_get_as_int_d ( g_conf, "grid.text_width", 50 ), -1 );
315 // scale preview no-pic
316 g_imagecache [ IMG_PREVIEW_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_PREVIEW_MISSING ].i,
317 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ),
318 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 50 ) );
320 // set alpha on detail panel
321 //SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
326 void ui_render ( void ) {
329 // divide width: 550 / 250
330 // divide left side: 5 columns == 110px width
331 // 20px buffer either side == 70px wide icon + 20 + 20?
333 // what jobs to do during render?
337 #define R_TABS (1<<1)
338 #define R_DETAIL (1<<2)
339 #define R_GRID (1<<3)
341 #define R_ALL (R_BG|R_TABS|R_DETAIL|R_GRID)
343 unsigned int render_jobs_b = 0;
345 if ( render_mask & CHANGED_EVERYTHING ) {
346 render_jobs_b |= R_ALL;
349 if ( render_mask & CHANGED_SELECTION ) {
350 render_jobs_b |= R_GRID;
351 render_jobs_b |= R_DETAIL;
354 if ( render_mask & CHANGED_CATEGORY ) {
355 render_jobs_b |= R_ALL;
358 render_mask = CHANGED_NOTHING;
362 unsigned int icon_rows;
365 SDL_Rect rects [ MAXRECTS ], src;
366 SDL_Rect *dest = rects;
367 bzero ( dest, sizeof(SDL_Rect)*MAXRECTS );
369 unsigned int row, displayrow, col;
370 mm_appref_t *appiter;
372 ui_context_t *c = &ui_display_context; // for convenience and shorthand
374 // on demand icon loading
375 static int load_visible = -1;
376 if ( load_visible == -1 ) {
377 load_visible = pnd_conf_get_as_int_d ( g_conf, "minimenu.load_visible_icons", 0 );
380 // how many total rows do we need?
381 if ( g_categorycount ) {
382 icon_rows = g_categories [ ui_category ] -> refcount / c -> col_max;
383 if ( g_categories [ ui_category ] -> refcount % c -> col_max > 0 ) {
391 // if no selected app yet, select the first one
392 if ( ! ui_selected && pnd_conf_get_as_int_d ( g_conf, "minimenu.start_selected", 0 ) ) {
394 // pick first visible app
395 ui_selected = g_categories [ ui_category ] -> refs;
397 // change.. so we pick first visible if option is set .. but now we also try to restore
398 // selection to the last app selected in previous session (if there is one.)
399 char *previous_unique_id = pnd_conf_get_as_char ( g_conf, "minimenu.last_known_app_uid" );
401 if ( previous_unique_id ) {
403 // 1) we should already be in the right category, since its set in ui_post_scan to minimenu.last_known_catname
404 // 2) so we just pick the app in question..
405 mm_appref_t *previter = g_categories [ ui_category ] -> refs;
407 if ( strcmp ( previter -> ref -> unique_id, previous_unique_id ) == 0 ) {
410 previter = previter -> next;
414 ui_selected = previter;
422 // reset touchscreen regions
423 if ( render_jobs_b ) {
427 // ensure selection is visible
430 unsigned char autoscrolled = 1;
431 while ( autoscrolled ) {
434 int index = ui_selected_index();
435 int topleft = c -> col_max * ui_rows_scrolled_down;
436 int botright = ( c -> col_max * ( ui_rows_scrolled_down + c -> row_max ) - 1 );
438 if ( index < topleft ) {
439 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
440 render_jobs_b |= R_ALL;
442 } else if ( index > botright ) {
443 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
444 render_jobs_b |= R_ALL;
448 } // while autoscrolling
450 if ( ui_rows_scrolled_down < 0 ) {
451 ui_rows_scrolled_down = 0;
452 } else if ( ui_rows_scrolled_down > icon_rows ) {
453 ui_rows_scrolled_down = icon_rows;
459 if ( render_jobs_b & R_BG ) {
461 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
464 dest -> w = sdl_realscreen -> w;
465 dest -> h = sdl_realscreen -> h;
466 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
471 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
474 dest -> w = sdl_realscreen -> w;
475 dest -> h = sdl_realscreen -> h;
476 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
483 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
484 static unsigned int tab_width;
485 static unsigned int tab_height;
486 static unsigned int tab_offset_x;
487 static unsigned int tab_offset_y;
488 static unsigned int text_offset_x;
489 static unsigned int text_offset_y;
490 static unsigned int text_width;
492 static unsigned char tab_first_run = 1;
493 if ( tab_first_run ) {
495 tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
496 tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
497 tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
498 tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
499 text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
500 text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
501 text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
504 unsigned int maxtab = ( c -> screen_width / tab_width ) < g_categorycount ? ( c -> screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift;
505 unsigned int maxtabspot = ( c -> screen_width / tab_width );
507 if ( g_categorycount > 0 ) {
509 // draw tabs with categories
510 for ( col = ui_catshift;
517 // if this is the first (leftmost) tab, we use different artwork
518 // than if the other tabs (so skinner can link lines up nicely.)
519 if ( col == ui_catshift ) {
520 // leftmost tab, special case
522 if ( col == ui_category ) {
523 s = g_imagecache [ IMG_TAB_SEL_L ].i;
525 s = g_imagecache [ IMG_TAB_UNSEL_L ].i;
528 } else if ( col == maxtab - 1 ) {
529 // rightmost tab, special case
531 if ( col == ui_category ) {
532 s = g_imagecache [ IMG_TAB_SEL_R ].i;
534 s = g_imagecache [ IMG_TAB_UNSEL_R ].i;
538 // normal (not leftmost) tab
540 if ( col == ui_category ) {
541 s = g_imagecache [ IMG_TAB_SEL ].i;
543 s = g_imagecache [ IMG_TAB_UNSEL ].i;
546 } // first col, or not first col?
553 if ( col == ui_category ) {
554 src.h = tab_selheight;
562 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
563 dest -> y = tab_offset_y;
566 ui_register_tab ( col, dest -> x, dest -> y, tab_width, tab_height );
568 if ( render_jobs_b & R_TABS ) {
569 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
570 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
574 if ( col == ui_category ) {
575 // no line for selected tab
577 if ( col - ui_catshift == 0 ) {
578 s = g_imagecache [ IMG_TAB_LINEL ].i;
579 } else if ( col - ui_catshift == maxtabspot - 1 ) {
580 s = g_imagecache [ IMG_TAB_LINER ].i;
582 s = g_imagecache [ IMG_TAB_LINE ].i;
584 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
585 dest -> y = tab_offset_y + tab_height;
586 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
592 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ] -> catname, c -> fontcolor );
595 src.w = rtext -> w < text_width ? rtext -> w : text_width;
597 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
598 dest -> y = tab_offset_y + text_offset_y;
599 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
600 SDL_FreeSurface ( rtext );
607 } // if we got categories
609 if ( render_jobs_b & R_TABS ) {
611 // draw tab lines under where tabs would be if we had categories
612 for ( /* foo */; col < maxtabspot; col++ ) {
615 if ( col - ui_catshift == 0 ) {
616 s = g_imagecache [ IMG_TAB_LINEL ].i;
617 } else if ( col - ui_catshift == maxtabspot - 1 ) {
618 s = g_imagecache [ IMG_TAB_LINER ].i;
620 s = g_imagecache [ IMG_TAB_LINE ].i;
622 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
623 dest -> y = tab_offset_y + tab_height;
624 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
633 // scroll bars and arrows
634 if ( render_jobs_b & R_BG ) {
635 unsigned char show_bar = 0;
638 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
639 dest -> x = c -> arrow_up_x;
640 dest -> y = c -> arrow_up_y;
641 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
648 if ( ui_rows_scrolled_down + c -> row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
649 dest -> x = c -> arrow_down_x;
650 dest -> y = c -> arrow_down_y;
651 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
658 // show scrollbar as well
661 src.w = c -> arrow_bar_clip_w;
662 src.h = c -> arrow_bar_clip_h;
663 dest -> x = c -> arrow_bar_x;
664 dest -> y = c -> arrow_bar_y;
665 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
669 } // r_bg, scroll bars
671 // render detail pane bg
672 if ( render_jobs_b & R_DETAIL && ui_detail_hidden == 0 ) {
674 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
677 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
678 src.x = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
679 src.y = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
680 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
681 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
682 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
683 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
684 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
688 // render detail pane
689 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
690 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
691 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
692 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
696 } // detailpane frame/bg
700 // anything to render?
701 if ( render_jobs_b & R_GRID && g_categorycount ) {
703 // if just rendering grid, and nothing else, better clear it first
704 if ( ! ( render_jobs_b & R_BG ) ) {
705 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
706 src.x = c -> grid_offset_x;
707 src.y = c -> grid_offset_y + c -> sel_icon_offset_y;
708 src.w = c -> col_max * c -> cell_width;
709 src.h = c -> row_max * c -> cell_height;
711 dest -> x = c -> grid_offset_x;
712 dest -> y = c -> grid_offset_y + c -> sel_icon_offset_y;
714 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
720 if ( g_categories [ ui_category ] -> refs ) {
722 appiter = g_categories [ ui_category ] -> refs;
726 // until we run out of apps, or run out of space
727 while ( appiter != NULL ) {
729 for ( col = 0; col < c -> col_max && appiter != NULL; col++ ) {
731 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
732 if ( row >= ui_rows_scrolled_down ) {
734 // selected? show hilights
735 if ( appiter == ui_selected ) {
736 SDL_Surface *s = g_imagecache [ IMG_SELECTED_ALPHAMASK ].i;
738 //dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + ( ( icon_max_width - s -> w ) / 2 );
739 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> icon_offset_x + c -> sel_icon_offset_x;
740 //dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + ( ( icon_max_height - s -> h ) / 2 );
741 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> icon_offset_y + c -> sel_icon_offset_y;
742 SDL_BlitSurface ( s, NULL /* all */, sdl_realscreen, dest );
745 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_clip_x;
746 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> text_hilite_offset_y;
747 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
752 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
753 SDL_Surface *iconsurface;
755 // if icon not in cache, and its a pnd-file source, perhaps try to load it right now..
758 ( ! ( appiter -> ref -> object_flags & PND_DISCO_GENERATED ) )
761 // try to load any icons that..
762 // - are not yet loaded
763 // - did not fail a previous load attempt
764 // this way user can upfront load all icons, or defer all icons, or even defer all icons
765 // and still try to load visible ones 'just before needed'; so not at mmenu load time, but
766 // as needed (only the ones needed.)
768 if ( ( appiter -> ref -> pnd_icon_pos ) ||
769 ( appiter -> ref -> icon && appiter -> ref -> object_flags & PND_DISCO_LIBPND_DD )
774 if ( ! cache_icon ( appiter -> ref, ui_display_context.icon_max_width, ui_display_context.icon_max_width ) ) {
779 appiter -> ref -> pnd_icon_pos = 0;
780 if ( appiter -> ref -> icon ) {
781 free ( appiter -> ref -> icon );
782 appiter -> ref -> icon = NULL;
785 // pick up as if nothing happened..
786 ic = cache_query_icon ( appiter -> ref -> unique_id );
790 } // load icon during rendering?
793 iconsurface = ic -> i;
795 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
797 // no icon override; was this a pnd-file (show the unknown icon then), or was this generated from
798 // filesystem (file or directory icon)
799 if ( appiter -> ref -> object_flags & PND_DISCO_GENERATED ) {
800 if ( appiter -> ref -> object_type == pnd_object_type_directory ) {
802 // is this a subcat, a .., or a filesystem folder?
803 //iconsurface = g_imagecache [ IMG_FOLDER ].i;
804 if ( g_categories [ ui_category ] -> fspath ) {
805 iconsurface = g_imagecache [ IMG_FOLDER ].i;
806 } else if ( strcmp ( appiter -> ref -> title_en, ".." ) == 0 ) {
807 iconsurface = g_imagecache [ IMG_DOTDOTFOLDER ].i;
809 iconsurface = g_imagecache [ IMG_SUBCATFOLDER ].i;
813 iconsurface = g_imagecache [ IMG_EXECBIN ].i;
816 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
821 // got an icon I hope?
823 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
829 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> icon_offset_x + (( c -> icon_max_width - iconsurface -> w ) / 2);
830 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> icon_offset_y + (( c -> icon_max_height - iconsurface -> h ) / 2);
832 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
835 ui_register_app ( appiter, dest -> x, dest -> y, src.w, src.h );
842 if ( appiter -> ref -> title_en ) {
844 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, c -> fontcolor );
847 src.w = c -> text_width < rtext -> w ? c -> text_width : rtext -> w;
849 if ( rtext -> w > c -> text_width ) {
850 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_clip_x;
852 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_offset_x - ( rtext -> w / 2 );
854 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> text_offset_y;
855 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
856 SDL_FreeSurface ( rtext );
860 } // display now? or scrolled away..
863 appiter = appiter -> next;
865 } // for column 1...X
867 if ( row >= ui_rows_scrolled_down ) {
873 // are we done displaying rows?
874 if ( displayrow >= c -> row_max ) {
881 // no apps to render?
882 pnd_log ( pndn_rem, "No applications to render?\n" );
887 // detail panel - show app details or blank-message
888 if ( render_jobs_b & R_DETAIL && ui_detail_hidden == 0 ) {
890 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
891 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
892 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
894 unsigned int desty = cell_offset_y;
901 if ( ui_selected -> ref -> title_en ) {
903 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, c -> fontcolor );
906 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
908 dest -> x = cell_offset_x;
910 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
911 SDL_FreeSurface ( rtext );
918 if ( ui_selected -> ref -> main_category ) {
920 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
923 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
926 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
928 dest -> x = cell_offset_x;
930 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
931 SDL_FreeSurface ( rtext );
938 if ( ui_selected -> ref -> clockspeed ) {
940 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
943 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
946 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
948 dest -> x = cell_offset_x;
950 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
951 SDL_FreeSurface ( rtext );
956 // show sub-app# on right side of cpu clock?
957 //if ( ui_selected -> ref -> subapp_number )
959 sprintf ( buffer, "(app#%u)", ui_selected -> ref -> subapp_number );
962 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
963 dest -> x = cell_offset_x + cell_width - rtext -> w;
964 dest -> y = desty - src.h;
965 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
966 SDL_FreeSurface ( rtext );
971 #if 0 // merged into hint-line
972 if ( ui_selected -> ref -> info_filename ) {
974 sprintf ( buffer, "Documentation - hit Y" );
977 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
980 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
982 dest -> x = cell_offset_x;
984 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
985 SDL_FreeSurface ( rtext );
992 if ( ui_selected -> ovrh ) {
997 desty += 5; // a touch of spacing can't hurt
999 for ( i = 1; i < 4; i++ ) {
1000 sprintf ( buffer, "Application-%u.note-%u", ui_selected -> ref -> subapp_number, i );
1001 n = pnd_conf_get_as_char ( ui_selected -> ovrh, buffer );
1005 rtext = TTF_RenderText_Blended ( g_detailtext_font, n, c -> fontcolor );
1008 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
1010 dest -> x = cell_offset_x;
1012 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1013 SDL_FreeSurface ( rtext );
1015 desty += rtext -> h;
1019 } // r_detail -> notes
1022 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
1023 SDL_Surface *previewpic;
1026 previewpic = ic -> i;
1028 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
1032 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
1033 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
1034 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
1035 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
1041 char *empty_message = "Press SELECT for menu";
1045 rtext = TTF_RenderText_Blended ( g_detailtext_font, empty_message, c -> fontcolor );
1049 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
1051 dest -> x = cell_offset_x;
1053 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1054 SDL_FreeSurface ( rtext );
1059 rtext = TTF_RenderText_Blended ( g_detailtext_font, "START or B to run app", c -> fontcolor );
1060 dest -> x = cell_offset_x;
1062 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1063 SDL_FreeSurface ( rtext );
1067 rtext = TTF_RenderText_Blended ( g_detailtext_font, "SPACE for app menu", c -> fontcolor );
1068 dest -> x = cell_offset_x;
1070 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1071 SDL_FreeSurface ( rtext );
1075 rtext = TTF_RenderText_Blended ( g_detailtext_font, "A to toggle details", c -> fontcolor );
1076 dest -> x = cell_offset_x;
1078 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1079 SDL_FreeSurface ( rtext );
1083 } // r_detail && selected?
1091 if ( render_jobs_b & R_BG ) {
1092 static int last_battlevel = 0;
1093 static unsigned char batterylevel = 0;
1094 char buffer [ 100 ];
1096 if ( time ( NULL ) - last_battlevel > 60 ) {
1097 batterylevel = pnd_device_get_battery_gauge_perc();
1098 last_battlevel = time ( NULL );
1101 sprintf ( buffer, "Battery: %u%%", batterylevel );
1104 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1105 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.battery_x", 20 );
1106 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
1107 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1108 SDL_FreeSurface ( rtext );
1113 if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
1115 unsigned int hintx, hinty;
1116 hintx = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
1117 hinty = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
1118 static unsigned int lastwidth = 3000;
1120 if ( ui_selected && ui_selected -> ref -> info_filename ) {
1121 buffer = "Documentation - hit Y";
1123 buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
1127 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1130 if ( ! ( render_jobs_b & R_BG ) ) {
1137 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, &src, sdl_realscreen, dest );
1139 lastwidth = rtext -> w;
1145 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1146 SDL_FreeSurface ( rtext );
1151 if ( render_jobs_b & R_BG &&
1152 pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 )
1156 time_t t = time ( NULL );
1157 struct tm *tm = localtime ( &t );
1158 strftime ( buffer, 50, "%a %H:%M %F", tm );
1161 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1162 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.clock_x", 700 );
1163 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.clock_y", 450 );
1164 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1165 SDL_FreeSurface ( rtext );
1169 // update all the rects and send it all to sdl
1170 // - at this point, we could probably just do 1 rect, of the
1171 // whole screen, and be faster :/
1172 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1176 void ui_process_input ( pnd_dbusnotify_handle dbh, pnd_notify_handle nh ) {
1179 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
1180 //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
1182 while ( ( ! ui_event ) &&
1183 /*block_p ?*/ SDL_WaitEvent ( &event ) /*: SDL_PollEvent ( &event )*/ )
1186 switch ( event.type ) {
1191 // the user-defined SDL events are all for threaded/delayed previews (and icons, which
1192 // generally are not used); if we're in wide mode, we can skip previews
1193 // to avoid slowing things down when they're not shown.
1195 if ( event.user.code == sdl_user_ticker ) {
1197 if ( ui_detail_hidden ) {
1198 break; // skip building previews when not showing them
1201 // timer went off, time to load something
1202 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1204 if ( ! ui_selected ) {
1208 // load the preview pics now!
1209 pnd_disco_t *iter = ui_selected -> ref;
1211 if ( iter -> preview_pic1 ) {
1213 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.threaded_preview", 0 ) ) {
1214 // load in bg thread, make user experience chuggy
1216 g_preview_thread = SDL_CreateThread ( (void*)ui_threaded_defered_preview, iter );
1218 if ( ! g_preview_thread ) {
1219 pnd_log ( pndn_error, "ERROR: Couldn't create preview thread\n" );
1223 // load it now, make user wait
1225 if ( ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
1226 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
1229 pnd_log ( pndn_debug, " Couldn't load preview pic: '%s' -> '%s'\n",
1230 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1235 } // got a preview at all?
1240 } else if ( event.user.code == sdl_user_finishedpreview ) {
1242 // if we just finished the one we happen to be looking at, better redraw now; otherwise, if
1243 // we finished another, no big woop
1244 if ( ui_selected && event.user.data1 == ui_selected -> ref ) {
1248 } else if ( event.user.code == sdl_user_finishedicon ) {
1249 // redraw, so we can show the newly loaded icon
1252 } else if ( event.user.code == sdl_user_checksd ) {
1253 // check if any inotify-type events occured, forcing us to rescan/re-disco the SDs
1255 unsigned char watch_dbus = 0;
1256 unsigned char watch_inotify = 0;
1259 watch_dbus = pnd_dbusnotify_rediscover_p ( dbh );
1263 watch_inotify = pnd_notify_rediscover_p ( nh );
1266 if ( watch_dbus || watch_inotify ) {
1267 pnd_log ( pndn_debug, "dbusnotify detected SD event\n" );
1268 applications_free();
1269 applications_scan();
1276 render_mask |= CHANGED_EVERYTHING;
1280 #if 0 // joystick motion
1281 case SDL_JOYAXISMOTION:
1283 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
1285 if ( event.jaxis.axis == 0 ) {
1287 if ( event.jaxis.value < 0 ) {
1289 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
1290 } else if ( event.jaxis.value > 0 ) {
1291 ui_push_right ( 0 );
1292 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
1294 } else if ( event.jaxis.axis == 1 ) {
1296 if ( event.jaxis.value < 0 ) {
1298 } else if ( event.jaxis.value > 0 ) {
1308 #if 0 // joystick buttons
1309 case SDL_JOYBUTTONDOWN:
1311 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
1313 if ( event.jbutton.button == 0 ) { // B
1315 } else if ( event.jbutton.button == 1 ) { // Y
1317 } else if ( event.jbutton.button == 2 ) { // X
1319 } else if ( event.jbutton.button == 3 ) { // A
1322 } else if ( event.jbutton.button == 4 ) { // Select
1323 ui_mask |= uisb_select;
1324 } else if ( event.jbutton.button == 5 ) { // Start
1325 ui_mask |= uisb_start;
1327 } else if ( event.jbutton.button == 7 ) { // L
1329 } else if ( event.jbutton.button == 8 ) { // R
1338 case SDL_JOYBUTTONUP:
1340 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
1342 if ( event.jbutton.button == 0 ) { // B
1345 } else if ( event.jbutton.button == 1 ) { // Y
1347 } else if ( event.jbutton.button == 2 ) { // X
1349 } else if ( event.jbutton.button == 3 ) { // A
1352 } else if ( event.jbutton.button == 4 ) { // Select
1353 ui_mask &= ~uisb_select;
1354 } else if ( event.jbutton.button == 5 ) { // Start
1355 ui_mask &= ~uisb_start;
1357 } else if ( event.jbutton.button == 7 ) { // L
1360 } else if ( event.jbutton.button == 8 ) { // R
1371 #if 1 // keyboard events
1375 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
1377 // SDLK_LALT -> Start
1378 // page up/down for y/x
1379 // home/end for a and b
1382 if ( event.key.keysym.sym == SDLK_RIGHT ) {
1383 ui_push_right ( 0 );
1385 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
1388 } else if ( event.key.keysym.sym == SDLK_UP ) {
1391 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1394 } else if ( event.key.keysym.sym == SDLK_END ) { // B
1397 } else if ( event.key.keysym.sym == SDLK_SPACE ) { // space
1398 if ( ui_selected ) {
1399 ui_menu_context ( ui_selected );
1401 // TBD: post an error?
1403 render_mask |= CHANGED_EVERYTHING;
1405 } else if ( event.key.keysym.sym == SDLK_TAB || event.key.keysym.sym == SDLK_HOME ) { // tab or A
1406 // if detail panel is togglable, then toggle it
1407 // if not, make sure its ruddy well shown!
1408 if ( ui_is_detail_hideable() ) {
1409 ui_toggle_detail_pane();
1411 ui_detail_hidden = 0;
1414 } else if ( event.key.keysym.sym == SDLK_RSHIFT || event.key.keysym.sym == SDLK_COMMA ) { // left trigger or comma
1417 } else if ( event.key.keysym.sym == SDLK_RCTRL || event.key.keysym.sym == SDLK_PERIOD ) { // right trigger or period
1421 } else if ( event.key.keysym.sym == SDLK_PAGEUP ) { // Y
1423 if ( ui_selected ) {
1424 ui_show_info ( pnd_run_script, ui_selected -> ref );
1427 } else if ( event.key.keysym.sym == SDLK_PAGEDOWN ) { // X
1430 // forget the selection, nolonger applies
1432 ui_set_selected ( ui_selected );
1434 if ( g_categories [ ui_category ] -> fspath ) {
1435 category_fs_restock ( g_categories [ ui_category ] );
1438 render_mask |= CHANGED_EVERYTHING;
1441 } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
1445 } else if ( event.key.keysym.sym == SDLK_LCTRL /*LALT*/ ) { // select button
1446 char *opts [ 20 ] = {
1447 "Reveal hidden category",
1449 "Configure Minimenu",
1450 "Manage custom app categories",
1451 "Rescan for applications",
1452 "Cache previews to SD now",
1453 "Run a terminal/console",
1454 "Run another GUI (xfce, etc)",
1456 "Select a Minimenu skin",
1459 int sel = ui_modal_single_menu ( opts, 11, "Minimenu", "Enter to select; other to return." );
1461 char buffer [ 100 ];
1465 } else if ( sel == 1 ) {
1466 // store conf on exit, so that last app/cat can be cached.. for ED :)
1467 conf_write ( g_conf, conf_determine_location ( g_conf ) );
1469 sprintf ( buffer, "sudo poweroff" );
1471 } else if ( sel == 2 ) {
1473 unsigned char restart = conf_run_menu ( NULL );
1474 conf_write ( g_conf, conf_determine_location ( g_conf ) );
1475 conf_write ( g_conf, CONF_PREF_TEMPPATH );
1477 emit_and_quit ( MM_RESTART );
1479 } else if ( sel == 3 ) {
1480 // manage custom categories
1481 ui_manage_categories();
1482 } else if ( sel == 4 ) {
1484 pnd_log ( pndn_debug, "Freeing up applications\n" );
1485 applications_free();
1486 pnd_log ( pndn_debug, "Rescanning applications\n" );
1487 applications_scan();
1488 } else if ( sel == 5 ) {
1489 // cache preview to SD now
1490 extern pnd_box_handle g_active_apps;
1491 pnd_box_handle h = g_active_apps;
1493 unsigned int maxwidth, maxheight;
1494 maxwidth = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 );
1495 maxheight = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 );
1497 pnd_disco_t *iter = pnd_box_get_head ( h );
1502 if ( ! cache_preview ( iter, maxwidth, maxheight ) ) {
1503 pnd_log ( pndn_debug, "Force cache: Couldn't load preview pic: '%s' -> '%s'\n",
1504 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1508 iter = pnd_box_get_next ( iter );
1511 } else if ( sel == 6 ) {
1514 argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
1518 ui_forkexec ( argv );
1521 } else if ( sel == 7 ) {
1522 char buffer [ PATH_MAX ];
1523 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/pandora/scripts/op_switchgui.sh" );
1524 emit_and_quit ( buffer );
1525 } else if ( sel == 8 ) {
1526 emit_and_quit ( MM_QUIT );
1527 } else if ( sel == 9 ) {
1529 if ( ui_pick_skin() ) {
1530 emit_and_quit ( MM_RESTART );
1532 } else if ( sel == 10 ) {
1534 char buffer [ PATH_MAX ];
1535 sprintf ( buffer, "%s/about.txt", g_skinpath );
1536 ui_aboutscreen ( buffer );
1540 render_mask |= CHANGED_EVERYTHING;
1543 // unknown SDLK_ keycode?
1545 // many SDLK_keycodes map to ASCII ("a" is ascii(a)), so try to jump to a filename of that name, in this category?
1546 // and if already there, try to jump to next, maybe?
1547 // future: look for sequence typing? ie: user types 'm' then 'a', look for 'ma*' instead of 'm' then 'a' matching
1548 if ( isalpha ( event.key.keysym.sym ) && g_categories [ ui_category ] -> refcount > 0 ) {
1549 mm_appref_t *app = g_categories [ ui_category ] -> refs;
1551 //fprintf ( stderr, "sel %s next %s\n", ui_selected -> ref -> title_en, ui_selected -> next -> ref -> title_en );
1553 // are we already matching the same char? and next item is also same char?
1554 if ( app && ui_selected && ui_selected -> next &&
1555 ui_selected -> ref -> title_en && ui_selected -> next -> ref -> title_en &&
1556 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( ui_selected -> next -> ref -> title_en [ 0 ] ) &&
1557 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym )
1560 // just skip down one
1561 app = ui_selected -> next;
1564 // walk the category, looking for a first-char match
1566 if ( app -> ref -> title_en && toupper ( app -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym ) ) {
1572 } // same start letter, or new run?
1574 // found something, or no?
1576 // looks like we found a potential match; try switching it to visible selection
1578 ui_set_selected ( ui_selected );
1583 } // SDLK_alphanumeric?
1589 if ( event.key.keysym.sym == SDLK_ESCAPE ) {
1590 emit_and_quit ( MM_QUIT );
1597 #if 1 // mouse / touchscreen
1599 case SDL_MOUSEBUTTONDOWN:
1600 if ( event.button.button == SDL_BUTTON_LEFT ) {
1601 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
1607 case SDL_MOUSEBUTTONUP:
1608 if ( event.button.button == SDL_BUTTON_LEFT ) {
1609 ui_touch_act ( event.button.x, event.button.y );
1622 } // switch event type
1629 void ui_push_left ( unsigned char forcecoil ) {
1631 if ( ! ui_selected ) {
1632 ui_push_right ( 0 );
1636 // what column we in?
1637 unsigned int col = ui_determine_screen_col ( ui_selected );
1639 // are we already at first item?
1640 if ( forcecoil == 0 &&
1641 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1644 unsigned int i = ui_display_context.col_max - 1;
1645 while ( i && ui_selected -> next ) {
1646 ui_push_right ( 0 );
1650 } else if ( g_categories [ ui_category ] -> refs == ui_selected ) {
1651 // can't go any more left, we're at the head
1654 // figure out the previous item; yay for singly linked list :/
1655 mm_appref_t *i = g_categories [ ui_category ] -> refs;
1657 if ( i -> next == ui_selected ) {
1665 ui_set_selected ( ui_selected );
1670 void ui_push_right ( unsigned char forcecoil ) {
1672 if ( ui_selected ) {
1674 // what column we in?
1675 unsigned int col = ui_determine_screen_col ( ui_selected );
1678 if ( forcecoil == 0 &&
1679 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1680 // and selected is far-right, or last icon in category (might not be far right)
1681 ( ( col == ui_display_context.col_max - 1 ) ||
1682 ( ui_selected -> next == NULL ) )
1686 //unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1687 while ( col /*i*/ ) {
1693 // just go to the next
1695 if ( ui_selected -> next ) {
1696 ui_selected = ui_selected -> next;
1702 ui_selected = g_categories [ ui_category ] -> refs;
1705 ui_set_selected ( ui_selected );
1710 void ui_push_up ( void ) {
1711 unsigned char col_max = ui_display_context.col_max;
1713 if ( ! ui_selected ) {
1718 unsigned int row = ui_determine_row ( ui_selected );
1721 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 0 ) == 0 )
1723 // wrap around instead
1725 unsigned int col = ui_determine_screen_col ( ui_selected );
1728 ui_selected = g_categories [ ui_category ] -> refs;
1729 while ( ui_selected -> next ) {
1730 ui_selected = ui_selected -> next;
1733 // try to move to same column
1734 unsigned int newcol = ui_determine_screen_col ( ui_selected );
1735 if ( newcol > col ) {
1743 // scroll down to show it
1744 int r = ui_determine_row ( ui_selected ) - 1;
1745 if ( r - ui_display_context.row_max > 0 ) {
1746 ui_rows_scrolled_down = (unsigned int) r;
1750 // stop at top/bottom
1762 void ui_push_down ( void ) {
1763 unsigned char col_max = ui_display_context.col_max;
1765 if ( ui_selected ) {
1768 unsigned int row = ui_determine_row ( ui_selected );
1771 unsigned int icon_rows = g_categories [ ui_category ] -> refcount / col_max;
1772 if ( g_categories [ ui_category ] -> refcount % col_max > 0 ) {
1777 if ( row == ( icon_rows - 1 ) &&
1778 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 0 ) == 0 )
1781 unsigned char col = ui_determine_screen_col ( ui_selected );
1783 ui_selected = g_categories [ ui_category ] -> refs;
1786 ui_selected = ui_selected -> next;
1790 ui_rows_scrolled_down = 0;
1792 render_mask |= CHANGED_EVERYTHING;
1797 ui_push_right ( 1 );
1804 ui_push_right ( 0 );
1810 // 'backup' is currently 'X', for going back up in a folder/subcat without having to hit exec on the '..' entry
1811 void ui_push_backup ( void ) {
1813 // a subcat-as-dir, or a dir browser?
1814 if ( g_categories [ ui_category] -> fspath ) {
1815 // dir browser, just climb our way back up
1820 // lop off last word; if the thing ends with /, lop that one, then the next word.
1821 while ( ( c = strrchr ( g_categories [ ui_category] -> fspath, '/' ) ) ) {
1822 *c = '\0'; // lop off the last hunk
1823 if ( *(c+1) != '\0' ) {
1829 if ( g_categories [ ui_category] -> fspath [ 0 ] == '\0' ) {
1830 free ( g_categories [ ui_category] -> fspath );
1831 g_categories [ ui_category] -> fspath = strdup ( "/" );
1835 // a pnd subcat .. are we in one, or at the 'top'?
1836 char *pcatname = g_categories [ ui_category ] -> parent_catname;
1839 return; // we're at the 'top' already
1842 // set to first cat!
1845 // republish cats .. shoudl just be the one
1846 category_publish ( CFNORMAL, NULL );
1849 ui_category = category_index ( pcatname );
1851 // ensure tab visible?
1852 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1853 if ( ui_category > ui_catshift + ( ui_display_context.screen_width / tab_width ) - 1 ) {
1854 ui_catshift = ui_category - ( ui_display_context.screen_width / tab_width ) + 1;
1864 void ui_push_exec ( void ) {
1866 if ( ! ui_selected ) {
1870 // cache the category/app so we can come back to it another time
1871 if ( ui_selected ) {
1872 pnd_conf_set_char ( g_conf, "minimenu.last_known_app_uid", ui_selected -> ref -> unique_id );
1874 if ( g_categories [ 0 ] ) {
1875 pnd_conf_set_char ( g_conf, "minimenu.last_known_catname", g_categories [ ui_category ] -> catname );
1877 // and also the parent cat..
1878 if ( g_categories [ ui_category ] -> parent_catname ) {
1879 pnd_conf_set_char ( g_conf, "minimenu.last_known_parentcatname", g_categories [ ui_category ] -> parent_catname );
1881 char *kv = pnd_box_find_by_key ( g_conf, "minimenu.last_known_parentcatname" );
1883 pnd_box_delete_node ( g_conf, kv );
1889 // cache last known cat/app to /tmp, so we can use it again later
1890 conf_write ( g_conf, CONF_PREF_TEMPPATH );
1892 // was this icon generated from filesystem, or from pnd-file?
1893 if ( ui_selected -> ref -> object_flags & PND_DISCO_GENERATED ) {
1895 if ( ! ui_selected -> ref -> title_en ) {
1896 return; // no filename
1899 if ( ui_selected -> ref -> object_type == pnd_object_type_directory ) {
1901 // check if this guy is a dir-browser tab, or is a directory on a pnd tab
1902 if ( ! g_categories [ ui_category] -> fspath ) {
1903 // pnd subcat as dir
1905 // are we already in a subcat? if so, go back to parent; there is no grandparenting or deeper
1906 if ( g_categories [ ui_category ] -> parent_catname ) {
1911 // delve into subcat
1913 // set to first cat!
1917 // republish cats .. shoudl just be the one
1918 category_publish ( CFBYNAME, ui_selected -> ref -> object_path );
1922 // forget the selection, nolonger applies
1924 ui_set_selected ( ui_selected );
1926 render_mask |= CHANGED_EVERYTHING;
1930 // delve up/down the dir tree
1931 if ( strcmp ( ui_selected -> ref -> title_en, ".." ) == 0 ) {
1936 char *temp = malloc ( strlen ( g_categories [ ui_category] -> fspath ) + strlen ( ui_selected -> ref -> title_en ) + 1 + 1 );
1937 sprintf ( temp, "%s/%s", g_categories [ ui_category] -> fspath, ui_selected -> ref -> title_en );
1938 free ( g_categories [ ui_category] -> fspath );
1939 g_categories [ ui_category] -> fspath = temp;
1942 pnd_log ( pndn_debug, "Cat %s is now in path %s\n", g_categories [ ui_category ] -> catname, g_categories [ ui_category ]-> fspath );
1944 // forget the selection, nolonger applies
1946 ui_set_selected ( ui_selected );
1948 category_fs_restock ( g_categories [ ui_category ] );
1950 render_mask |= CHANGED_SELECTION;
1952 } // directory browser or pnd subcat?
1955 // just run it arbitrarily?
1957 // if this a pnd-file, or just some executable?
1958 if ( strcasestr ( ui_selected -> ref -> object_filename, PND_PACKAGE_FILEEXT ) ) {
1959 // looks like a pnd, now what do we do..
1960 pnd_box_handle h = pnd_disco_file ( ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
1963 pnd_disco_t *d = pnd_box_get_head ( h );
1964 pnd_apps_exec_disco ( pnd_run_script, d, PND_EXEC_OPTION_NORUN, NULL );
1965 char buffer [ PATH_MAX ];
1966 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1967 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
1968 emit_and_quit ( buffer );
1970 emit_and_run ( buffer );
1977 // is it even executable? if we don't have handlers for non-executables yet (Jan 2011 we don't),
1978 // then don't even try to run things not-flagged as executable.. but wait most people are on
1979 // FAT filesystems, what a drag, we can't tell at the fs level.
1980 // ... but we can still invoke 'file' and grep out the good bits, at least.
1982 // open a stream reading 'file /path/to/file' and check output for 'executable'
1983 // -- not checking for "ARM" so it can pick up x86 (or whatever native) executables in build environment
1984 unsigned char is_executable = 0;
1988 char popenbuf [ FILENAME_MAX ];
1989 snprintf ( popenbuf, FILENAME_MAX, "%s %s/%s", MIMETYPE_EXE, g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
1992 if ( ! ( marceau = popen ( popenbuf, "r" ) ) ) {
1993 return; // error, we need some useful error handling and dialog boxes here
1996 if ( fgets ( popenbuf, FILENAME_MAX, marceau ) ) {
1997 //printf ( "File test returns: %s\n", popenbuf );
1998 if ( strstr ( popenbuf, "executable" ) != NULL ) {
2007 if ( ! is_executable ) {
2008 fprintf ( stderr, "ERROR: File to invoke is not executable, skipping. (%s)\n", ui_selected -> ref -> title_en );
2009 return; // need some error handling here
2012 #if 0 // eat up any pending SDL events and toss 'em?
2016 while ( SDL_PeepEvents ( &e, 1, SDL_GETEVENT, SDL_ALLEVENTS ) > 0 ) {
2026 // get CWD so we can restore it on return
2027 char cwd [ PATH_MAX ];
2028 getcwd ( cwd, PATH_MAX );
2030 // full path to executable so we don't rely on implicit "./"
2031 char execbuf [ FILENAME_MAX ];
2032 snprintf ( execbuf, FILENAME_MAX, "%s/%s", g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
2035 chdir ( g_categories [ ui_category ] -> fspath );
2036 exec_raw_binary ( execbuf /*ui_selected -> ref -> title_en*/ );
2039 // DEPRECATED / NOT TESTED
2040 // get mmwrapper to run it
2041 char buffer [ PATH_MAX ];
2042 sprintf ( buffer, "%s %s/%s\n", MM_RUN, g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
2043 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
2044 emit_and_quit ( buffer );
2046 emit_and_run ( buffer );
2055 // set app-run speed
2056 int use_run_speed = pnd_conf_get_as_int_d ( g_conf, "minimenu.use_run_speed", 0 );
2057 if ( use_run_speed > 0 ) {
2058 int mm_speed = pnd_conf_get_as_int_d ( g_conf, "minimenu.run_speed", -1 );
2059 if ( mm_speed > -1 ) {
2060 char buffer [ 512 ];
2061 snprintf ( buffer, 500, "sudo /usr/pandora/scripts/op_cpuspeed.sh %d", mm_speed );
2064 } // do speed change?
2066 // request app to run and quit mmenu
2067 pnd_apps_exec_disco ( pnd_run_script, ui_selected -> ref, PND_EXEC_OPTION_NORUN, NULL );
2068 char buffer [ PATH_MAX ];
2069 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
2070 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
2071 emit_and_quit ( buffer );
2073 emit_and_run ( buffer );
2080 void ui_push_ltrigger ( void ) {
2081 unsigned char oldcat = ui_category;
2082 unsigned int screen_width = ui_display_context.screen_width;
2083 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2085 if ( g_categorycount == 0 ) {
2089 if ( g_icon_thread_busy ) {
2090 ui_stop_defered_icon_thread();
2093 if ( ui_category > 0 ) {
2095 category_fs_restock ( g_categories [ ui_category ] );
2097 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
2098 ui_category = g_categorycount - 1;
2100 if ( ui_category >= ( screen_width / tab_width ) ) {
2101 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
2103 category_fs_restock ( g_categories [ ui_category ] );
2107 if ( oldcat != ui_category ) {
2109 ui_set_selected ( ui_selected );
2112 // make tab visible?
2113 if ( ui_catshift > 0 && ui_category == ui_catshift - 1 ) {
2118 ui_rows_scrolled_down = 0;
2120 render_mask |= CHANGED_CATEGORY;
2121 ui_start_defered_icon_thread();
2126 void ui_push_rtrigger ( void ) {
2127 unsigned char oldcat = ui_category;
2129 if ( g_categorycount == 0 ) {
2133 if ( g_icon_thread_busy ) {
2134 ui_stop_defered_icon_thread();
2137 unsigned int screen_width = ui_display_context.screen_width;
2138 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2140 if ( ui_category < ( g_categorycount - 1 ) ) {
2142 category_fs_restock ( g_categories [ ui_category ] );
2144 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
2147 category_fs_restock ( g_categories [ ui_category ] );
2151 if ( oldcat != ui_category ) {
2153 ui_set_selected ( ui_selected );
2156 // make tab visible?
2157 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2162 ui_rows_scrolled_down = 0;
2164 render_mask |= CHANGED_CATEGORY;
2165 ui_start_defered_icon_thread();
2170 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
2171 double scale = 1000000.0;
2172 double scalex = 1000000.0;
2173 double scaley = 1000000.0;
2174 SDL_Surface *scaled;
2176 scalex = (double)maxwidth / (double)s -> w;
2178 if ( maxheight == -1 ) {
2181 scaley = (double)maxheight / (double)s -> h;
2183 if ( scaley < scalex ) {
2191 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
2192 SDL_FreeSurface ( s );
2198 void ui_loadscreen ( void ) {
2203 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2207 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", ui_display_context.fontcolor );
2210 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
2211 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2212 SDL_FreeSurface ( rtext );
2217 void ui_discoverscreen ( unsigned char clearscreen ) {
2222 if ( clearscreen ) {
2223 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2225 // render background
2226 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2229 dest.w = sdl_realscreen -> w;
2230 dest.h = sdl_realscreen -> h;
2231 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
2232 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2239 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", ui_display_context.fontcolor );
2240 if ( clearscreen ) {
2247 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
2248 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2249 SDL_FreeSurface ( rtext );
2252 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
2253 dest.x = rtext -> w + 30;
2255 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
2256 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2262 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
2264 SDL_Rect rects [ 4 ];
2265 SDL_Rect *dest = rects;
2267 bzero ( dest, sizeof(SDL_Rect)* 4 );
2269 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
2270 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
2271 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
2272 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
2274 static unsigned int stepx = 0;
2277 if ( clearscreen ) {
2278 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2280 // render background
2281 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2284 dest -> w = sdl_realscreen -> w;
2285 dest -> h = sdl_realscreen -> h;
2286 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
2292 // render background
2293 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2296 src.w = sdl_realscreen -> w;
2300 dest -> w = sdl_realscreen -> w;
2301 dest -> h = sdl_realscreen -> h;
2302 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
2310 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
2311 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
2314 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2315 SDL_FreeSurface ( rtext );
2319 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
2320 dest -> x = rtext -> w + 30 + stepx;
2322 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
2328 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
2331 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2332 SDL_FreeSurface ( rtext );
2339 if ( stepx > 350 ) {
2343 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
2348 int ui_selected_index ( void ) {
2350 if ( ! ui_selected ) {
2351 return ( -1 ); // no index
2354 mm_appref_t *r = g_categories [ ui_category ] -> refs;
2357 if ( r == ui_selected ) {
2367 static mm_appref_t *timer_ref = NULL;
2368 void ui_set_selected ( mm_appref_t *r ) {
2370 render_mask |= CHANGED_SELECTION;
2372 // preview pic stuff
2375 if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
2376 return; // no desire to defer anything
2381 SDL_SetTimer ( 0, NULL );
2386 SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
2392 unsigned int ui_callback_f ( unsigned int t ) {
2394 if ( ui_selected != timer_ref ) {
2395 return ( 0 ); // user has moved it, who cares
2399 bzero ( &e, sizeof(SDL_Event) );
2400 e.type = SDL_USEREVENT;
2401 e.user.code = sdl_user_ticker;
2402 SDL_PushEvent ( &e );
2407 int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
2408 SDL_Rect rects [ 40 ];
2409 SDL_Rect *dest = rects;
2412 unsigned char max_visible = pnd_conf_get_as_int_d ( g_conf, "detailtext.max_visible" , 11 );
2413 unsigned char first_visible = 0;
2415 bzero ( rects, sizeof(SDL_Rect) * 40 );
2417 unsigned int sel = 0;
2419 SDL_Color selfontcolor = { 0/*font_rgba_r*/, ui_display_context.font_rgba_g, ui_display_context.font_rgba_b, ui_display_context.font_rgba_a };
2427 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2428 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2429 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
2430 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
2431 SDL_FillRect( sdl_realscreen, dest, 0 );
2433 // show dialog background
2434 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
2437 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> w;
2438 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> h;
2439 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2440 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2441 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2442 // repeat for darken?
2443 //SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2444 //SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2445 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2449 // show dialog frame
2450 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
2451 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2452 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2453 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
2454 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2460 rtext = TTF_RenderText_Blended ( g_tab_font, title, ui_display_context.fontcolor );
2461 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2462 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
2463 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2464 SDL_FreeSurface ( rtext );
2470 rtext = TTF_RenderText_Blended ( g_tab_font, footer, ui_display_context.fontcolor );
2471 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2472 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
2473 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
2475 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2476 SDL_FreeSurface ( rtext );
2481 for ( i = first_visible; i < first_visible + max_visible && i < argc; i++ ) {
2485 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
2487 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], ui_display_context.fontcolor );
2489 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2490 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 - first_visible ) );
2491 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2492 SDL_FreeSurface ( rtext );
2497 // update all the rects and send it all to sdl
2498 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
2502 while ( SDL_WaitEvent ( &event ) ) {
2504 switch ( event.type ) {
2509 if ( event.key.keysym.sym == SDLK_UP ) {
2513 if ( sel < first_visible ) {
2518 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
2520 if ( sel < argc - 1 ) {
2523 // ensure visibility
2524 if ( sel >= first_visible + max_visible ) {
2530 } else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_END ) { // return, or "B"
2534 } else if ( event.key.keysym.sym == SDLK_q ) {
2539 return ( -1 ); // nada
2554 unsigned char ui_determine_row ( mm_appref_t *a ) {
2555 unsigned int row = 0;
2557 mm_appref_t *i = g_categories [ ui_category ] -> refs;
2562 row /= ui_display_context.col_max;
2567 unsigned char ui_determine_screen_row ( mm_appref_t *a ) {
2568 return ( ui_determine_row ( a ) % ui_display_context.row_max );
2571 unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
2572 unsigned int col = 0;
2574 mm_appref_t *i = g_categories [ ui_category ] -> refs;
2579 col %= ui_display_context.col_max;
2584 unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ) {
2585 char *viewer, *searchpath;
2586 pnd_conf_handle desktoph;
2589 searchpath = pnd_conf_query_searchpath();
2591 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
2597 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
2600 return ( 0 ); // no way to view the file
2604 if ( ! p -> unique_id ) {
2608 if ( ! p -> info_filename ) {
2612 if ( ! p -> info_name ) {
2623 if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
2624 snprintf ( pargs, 1001, "%s %s",
2625 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
2630 char pndfile [ 1024 ];
2631 if ( p -> object_type == pnd_object_type_directory ) {
2632 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
2633 strncpy ( pndfile, p -> object_path, 1000 );
2634 } else if ( p -> object_type == pnd_object_type_pnd ) {
2635 // pnd_run.sh wants the full path and filename for the .pnd file
2636 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
2639 if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
2640 p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
2645 pnd_log ( pndn_debug, "Info Exec=%s\n", pnd_apps_exec_runline() );
2649 if ( ( x = fork() ) < 0 ) {
2650 pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
2655 execl ( "/bin/sh", "/bin/sh", "-c", pnd_apps_exec_runline(), (char*)NULL );
2656 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", pnd_apps_exec_runline() );
2668 #define MAXTOUCH 100
2669 ui_touch_t ui_touchrects [ MAXTOUCH ];
2670 unsigned char ui_touchrect_count = 0;
2672 void ui_register_reset ( void ) {
2673 bzero ( ui_touchrects, sizeof(ui_touch_t)*MAXTOUCH );
2674 ui_touchrect_count = 0;
2678 void ui_register_tab ( unsigned char catnum, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2680 if ( ui_touchrect_count == MAXTOUCH ) {
2684 ui_touchrects [ ui_touchrect_count ].r.x = x;
2685 ui_touchrects [ ui_touchrect_count ].r.y = y;
2686 ui_touchrects [ ui_touchrect_count ].r.w = w;
2687 ui_touchrects [ ui_touchrect_count ].r.h = h;
2688 ui_touchrects [ ui_touchrect_count ].catnum = catnum;
2689 ui_touchrect_count++;
2694 void ui_register_app ( mm_appref_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2696 if ( ui_touchrect_count == MAXTOUCH ) {
2700 ui_touchrects [ ui_touchrect_count ].r.x = x;
2701 ui_touchrects [ ui_touchrect_count ].r.y = y;
2702 ui_touchrects [ ui_touchrect_count ].r.w = w;
2703 ui_touchrects [ ui_touchrect_count ].r.h = h;
2704 ui_touchrects [ ui_touchrect_count ].ref = app;
2705 ui_touchrect_count++;
2710 void ui_touch_act ( unsigned int x, unsigned int y ) {
2715 for ( i = 0; i < ui_touchrect_count; i++ ) {
2716 t = &(ui_touchrects [ i ]);
2718 if ( x >= t -> r.x &&
2719 x <= t -> r.x + t -> r.w &&
2721 y <= t -> r.y + t -> r.h
2726 ui_selected = t -> ref;
2729 if ( ui_category != t -> catnum ) {
2732 ui_category = t -> catnum;
2733 render_mask |= CHANGED_CATEGORY;
2735 category_fs_restock ( g_categories [ ui_category ] );
2736 ui_start_defered_icon_thread();
2747 unsigned char ui_forkexec ( char *argv[] ) {
2748 char *fooby = argv[0];
2751 if ( ( x = fork() ) < 0 ) {
2752 pnd_log ( pndn_error, "ERROR: Couldn't fork() for '%s'\n", fooby );
2756 if ( x == 0 ) { // child
2757 execv ( fooby, argv );
2758 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", fooby );
2766 unsigned char ui_threaded_timer_create ( void ) {
2768 g_timer_thread = SDL_CreateThread ( (void*)ui_threaded_timer, NULL );
2770 if ( ! g_timer_thread ) {
2771 pnd_log ( pndn_error, "ERROR: Couldn't create timer thread\n" );
2778 int ui_threaded_timer ( pnd_disco_t *p ) {
2780 // this timer's job is to ..
2781 // - do nothing for quite awhile
2782 // - on wake, post event to SDL event queue, so that main thread will check if SD insert/eject occurred
2785 unsigned int delay_s = 2; // seconds
2790 //sleep ( delay_s );
2791 SDL_Delay ( delay_s * 1000 );
2793 // .. trigger SD check
2795 bzero ( &e, sizeof(SDL_Event) );
2796 e.type = SDL_USEREVENT;
2797 e.user.code = sdl_user_checksd;
2798 SDL_PushEvent ( &e );
2805 unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
2807 if ( ! cache_preview ( p, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
2808 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
2811 pnd_log ( pndn_debug, "THREAD: Couldn't load preview pic: '%s' -> '%s'\n",
2812 IFNULL(p->title_en,"No Name"), p -> preview_pic1 );
2815 // trigger that we completed
2817 bzero ( &e, sizeof(SDL_Event) );
2818 e.type = SDL_USEREVENT;
2819 e.user.code = sdl_user_finishedpreview;
2821 SDL_PushEvent ( &e );
2826 void ui_post_scan ( void ) {
2830 ui_rows_scrolled_down = 0;
2831 // set back to first tab, to be safe
2835 // do we have a preferred category to jump to? or a last known one?
2836 char *dc = pnd_conf_get_as_char ( g_conf, "categories.default_cat" );
2837 char *lastcat = pnd_conf_get_as_char ( g_conf, "minimenu.last_known_catname" );
2839 ( pnd_conf_get_as_int_d ( g_conf, "minimenu.start_selected", 0 ) && lastcat ) )
2841 char *catpick = NULL;
2843 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.start_selected", 0 ) && lastcat ) {
2846 // if this is a subcat, we have some doctoring to do :/ the hackishness is really
2847 // starting to show..
2848 if ( pnd_conf_get_as_char ( g_conf, "minimenu.last_known_parentcatname" ) ) {
2849 // in subcat view, we only have one cat
2852 // the cat name to search for is Child*Parent
2854 sprintf ( key, "%s*%s",
2855 pnd_conf_get_as_char ( g_conf, "minimenu.last_known_catname" )
2856 , pnd_conf_get_as_char ( g_conf, "minimenu.last_known_parentcatname" ) );
2857 category_publish ( CFBYNAME, key );
2858 // since we forced it by hand, no need to do a cat-scan below
2866 // attempt to find default cat; if we do find it, select it; otherwise
2867 // default behaviour will pick first cat (ie: usually All)
2871 for ( i = 0; i < g_categorycount; i++ ) {
2872 if ( strcasecmp ( g_categories [ i ] -> catname, catpick ) == 0 ) {
2874 // ensure visibility
2875 unsigned int screen_width = ui_display_context.screen_width;
2876 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2877 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2878 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
2884 if ( i == g_categorycount ) {
2885 pnd_log ( pndn_warning, " User defined default category or last known cat '%s' but not found, so using default behaviour\n", catpick );
2892 // if we're sent right to a dirbrowser tab, restock it now (normally we restock on entry)
2893 if ( g_categories [ ui_category ] -> fspath ) {
2894 printf ( "Restock on start: '%s'\n", g_categories [ ui_category ] -> fspath );
2895 category_fs_restock ( g_categories [ ui_category ] );
2899 render_mask |= CHANGED_EVERYTHING;
2901 // if deferred icon load, kick off the thread now
2902 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 1 ) {
2903 ui_start_defered_icon_thread();
2904 } // deferred icon load
2909 unsigned char ui_threaded_defered_icon ( void *p ) {
2910 extern pnd_box_handle g_active_apps;
2912 unsigned char maxwidth, maxheight;
2913 maxwidth = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 );
2914 maxheight = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_height", 50 );
2918 g_icon_thread_busy = 1;
2920 // work at it in order within current category
2922 mm_appref_t *refiter = g_categories [ ui_category ] -> refs;
2923 while ( refiter && ! g_icon_thread_stop ) {
2924 iter = refiter -> ref;
2926 // has an icon that is not already cached?
2927 if ( ( iter -> pnd_icon_pos ) ||
2928 ( iter -> icon && iter -> object_flags & PND_DISCO_LIBPND_DD )
2933 if ( ! cache_icon ( iter, maxwidth, maxheight ) ) {
2934 //pnd_log ( pndn_warning, " Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2938 // trigger that we completed
2940 bzero ( &e, sizeof(SDL_Event) );
2941 e.type = SDL_USEREVENT;
2942 e.user.code = sdl_user_finishedicon;
2943 SDL_PushEvent ( &e );
2945 //pnd_log ( pndn_warning, " Finished deferred load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2946 //usleep ( pnd_conf_get_as_int_d ( g_conf, "minimenu.defer_icon_us", 50000 ) );
2951 iter -> pnd_icon_pos = 0;
2952 if ( iter -> icon ) {
2953 free ( iter -> icon );
2954 iter -> icon = NULL;
2957 // let user do something..
2962 refiter = refiter -> next;
2966 g_icon_thread_busy = 0;
2971 void ui_show_hourglass ( unsigned char updaterect ) {
2974 SDL_Surface *s = g_imagecache [ IMG_HOURGLASS ].i;
2976 dest.x = ( 800 - s -> w ) / 2;
2977 dest.y = ( 480 - s -> h ) / 2;
2979 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, &dest );
2982 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2988 unsigned char ui_pick_skin ( void ) {
2990 char *skins [ MAXSKINS ];
2993 char *searchpath = pnd_conf_get_as_char ( g_conf, "minimenu.skin_searchpath" );
2994 char tempname [ 100 ];
2998 skins [ iter++ ] = "No skin change";
3002 DIR *d = opendir ( buffer );
3007 while ( ( dd = readdir ( d ) ) ) {
3009 if ( dd -> d_name [ 0 ] == '.' ) {
3011 } else if ( ( dd -> d_type == DT_DIR || dd -> d_type == DT_UNKNOWN ) &&
3014 snprintf ( tempname, 100, "Skin: %s", dd -> d_name );
3015 skins [ iter++ ] = strdup ( tempname );
3026 int sel = ui_modal_single_menu ( skins, iter, "Skins", "Enter to select; other to return." );
3028 // did they pick one?
3032 char *s = strdup ( pnd_conf_get_as_char ( g_conf, "minimenu.skin_selected" ) );
3033 s = pnd_expand_tilde ( s );
3035 f = fopen ( s, "w" );
3040 fprintf ( f, "%s\n", skins [ sel ] + 6 );
3050 void ui_aboutscreen ( char *textpath ) {
3057 #define ROWS SCRH / ( PIXELH + MARGINH )
3058 #define COLS SCRW / ( PIXELW + MARGINW )
3060 unsigned char pixelboard [ ROWS * COLS ]; // pixel heat
3061 bzero ( pixelboard, ROWS * COLS );
3066 SDL_Color rtextc = { 200, 200, 200, 100 };
3069 char *textloop [ 500 ];
3070 unsigned int textmax = 0;
3071 bzero ( textloop, 500 * sizeof(char*) );
3074 char cbuffer [ 50000 ];
3075 bzero ( cbuffer, 50000 );
3076 unsigned int crevealed = 0;
3078 FILE *f = fopen ( textpath, "r" );
3081 pnd_log ( pndn_error, "ERROR: Couldn't open about text: %s\n", textpath );
3085 char textbuf [ 100 ];
3086 while ( fgets ( textbuf, 100, f ) ) {
3088 // add to full buffer
3089 strncat ( cbuffer, textbuf, 50000 );
3092 if ( strchr ( textbuf, '\n' ) ) {
3093 * strchr ( textbuf, '\n' ) = '\0';
3096 // add to pixel loop
3097 if ( 1||textbuf [ 0 ] ) {
3098 textloop [ textmax ] = strdup ( textbuf );
3106 unsigned int textiter = 0;
3107 while ( textiter < textmax ) {
3108 char *text = textloop [ textiter ];
3112 // render to surface
3113 rtext = TTF_RenderText_Blended ( g_grid_font, text, rtextc );
3115 // render font to pixelboard
3116 unsigned int px, py;
3118 unsigned int *pixels = rtext -> pixels;
3119 unsigned char cr, cg, cb, ca;
3120 for ( py = 0; py < rtext -> h; py ++ ) {
3121 for ( px = 0; px < ( rtext -> w > COLS ? COLS : rtext -> w ); px++ ) {
3123 SDL_GetRGBA ( pixels [ ( py * rtext -> pitch / 4 ) + px ],
3124 rtext -> format, &cr, &cg, &cb, &ca );
3128 ph = pixelboard + ( /*y offset */ 30 * COLS ) + ( py * COLS ) + px /* / 2 */;
3135 if ( *ph + ca < 250 ) {
3146 unsigned int runcount = 10;
3147 while ( runcount-- ) {
3150 SDL_FillRect( sdl_realscreen, NULL /* whole */, 0 );
3152 // render pixelboard
3155 for ( y = 0; y < ROWS; y++ ) {
3156 for ( x = 0; x < COLS; x++ ) {
3158 if ( 1||pixelboard [ ( y * COLS ) + x ] ) {
3161 r.x = x * ( PIXELW + MARGINW );
3162 r.y = y * ( PIXELH + MARGINH );
3166 c = SDL_MapRGB ( sdl_realscreen -> format, 100 /* r */, 0 /* g */, pixelboard [ ( y * COLS ) + x ] );
3168 SDL_FillRect( sdl_realscreen, &r /* whole */, c );
3176 unsigned char *pc = pixelboard;
3177 for ( y = 0; y < ROWS; y++ ) {
3178 for ( x = 0; x < COLS; x++ ) {
3188 // slide pixels upwards
3189 memmove ( pixelboard, pixelboard + COLS, ( COLS * ROWS ) - COLS );
3191 // render actual readable text
3194 // display up to cursor
3196 unsigned int cdraw = 0;
3200 if ( crevealed > 200 ) {
3201 cdraw = crevealed - 200;
3207 for ( ; cdraw < crevealed; cdraw++ ) {
3208 ctb [ 0 ] = cbuffer [ cdraw ];
3210 // move over or down
3211 if ( cbuffer [ cdraw ] == '\n' ) {
3216 if ( dest.y > 450 ) {
3222 cs = TTF_RenderText_Blended ( g_tab_font, ctb, rtextc );
3224 SDL_BlitSurface ( cs, NULL /* all */, sdl_realscreen, &dest );
3225 SDL_FreeSurface ( cs );
3235 SDL_FillRect ( sdl_realscreen, &dest /* whole */, 220 );
3237 // increment cursor to next character
3238 if ( cbuffer [ crevealed ] != '\0' ) {
3242 } // draw cursor text
3246 SDL_UpdateRect ( sdl_realscreen, 0, 0, 0, 0 ); // whole screen
3250 // any button? if so, about
3256 if ( SDL_PeepEvents ( &e, 1, SDL_GETEVENT, SDL_EVENTMASK(/*SDL_KEYUP|*/SDL_KEYDOWN) ) > 0 ) {
3265 SDL_FreeSurface ( rtext );
3269 } // while more text
3273 for ( i = 0; i < textmax; i++ ) {
3274 if ( textloop [ i ] ) {
3275 free ( textloop [ i ] );
3283 void ui_revealscreen ( void ) {
3284 char *labels [ 500 ];
3285 unsigned int labelmax = 0;
3287 char fulllabel [ 200 ];
3289 if ( ! category_count ( CFHIDDEN ) ) {
3290 return; // nothing to do
3293 // switch to hidden categories
3294 category_publish ( CFHIDDEN, NULL );
3296 // build up labels to show in menu
3297 for ( i = 0; i < g_categorycount; i++ ) {
3299 if ( g_categories [ i ] -> parent_catname ) {
3300 sprintf ( fulllabel, "%s [%s]", g_categories [ i ] -> catname, g_categories [ i ] -> parent_catname );
3302 sprintf ( fulllabel, "%s", g_categories [ i ] -> catname );
3305 labels [ labelmax++ ] = strdup ( fulllabel );
3309 int sel = ui_modal_single_menu ( labels, labelmax, "Temporary Category Reveal",
3310 "Enter to select; other to return." );
3312 // if selected, try to set this guy to visible
3315 // fix up category name, if its been hacked
3316 #if 0 // prepending and .. wtf crap is this
3317 if ( strchr ( g_categories [ sel ] -> catname, '.' ) ) {
3318 char *t = g_categories [ sel ] -> catname;
3319 g_categories [ sel ] -> catname = strdup ( strchr ( g_categories [ sel ] -> catname, '.' ) + 1 );
3324 // reflag this guy to be visible
3325 g_categories [ sel ] -> catflags = CFNORMAL;
3327 // switch to the new category.. cache name.
3328 char *switch_to_name = g_categories [ sel ] -> catname;
3330 // republish categories
3331 category_publish ( CFNORMAL, NULL );
3333 // switch to the new category.. with the cached name!
3334 ui_category = category_index ( switch_to_name );
3336 // ensure visibility
3337 unsigned int screen_width = ui_display_context.screen_width;
3338 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
3339 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
3340 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
3345 // republish categories
3346 category_publish ( CFNORMAL, NULL );
3349 render_mask |= CHANGED_CATEGORY;
3350 ui_start_defered_icon_thread();
3355 void ui_recache_context ( ui_context_t *c ) {
3357 c -> screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
3359 c -> font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
3360 c -> font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
3361 c -> font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
3362 c -> font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
3364 c -> grid_offset_x = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_x" );
3365 c -> grid_offset_y = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_y" );
3367 c -> icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
3368 c -> icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
3369 c -> icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
3370 c -> icon_max_height = pnd_conf_get_as_int ( g_conf, "grid.icon_max_height" );
3371 c -> sel_icon_offset_x = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_x", 0 );
3372 c -> sel_icon_offset_y = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_y", 0 );
3374 c -> text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
3375 c -> text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
3376 c -> text_offset_x = pnd_conf_get_as_int ( g_conf, "grid.text_offset_x" );
3377 c -> text_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_offset_y" );
3378 c -> text_hilite_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
3380 c -> row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 4 );
3381 c -> col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
3383 c -> cell_width = pnd_conf_get_as_int ( g_conf, "grid.cell_width" );
3384 c -> cell_height = pnd_conf_get_as_int ( g_conf, "grid.cell_height" );
3386 c -> arrow_bar_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
3387 c -> arrow_bar_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
3388 c -> arrow_bar_clip_w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
3389 c -> arrow_bar_clip_h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
3390 c -> arrow_up_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
3391 c -> arrow_up_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
3392 c -> arrow_down_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
3393 c -> arrow_down_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
3396 SDL_Color tmp = { c -> font_rgba_r, c -> font_rgba_g, c -> font_rgba_b, c -> font_rgba_a };
3397 c -> fontcolor = tmp;
3399 // now that we've got 'normal' (detail pane shown) param's, lets check if detail pane
3400 // is hidden; if so, override some values with those alternate skin values where possible.
3401 if ( ui_detail_hidden ) {
3402 // if detail panel is hidden, and theme cannot support it, unhide the bloody thing. (This may help
3403 // when someone is amid theme hacking or changing.)
3404 if ( ! ui_is_detail_hideable() ) {
3405 ui_detail_hidden = 0;
3409 if ( ui_detail_hidden ) {
3411 c -> row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max_w", c -> row_max );
3412 c -> col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max_w", c -> col_max );
3414 c -> cell_width = pnd_conf_get_as_int_d ( g_conf, "grid.cell_width_w", c -> cell_width );
3415 c -> cell_height = pnd_conf_get_as_int_d ( g_conf, "grid.cell_height_w", c -> cell_height );
3417 c -> arrow_bar_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x_w", 450 );
3418 c -> arrow_bar_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y_w", 100 );
3419 c -> arrow_up_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x_w", 450 );
3420 c -> arrow_up_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y_w", 80 );
3421 c -> arrow_down_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x_w", 450 );
3422 c -> arrow_down_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y_w", 80 );
3424 } // if detail hidden.. still.
3426 } // if detail hidden
3431 unsigned char ui_is_detail_hideable ( void ) {
3433 // if skin has a bit of info for wide-mode, we assume wide-mode is available
3434 if ( pnd_conf_get_as_char ( g_conf, "grid.row_max_w" ) != NULL ) {
3442 void ui_toggle_detail_pane ( void ) {
3444 // no bitmask trickery here; I like it to be stand-out obvious at 3am.
3446 if ( ui_detail_hidden ) {
3447 ui_detail_hidden = 0;
3449 ui_detail_hidden = 1;
3452 // repull skin config
3453 ui_recache_context ( &ui_display_context );
3456 render_mask |= CHANGED_EVERYTHING;
3461 void ui_menu_context ( mm_appref_t *a ) {
3463 unsigned char rescan_apps = 0;
3464 unsigned char context_alive = 1;
3469 context_file_delete,
3472 context_app_recategorize,
3473 context_app_recategorize_sub,
3475 context_app_cpuspeed,
3483 char *verbiage[] = {
3484 "Done (return to grid)", // context_done
3485 "Get info about file/dir", // context_file_info
3486 "Delete file/dir", // context_file_delete
3487 "Get info", // context_app_info
3488 "Hide application", // hide
3489 "Recategorize", // recategorize
3490 "Recategorize subcategory", // recategorize
3491 "Change displayed title", // rename
3492 "Set CPU speed for launch", // cpuspeed
3493 "Run application", // run
3494 "Edit notes line 1", // notes1
3495 "Edit notes line 2", // notes2
3496 "Edit notes line 3", // notes3
3499 unsigned short int menu [ context_menu_max ];
3500 char *menustring [ context_menu_max ];
3501 unsigned char menumax = 0;
3504 menu [ menumax ] = context_done; menustring [ menumax++ ] = verbiage [ context_done ];
3506 // hook up appropriate menu options based on tab-type and object-type
3507 if ( g_categories [ ui_category ] -> fspath ) {
3509 menu [ menumax ] = context_file_info; menustring [ menumax++ ] = verbiage [ context_file_info ];
3510 menu [ menumax ] = context_file_delete; menustring [ menumax++ ] = verbiage [ context_file_delete ];
3513 if ( a -> ref -> object_type == pnd_object_type_directory ) {
3514 return; // don't do anything if the guy is a subcat-as-folder
3517 //menu [ menumax ] = context_app_info; menustring [ menumax++ ] = verbiage [ context_app_info ];
3518 menu [ menumax ] = context_app_run; menustring [ menumax++ ] = verbiage [ context_app_run ];
3519 menu [ menumax ] = context_app_hide; menustring [ menumax++ ] = verbiage [ context_app_hide ];
3520 menu [ menumax ] = context_app_recategorize; menustring [ menumax++ ] = verbiage [ context_app_recategorize ];
3521 menu [ menumax ] = context_app_recategorize_sub; menustring [ menumax++ ] = verbiage [ context_app_recategorize_sub ];
3522 menu [ menumax ] = context_app_rename; menustring [ menumax++ ] = verbiage [ context_app_rename ];
3523 menu [ menumax ] = context_app_cpuspeed; menustring [ menumax++ ] = verbiage [ context_app_cpuspeed ];
3524 menu [ menumax ] = context_app_notes1; menustring [ menumax++ ] = verbiage [ context_app_notes1 ];
3525 menu [ menumax ] = context_app_notes2; menustring [ menumax++ ] = verbiage [ context_app_notes2 ];
3526 menu [ menumax ] = context_app_notes3; menustring [ menumax++ ] = verbiage [ context_app_notes3 ];
3530 while ( context_alive ) {
3532 int sel = ui_modal_single_menu ( menustring, menumax, a -> ref -> title_en ? a -> ref -> title_en : "Quickpick Menu" /* title */, "B or Enter; other to cancel." /* footer */ );
3539 switch ( menu [ sel ] ) {
3545 case context_file_info:
3548 case context_file_delete:
3549 //ui_menu_twoby ( "Delete - Are you sure?", "B/enter; other to cancel", "Delete", "Do not delete" );
3552 case context_app_info:
3555 case context_app_hide:
3558 char confkey [ 1000 ];
3559 snprintf ( confkey, 999, "%s.%s", "appshow", a -> ref -> unique_id );
3562 pnd_conf_set_char ( g_conf, confkey, "0" );
3564 // write conf, so it will take next time
3565 conf_write ( g_conf, conf_determine_location ( g_conf ) );
3566 conf_write ( g_conf, CONF_PREF_TEMPPATH );
3568 // can we just 'hide' this guy without reloading all apps? (this is for you, EvilDragon)
3571 // DOESN'T WORK YET; other parts of app are still hanging onto some values and blow up
3573 char *uid = strdup ( a -> ref -> unique_id );
3575 for ( i = 0; i < g_categorycount; i++ ) {
3576 mm_appref_t *p = g_categories [ i ] -> refs;
3581 if ( strcmp ( p -> ref -> unique_id, uid ) == 0 ) {
3583 if ( g_categories [ i ] -> refcount ) {
3584 g_categories [ i ] -> refcount--;
3589 } // while for each appref
3590 } // for each cat/tab
3595 // request rescan and wrap up
3599 context_alive = 0; // nolonger visible, so lets just get out
3605 case context_app_recategorize:
3608 unsigned char optmax = 0;
3611 // show custom categories
3612 if ( mmcustom_setup() ) {
3614 for ( i = 0; i < mmcustom_count; i++ ) {
3615 if ( mmcustom_complete [ i ].parent_cat == NULL ) {
3616 opts [ optmax++ ] = mmcustom_complete [ i ].cat;
3622 // show FD categories
3623 i = 2; // skip first two - Other and NoParentCategory
3626 if ( ! freedesktop_complete [ i ].cat ) {
3630 if ( ! freedesktop_complete [ i ].parent_cat ) {
3631 opts [ optmax++ ] = freedesktop_complete [ i ].cat;
3638 char prompt [ 101 ];
3639 snprintf ( prompt, 100, "Pick category [%s]", a -> ref -> main_category ? a -> ref -> main_category : "NoParentCategory" );
3641 int sel = ui_modal_single_menu ( opts, optmax, prompt /*"Select parent category"*/, "Enter to select; other to skip." );
3644 char confirm [ 1001 ];
3645 snprintf ( confirm, 1000, "Confirm: %s", opts [ sel ] );
3647 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm categorization", "Do not set category" ) == 1 ) {
3648 ovr_replace_or_add ( a, "maincategory", opts [ sel ] );
3650 // when changing main cat, reset subcat, otherwise you go from Game/Emu to Network/Emu and get sent to Other right away
3651 ovr_replace_or_add ( a, "maincategorysub1", freedesktop_complete [ 2 ].cat );
3656 if ( mmcustom_is_ready() ) {
3657 mmcustom_shutdown();
3663 case context_app_recategorize_sub:
3666 unsigned char optmax = 0;
3667 unsigned char i = 0;
3669 char *whichparentarewe;
3670 if ( g_categories [ ui_category ] -> parent_catname ) {
3671 whichparentarewe = g_categories [ ui_category ] -> parent_catname;
3673 whichparentarewe = g_categories [ ui_category ] -> catname;
3676 // add NoSubcategory magic one
3677 opts [ optmax++ ] = freedesktop_complete [ 2 ].cat;
3679 // add custom categories
3680 if ( mmcustom_setup() ) {
3682 for ( i = 0; i < mmcustom_count; i++ ) {
3683 if ( mmcustom_complete [ i ].parent_cat && strcmp ( mmcustom_complete [ i ].parent_cat, whichparentarewe ) == 0 ) {
3684 opts [ optmax++ ] = mmcustom_complete [ i ].cat;
3690 // add FD categories
3693 if ( ! freedesktop_complete [ i ].cat ) {
3697 if ( ( freedesktop_complete [ i ].parent_cat ) &&
3698 ( strcasecmp ( freedesktop_complete [ i ].parent_cat, whichparentarewe ) == 0 )
3701 opts [ optmax++ ] = freedesktop_complete [ i ].cat;
3707 char prompt [ 101 ];
3708 //snprintf ( prompt, 100, "Currently: %s", a -> ref -> main_category1 ? a -> ref -> main_category1 : "NoSubcategory" );
3709 snprintf ( prompt, 100, "%s [%s]", a -> ref -> main_category1 ? a -> ref -> main_category1 : "NoSubcategory", whichparentarewe );
3711 int sel = ui_modal_single_menu ( opts, optmax, prompt /*"Select subcategory"*/, "Enter to select; other to skip." );
3714 char confirm [ 1001 ];
3715 snprintf ( confirm, 1000, "Confirm: %s", opts [ sel ] );
3717 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm sub-categorization", "Do not set sub-category" ) == 1 ) {
3718 ovr_replace_or_add ( a, "maincategorysub1", opts [ sel ] );
3724 if ( mmcustom_is_ready() ) {
3725 mmcustom_shutdown();
3731 case context_app_rename:
3733 char namebuf [ 101 ];
3734 unsigned char changed;
3736 changed = ui_menu_get_text_line ( "Rename application", "Use keyboard; Enter when done.",
3737 a -> ref -> title_en ? a -> ref -> title_en : "blank", namebuf, 30, 0 /* alphanumeric */ );
3740 char confirm [ 1001 ];
3741 snprintf ( confirm, 1000, "Confirm: %s", namebuf );
3743 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm rename", "Do not rename" ) == 1 ) {
3744 ovr_replace_or_add ( a, "title", namebuf );
3754 case context_app_cpuspeed:
3756 char namebuf [ 101 ];
3757 unsigned char changed;
3759 changed = ui_menu_get_text_line ( "Specify runspeed", "Use keyboard; Enter when done.",
3760 a -> ref -> clockspeed ? a -> ref -> clockspeed : "500", namebuf, 6, 1 /* numeric */ );
3763 char confirm [ 1001 ];
3764 snprintf ( confirm, 1000, "Confirm: %s", namebuf );
3766 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm clockspeed", "Do not set" ) == 1 ) {
3767 ovr_replace_or_add ( a, "clockspeed", namebuf );
3777 case context_app_run:
3781 case context_app_notes1:
3782 case context_app_notes2:
3783 case context_app_notes3:
3785 char namebuf [ 101 ] = "";
3788 unsigned char notenum;
3791 if ( menu [ sel ] == context_app_notes1 ) {
3793 } else if ( menu [ sel ] == context_app_notes2 ) {
3795 } else if ( menu [ sel ] == context_app_notes3 ) {
3799 // figure out key for looking up existing, and for storing replacement
3800 snprintf ( key, 500, "Application-%u.note-%u", a -> ref -> subapp_number, notenum );
3802 // do we have existing value?
3804 char *existing = pnd_conf_get_as_char ( a -> ovrh, key );
3806 strncpy ( namebuf, existing, 100 );
3810 unsigned char changed;
3812 changed = ui_menu_get_text_line ( "Enter replacement note", "Use keyboard; Enter when done.",
3813 namebuf, namebuf, 30, 0 /* not-numeric-forced */ );
3816 ovr_replace_or_add ( a, strchr ( key, '.' ) + 1, namebuf );
3828 } // if useful return
3833 if ( rescan_apps ) {
3834 applications_free();
3835 applications_scan();
3841 unsigned char ui_menu_oneby ( char *title, char *footer, char *one ) {
3844 int sel = ui_modal_single_menu ( opts, 1, title, footer );
3851 unsigned char ui_menu_twoby ( char *title, char *footer, char *one, char *two ) {
3855 int sel = ui_modal_single_menu ( opts, 2, title, footer );
3862 unsigned char ui_menu_get_text_line ( char *title, char *footer, char *initialvalue,
3863 char *r_buffer, unsigned char maxlen, unsigned char numbersonlyp )
3865 SDL_Rect rects [ 40 ];
3866 SDL_Rect *dest = rects;
3870 char hacktext [ 1024 ];
3871 unsigned char shifted = 0;
3873 bzero ( rects, sizeof(SDL_Rect) * 40 );
3875 if ( initialvalue ) {
3876 if ( initialvalue == r_buffer ) {
3877 // already good to go
3879 strncpy ( r_buffer, initialvalue, maxlen );
3882 bzero ( r_buffer, maxlen );
3888 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
3889 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
3890 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
3891 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
3892 SDL_FillRect( sdl_realscreen, dest, 0 );
3894 // show dialog background
3895 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
3898 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> w;
3899 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> h;
3900 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
3901 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
3902 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
3906 // show dialog frame
3907 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
3908 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
3909 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
3910 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
3916 rtext = TTF_RenderText_Blended ( g_tab_font, title, ui_display_context.fontcolor );
3917 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
3918 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
3919 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
3920 SDL_FreeSurface ( rtext );
3926 rtext = TTF_RenderText_Blended ( g_tab_font, footer, ui_display_context.fontcolor );
3927 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
3928 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
3929 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
3931 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
3932 SDL_FreeSurface ( rtext );
3936 // show text line - and embed cursor
3937 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
3938 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( 0/*i*/ + 1 - 0/*first_visible*/ ) );
3940 strncpy ( hacktext, r_buffer, 1000 );
3941 strncat ( hacktext, "\n", 1000 ); // add [] in most fonts
3943 rtext = TTF_RenderText_Blended ( g_tab_font, hacktext, ui_display_context.fontcolor );
3944 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
3945 SDL_FreeSurface ( rtext );
3948 // update all the rects and send it all to sdl
3949 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
3954 while ( SDL_WaitEvent ( &event ) ) {
3956 switch ( event.type ) {
3959 if ( event.key.keysym.sym == SDLK_LSHIFT || event.key.keysym.sym == SDLK_RSHIFT ) {
3966 if ( event.key.keysym.sym == SDLK_LEFT || event.key.keysym.sym == SDLK_BACKSPACE ) {
3967 if ( strlen ( r_buffer ) > 0 ) {
3968 char *eol = strchr ( r_buffer, '\0' );
3969 *( eol - 1 ) = '\0';
3972 } else if ( event.key.keysym.sym == SDLK_UP ) {
3973 r_buffer [ 0 ] = '\0'; // truncate!
3975 } else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_END ) { // return, or "B"
3976 // on Enter/Return or B, if the buffer has 1 or more chars, we return it as valid.. otherwise, invalid.
3977 if ( strlen ( r_buffer ) > 0 ) {
3982 } else if ( event.key.keysym.sym == SDLK_LSHIFT || event.key.keysym.sym == SDLK_RSHIFT ) {
3985 } else if ( event.key.keysym.sym == SDLK_ESCAPE ||
3986 event.key.keysym.sym == SDLK_PAGEUP ||
3987 event.key.keysym.sym == SDLK_PAGEDOWN ||
3988 event.key.keysym.sym == SDLK_HOME
3995 if ( isprint(event.key.keysym.sym) ) {
3997 unsigned char good = 1;
3999 if ( numbersonlyp && ( ! isdigit(event.key.keysym.sym) ) ) {
4003 if ( maxlen && strlen(r_buffer) >= maxlen ) {
4008 char b [ 2 ] = { '\0', '\0' };
4010 b [ 0 ] = toupper ( event.key.keysym.sym );
4012 b [ 0 ] = event.key.keysym.sym;
4014 strncat ( r_buffer, b, maxlen );
4027 } // while waiting for input
4034 unsigned char ovr_replace_or_add ( mm_appref_t *a, char *keybase, char *newvalue ) {
4035 //printf ( "setting %s:%u - '%s' to '%s' - %s/%s\n", a -> ref -> title_en, a -> ref -> subapp_number, keybase, newvalue, a -> ref -> object_path, a -> ref -> object_filename );
4037 char fullpath [ PATH_MAX ];
4039 sprintf ( fullpath, "%s/%s", a -> ref -> object_path, a -> ref -> object_filename );
4040 char *dot = strrchr ( fullpath, '.' );
4042 sprintf ( dot, PXML_SAMEPATH_OVERRIDE_FILEEXT );
4044 pnd_log ( pndn_error, "ERROR: Bad pnd-path in disco_t! %s\n", fullpath );
4048 struct stat statbuf;
4050 if ( stat ( fullpath, &statbuf ) == 0 ) {
4054 h = pnd_conf_fetch_by_path ( fullpath );
4057 return ( 0 ); // fail!
4061 snprintf ( key, 100, "Application-%u.%s", a -> ref -> subapp_number, keybase );
4063 pnd_conf_set_char ( h, key, newvalue );
4065 return ( pnd_conf_write ( h, fullpath ) );
4068 // file needs to be created - easy!
4070 FILE *f = fopen ( fullpath, "w" );
4073 fprintf ( f, "Application-%u.%s\t%s\n", a -> ref -> subapp_number, keybase, newvalue );
4077 return ( 0 ); // fail!
4085 void ui_manage_categories ( void ) {
4086 unsigned char require_app_scan = 0;
4088 if ( ! mmcustom_setup() ) {
4092 char *opts [ 20 ] = {
4093 "List custom categories",
4094 "List custom subcategories",
4095 "Register custom category",
4096 "Register custom subcategory",
4097 "Unregister custom category",
4098 "Unregister custom subcategory",
4104 int sel = ui_modal_single_menu ( opts, 7, "Custom Categories", "B to select; other to cancel." );
4108 case 0: // list custom
4109 ui_pick_custom_category ( 0 );
4112 case 1: // list custom sub
4113 if ( mmcustom_count ) {
4115 char *maincat = ui_pick_custom_category ( 2 );
4118 unsigned int subcount = mmcustom_count_subcats ( maincat );
4119 char titlebuf [ 201 ];
4121 snprintf ( titlebuf, 200, "Category: %s", maincat );
4123 if ( subcount == 0 ) {
4124 ui_menu_oneby ( titlebuf, "B/Enter to accept", "Category has no subcategories." );
4127 char **list = malloc ( subcount * sizeof(char*) );
4129 unsigned int counter = 0;
4131 for ( i = 0; i < mmcustom_count; i++ ) {
4132 if ( mmcustom_complete [ i ].parent_cat && strcasecmp ( mmcustom_complete [ i ].parent_cat, maincat ) == 0 ) {
4133 list [ counter++ ] = mmcustom_complete [ i ].cat;
4137 ui_modal_single_menu ( list, counter, titlebuf, "Any button to exit." );
4141 } // more than 0 subcats?
4143 } // user picked a main cat?
4146 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4150 case 2: // register custom
4152 unsigned char changed;
4153 char namebuf [ 101 ] = "";
4155 changed = ui_menu_get_text_line ( "Enter unique category name", "Use keyboard; Enter when done.",
4156 "Pandora", namebuf, 30, 0 /* alphanumeric */ );
4158 // did the user enter something?
4161 // and if so, is it existant already or not?
4162 if ( mmcustom_query ( namebuf, NULL ) ) {
4163 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a registered category." );
4164 } else if ( freedesktop_category_query ( namebuf, NULL ) ) {
4165 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a Standard category." );
4168 char confirm [ 1001 ];
4169 snprintf ( confirm, 1000, "Confirm: %s", namebuf );
4171 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm new category", "Do not register" ) == 1 ) {
4172 // register, save, recycle the current list
4173 mmcustom_register ( namebuf, NULL );
4174 mmcustom_write ( NULL );
4175 mmcustom_shutdown();
4181 } // entered something?
4186 case 3: // register custom sub
4187 if ( 1 /*mmcustom_count -- we allow FD cats now, so this isn't applicable error */ ) {
4189 char *maincat = ui_pick_custom_category ( 1 /* include FD */ );
4192 char titlebuf [ 201 ];
4194 snprintf ( titlebuf, 200, "Subcat of: %s", maincat );
4196 unsigned char changed;
4197 char namebuf [ 101 ] = "";
4199 changed = ui_menu_get_text_line ( titlebuf, "Use keyboard; Enter when done.", "Submarine", namebuf, 30, 0 /* alphanumeric */ );
4201 // did the user enter something?
4204 // and if so, is it existant already or not?
4205 if ( mmcustom_query ( namebuf, maincat ) ) {
4206 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a subcategory." );
4207 } else if ( freedesktop_category_query ( namebuf, maincat ) ) {
4208 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a Standard subcategory." );
4211 char confirm [ 1001 ];
4212 snprintf ( confirm, 1000, "Confirm: %s [%s]", namebuf, maincat );
4214 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm new category", "Do not register" ) == 1 ) {
4215 // register, save, recycle the current list
4216 mmcustom_register ( namebuf, maincat );
4217 mmcustom_write ( NULL );
4218 mmcustom_shutdown();
4224 } // entered something?
4226 } // selected parent cat?
4229 ui_menu_oneby ( "Warning", "B/Enter to accept", "No categories registered." );
4233 case 4: // unreg custom
4234 if ( mmcustom_count ) {
4235 char *maincat = ui_pick_custom_category ( 0 );
4238 char confirm [ 1001 ];
4239 snprintf ( confirm, 1000, "Confirm remove: %s", maincat );
4241 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm unregister", "Do not unregister" ) == 1 ) {
4242 // register, save, recycle the current list
4243 mmcustom_unregister ( maincat, NULL );
4244 mmcustom_write ( NULL );
4245 mmcustom_shutdown();
4252 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4256 case 5: // unreg custom sub
4257 if ( mmcustom_count ) {
4258 char *maincat = ui_pick_custom_category ( 2 );
4261 unsigned int subcount = mmcustom_count_subcats ( maincat );
4262 char titlebuf [ 201 ];
4264 snprintf ( titlebuf, 200, "Category: %s", maincat );
4266 if ( subcount == 0 ) {
4267 ui_menu_oneby ( titlebuf, "B/Enter to accept", "Category has no subcategories." );
4270 char **list = malloc ( subcount * sizeof(char*) );
4272 unsigned int counter = 0;
4274 for ( i = 0; i < mmcustom_count; i++ ) {
4275 if ( mmcustom_complete [ i ].parent_cat && strcasecmp ( mmcustom_complete [ i ].parent_cat, maincat ) == 0 ) {
4276 list [ counter++ ] = mmcustom_complete [ i ].cat;
4280 int sel = ui_modal_single_menu ( list, counter, titlebuf, "B to selct; other to exit." );
4283 char confirm [ 1001 ];
4284 snprintf ( confirm, 1000, "Confirm remove: %s", list [ sel ] );
4286 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm unregister", "Do not unregister" ) == 1 ) {
4287 // register, save, recycle the current list
4288 mmcustom_unregister ( list [ sel ], maincat );
4289 mmcustom_write ( NULL );
4290 mmcustom_shutdown();
4298 } // more than 0 subcats?
4300 } // user picked a main cat?
4303 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4310 if ( sel < 0 || sel > 5 ) {
4314 } // while running the menu
4316 // shut down custom cats
4317 mmcustom_shutdown();
4320 if ( require_app_scan ) {
4321 applications_free();
4322 applications_scan();
4326 render_mask |= CHANGED_EVERYTHING;
4331 // mode 0 == custom main only; 1 == custom main + FD main; 2 == custom main + FD mains-with-custom-subs
4332 char *ui_pick_custom_category ( unsigned char mode ) {
4335 unsigned int counter = 0;
4337 // alloc space for list, depending on scope
4339 list = malloc ( (mmcustom_count+freedesktop_count()) * sizeof(char*) );
4341 list = malloc ( mmcustom_count * sizeof(char*) );
4345 for ( i = 0; i < mmcustom_count; i++ ) {
4346 if ( mmcustom_complete [ i ].parent_cat == NULL ) {
4347 list [ counter++ ] = mmcustom_complete [ i ].cat;
4357 if ( ! freedesktop_complete [ i ].cat ) {
4362 if ( freedesktop_complete [ i ].parent_cat == NULL ) {
4364 // mode 1 == include them all
4365 // mode 2 == include them if they have a custom subcat
4366 if ( ( mode == 1 ) ||
4367 ( mmcustom_subcount ( freedesktop_complete [ i ].cat ) ) )
4369 list [ counter++ ] = freedesktop_complete [ i ].cat;
4379 // we actually showing anything?
4381 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4386 int sel = ui_modal_single_menu ( list, counter, "Custom Categories", "Any button to exit." );
4393 char *foo = list [ sel ];
4399 void ui_start_defered_icon_thread ( void ) {
4400 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 0 ) {
4404 if ( g_icon_thread_busy ) {
4405 //fprintf ( stderr, "REM: Waiting for thread to stop..\n" );
4406 ui_stop_defered_icon_thread();
4409 //fprintf ( stderr, "WARN: Starting new icon caching thread..\n" );
4410 g_icon_thread = SDL_CreateThread ( (void*)ui_threaded_defered_icon, NULL );
4412 if ( ! g_icon_thread ) {
4413 pnd_log ( pndn_error, "ERROR: Couldn't create icon thread\n" );
4419 void ui_stop_defered_icon_thread ( void ) {
4420 time_t started = time ( NULL );
4422 // ask thread to stop, then wait for it (if two run at same time, or if we change
4423 // category content under neath it, could be bad..)
4424 g_icon_thread_stop = 1;
4425 while ( g_icon_thread_busy ) {
4426 time ( NULL ); // spin
4428 g_icon_thread_stop = 0;
4430 fprintf ( stderr, "REM: Thread stoppage took %u seconds.\n", (int) ( time ( NULL ) - started ) );