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_viewmode_e ui_viewmode = uiv_icons; // default to traditional icon view; why or why is viewstate not per-viewmode :/
93 ui_context_t ui_display_context; // display paramaters: see mmui_context.h
94 unsigned char ui_detail_hidden = 0; // if >0, detail panel is hidden
95 // FUTURE: If multiple panels can be shown/hidden, convert ui_detail_hidden to a bitmask
97 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ); // height -1 means ignore
99 static int ui_selected_index ( void );
100 static void ui_start_defered_icon_thread ( void );
101 static void ui_stop_defered_icon_thread ( void );
103 unsigned char ui_setup ( void ) {
108 SDL_Init ( SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE );
110 SDL_JoystickOpen ( 0 ); // turn on joy-0
112 SDL_WM_SetCaption ( "mmenu", "mmenu" );
114 // hide the mouse cursor if we can
115 if ( SDL_ShowCursor ( -1 ) == 1 ) {
116 SDL_ShowCursor ( 0 );
122 unsigned int svm = SDL_SWSURFACE /*| SDL_FULLSCREEN*/ /* 0*/;
123 if ( pnd_conf_get_as_int_d ( g_conf, "display.fullscreen", 0 ) > 0 ) {
124 svm |= SDL_FULLSCREEN;
128 SDL_SetVideoMode ( 800 * g_scale, 480 * g_scale, 16 /*bpp*/, svm );
130 if ( ! sdl_realscreen ) {
131 pnd_log ( pndn_error, "ERROR: Couldn't open SDL real screen; dieing." );
135 pnd_log ( pndn_debug, "Pixel format:" );
136 pnd_log ( pndn_debug, "bpp b: %u\n", sdl_realscreen -> format -> BitsPerPixel );
137 pnd_log ( pndn_debug, "bpp B: %u\n", sdl_realscreen -> format -> BytesPerPixel );
138 pnd_log ( pndn_debug, "R mask: %08x\n", sdl_realscreen -> format -> Rmask );
139 pnd_log ( pndn_debug, "G mask: %08x\n", sdl_realscreen -> format -> Gmask );
140 pnd_log ( pndn_debug, "B mask: %08x\n", sdl_realscreen -> format -> Bmask );
146 /* Set 16-bit stereo audio at 22Khz */
147 fmt.freq = 44100; //22050;
148 fmt.format = AUDIO_S16; //AUDIO_S16;
150 fmt.samples = 2048; /* A good value for games */
151 fmt.callback = mixaudio;
154 /* Open the audio device and start playing sound! */
155 if ( SDL_OpenAudio ( &fmt, NULL ) < 0 ) {
156 zotlog ( "Unable to open audio: %s\n", SDL_GetError() );
160 SDL_PauseAudio ( 0 );
165 SDL_EnableKeyRepeat ( 500, 125 /* 150 */ );
168 //IMG_Init ( IMG_INIT_JPG | IMG_INIT_PNG );
174 if ( TTF_Init() == -1 ) {
175 pnd_log ( pndn_error, "ERROR: Couldn't set up SDL TTF lib\n" );
176 return ( 0 ); // couldn't set up SDL TTF
179 char fullpath [ PATH_MAX ];
181 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "minimenu.font" ) );
182 g_big_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
183 if ( ! g_big_font ) {
184 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
185 pnd_conf_get_as_char ( g_conf, "minimenu.font" ), pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
186 return ( 0 ); // couldn't set up SDL TTF
190 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "grid.font" ) );
191 g_grid_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
192 if ( ! g_grid_font ) {
193 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
194 pnd_conf_get_as_char ( g_conf, "grid.font" ), pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
195 return ( 0 ); // couldn't set up SDL TTF
199 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "detailtext.font" ) );
200 g_detailtext_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
201 if ( ! g_detailtext_font ) {
202 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
203 pnd_conf_get_as_char ( g_conf, "detailtext.font" ), pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
204 return ( 0 ); // couldn't set up SDL TTF
208 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "tabs.font" ) );
209 g_tab_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
210 if ( ! g_tab_font ) {
211 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
212 pnd_conf_get_as_char ( g_conf, "tabs.font" ), pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
213 return ( 0 ); // couldn't set up SDL TTF
216 // determine display context
217 if ( pnd_conf_get_as_int_d ( g_conf, "display.show_detail_pane", 1 ) > 0 ) {
218 ui_detail_hidden = 0;
220 ui_detail_hidden = 1;
223 // determine default viewmode
224 if ( pnd_conf_get_as_int_d ( g_conf, "display.viewmode_list", -1 ) != -1 ) {
225 int i = pnd_conf_get_as_int_d ( g_conf, "display.viewmode_list", 0 );
226 if ( i >= uiv_max ) {
227 ui_viewmode = uiv_icons;
233 // update display context
234 ui_recache_context ( &ui_display_context );
239 mm_imgcache_t g_imagecache [ IMG_TRUEMAX ] = {
240 { IMG_BACKGROUND_800480, "graphics.IMG_BACKGROUND_800480" },
241 { IMG_BACKGROUND_TABMASK, "graphics.IMG_BACKGROUND_TABMASK" },
242 { IMG_DETAIL_PANEL, "graphics.IMG_DETAIL_PANEL" },
243 { IMG_DETAIL_BG, "graphics.IMG_DETAIL_BG" },
244 { IMG_SELECTED_ALPHAMASK, "graphics.IMG_SELECTED_ALPHAMASK" },
245 { IMG_TAB_SEL, "graphics.IMG_TAB_SEL" },
246 { IMG_TAB_SEL_L, "graphics.IMG_TAB_SEL_L" },
247 { IMG_TAB_SEL_R, "graphics.IMG_TAB_SEL_R" },
248 { IMG_TAB_UNSEL, "graphics.IMG_TAB_UNSEL" },
249 { IMG_TAB_UNSEL_L, "graphics.IMG_TAB_UNSEL_L" },
250 { IMG_TAB_UNSEL_R, "graphics.IMG_TAB_UNSEL_R" },
251 { IMG_TAB_LINE, "graphics.IMG_TAB_LINE" },
252 { IMG_TAB_LINEL, "graphics.IMG_TAB_LINEL" },
253 { IMG_TAB_LINER, "graphics.IMG_TAB_LINER" },
254 { IMG_ICON_MISSING, "graphics.IMG_ICON_MISSING" },
255 { IMG_SELECTED_HILITE, "graphics.IMG_SELECTED_HILITE" },
256 { IMG_PREVIEW_MISSING, "graphics.IMG_PREVIEW_MISSING" },
257 { IMG_ARROW_UP, "graphics.IMG_ARROW_UP", },
258 { IMG_ARROW_DOWN, "graphics.IMG_ARROW_DOWN", },
259 { IMG_ARROW_SCROLLBAR, "graphics.IMG_ARROW_SCROLLBAR", },
260 { IMG_HOURGLASS, "graphics.IMG_HOURGLASS", },
261 { IMG_FOLDER, "graphics.IMG_FOLDER", },
262 { IMG_EXECBIN, "graphics.IMG_EXECBIN", },
263 { IMG_SUBCATFOLDER, "graphics.IMG_SUBCATFOLDER", "graphics.IMG_FOLDER", },
264 { IMG_DOTDOTFOLDER, "graphics.IMG_DOTDOTFOLDER", "graphics.IMG_FOLDER", },
266 { IMG_LIST_ALPHAMASK, NULL }, // generated
267 { IMG_LIST_ALPHAMASK_W, NULL }, // generated
270 unsigned char ui_imagecache ( char *basepath ) {
272 char fullpath [ PATH_MAX ];
277 for ( i = 0; i < IMG_MAX; i++ ) {
279 if ( g_imagecache [ i ].id != i ) {
280 pnd_log ( pndn_error, "ERROR: Internal table mismatch during caching [%u]\n", i );
284 for ( try = 0; try < 2; try++ ) {
289 filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].confname );
291 if ( g_imagecache [ i ].alt_confname ) {
292 filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].alt_confname );
299 pnd_log ( pndn_error, "ERROR: (Try %u) Missing filename in conf for key: %s\n", try + 1, g_imagecache [ i ].confname );
300 if ( try == 0 ) { continue; } else { return ( 0 ); }
303 if ( filename [ 0 ] == '/' ) {
304 strncpy ( fullpath, filename, PATH_MAX );
306 sprintf ( fullpath, "%s/%s", basepath, filename );
309 if ( ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
311 // also make a 'tiny' version..
312 SDL_Surface *s = g_imagecache [ i ].i;
313 SDL_Surface *scaled_tiny = SDL_ConvertSurface ( s, s -> format, s -> flags ); // duplicate
314 extern ui_context_t ui_display_context;
315 scaled_tiny = ui_scale_image ( scaled_tiny, -1 , ui_display_context.text_height_tab ); // resize
316 g_imagecache [ i ].itiny = scaled_tiny;
318 break; // no retry needed
320 pnd_log ( pndn_error, "ERROR: (Try %u) Couldn't load static cache image: %s\n", try + 1, fullpath );
321 if ( try == 0 ) { continue; } else { return ( 0 ); }
331 //g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = SDL_CreateRGBSurface ( SDL_SWSURFACE, 60, 60, 32, 0xFF0000, 0x00FF00, 0xFF, 0xFF000000 );
332 //boxRGBA ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, 0, 0, 60, 60, 100, 100, 100, 250 );
334 SDL_Surface *p = g_imagecache [ IMG_SELECTED_ALPHAMASK ].i;
335 g_imagecache [ IMG_LIST_ALPHAMASK ].i = SDL_ConvertSurface ( p, p -> format, p -> flags );
336 g_imagecache [ IMG_LIST_ALPHAMASK_W ].i = SDL_ConvertSurface ( p, p -> format, p -> flags );
338 g_imagecache [ IMG_LIST_ALPHAMASK ].i =
339 ui_scale_image ( g_imagecache [ IMG_LIST_ALPHAMASK ].i,
340 pnd_conf_get_as_int ( g_conf, "grid.col_max" ) * pnd_conf_get_as_int ( g_conf, "grid.cell_width" ) , -1 );
342 g_imagecache [ IMG_LIST_ALPHAMASK_W ].i =
343 ui_scale_image ( g_imagecache [ IMG_LIST_ALPHAMASK_W ].i,
344 pnd_conf_get_as_int ( g_conf, "grid.col_max_w" ) * pnd_conf_get_as_int ( g_conf, "grid.cell_width_w" ) , -1 );
350 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 );
351 // scale text hilight
352 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 );
353 // scale preview no-pic
354 g_imagecache [ IMG_PREVIEW_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_PREVIEW_MISSING ].i,
355 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ),
356 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 50 ) );
358 // set alpha on detail panel
359 //SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
364 void ui_render ( void ) {
367 // divide width: 550 / 250
368 // divide left side: 5 columns == 110px width
369 // 20px buffer either side == 70px wide icon + 20 + 20?
371 // what jobs to do during render?
375 #define R_TABS (1<<1)
376 #define R_DETAIL (1<<2)
377 #define R_GRID (1<<3)
379 #define R_ALL (R_BG|R_TABS|R_DETAIL|R_GRID)
381 unsigned int render_jobs_b = 0;
383 if ( render_mask & CHANGED_EVERYTHING ) {
384 render_jobs_b |= R_ALL;
387 if ( render_mask & CHANGED_SELECTION ) {
388 render_jobs_b |= R_GRID;
389 render_jobs_b |= R_DETAIL;
392 if ( render_mask & CHANGED_CATEGORY ) {
393 render_jobs_b |= R_ALL;
396 render_mask = CHANGED_NOTHING;
400 unsigned int icon_rows;
401 unsigned int icon_visible_rows = 0; // list view, max number of visible rows
404 SDL_Rect rects [ MAXRECTS ], src;
405 SDL_Rect *dest = rects;
406 bzero ( dest, sizeof(SDL_Rect)*MAXRECTS );
408 unsigned int row, displayrow, col;
409 mm_appref_t *appiter;
411 ui_context_t *c = &ui_display_context; // for convenience and shorthand
413 // on demand icon loading
414 static int load_visible = -1;
415 if ( load_visible == -1 ) {
416 load_visible = pnd_conf_get_as_int_d ( g_conf, "minimenu.load_visible_icons", 0 );
420 // if no selected app yet, select the first one
421 if ( ! ui_selected && pnd_conf_get_as_int_d ( g_conf, "minimenu.start_selected", 0 ) ) {
423 // pick first visible app
424 ui_selected = g_categories [ ui_category ] -> refs;
426 // change.. so we pick first visible if option is set .. but now we also try to restore
427 // selection to the last app selected in previous session (if there is one.)
428 char *previous_unique_id = pnd_conf_get_as_char ( g_conf, "minimenu.last_known_app_uid" );
430 if ( previous_unique_id ) {
432 // 1) we should already be in the right category, since its set in ui_post_scan to minimenu.last_known_catname
433 // 2) so we just pick the app in question..
434 mm_appref_t *previter = g_categories [ ui_category ] -> refs;
436 if ( strcmp ( previter -> ref -> unique_id, previous_unique_id ) == 0 ) {
439 previter = previter -> next;
443 ui_selected = previter;
451 // how many total rows do we need?
452 if ( g_categorycount ) {
454 if ( ui_viewmode == uiv_list ) {
455 // in list view, dimension of grid area is ..
456 // grid height == cell-height * row-max
457 // font height == display_context -> text_height
458 // padding == icon_offset_y
459 // max visible --> row-max == grid height / ( font-height + padding )
461 icon_rows = g_categories [ ui_category ] -> refcount; // one app per row
462 icon_visible_rows = ( c -> cell_height * c -> row_max ) / ( c -> text_height_tab + c -> icon_offset_y );
466 icon_rows = g_categories [ ui_category ] -> refcount / c -> col_max;
467 if ( g_categories [ ui_category ] -> refcount % c -> col_max > 0 ) {
475 icon_visible_rows = 0;
478 // reset touchscreen regions
479 if ( render_jobs_b ) {
483 // ensure selection is visible
486 unsigned char autoscrolled = 1;
487 while ( autoscrolled ) {
490 int index = ui_selected_index();
492 if ( ui_viewmode == uiv_list ) {
494 if ( index >= ui_rows_scrolled_down + icon_visible_rows ) {
495 ui_rows_scrolled_down += 1;
497 render_jobs_b |= R_ALL;
498 } else if ( index < ui_rows_scrolled_down ) {
499 ui_rows_scrolled_down -= 1;
501 render_jobs_b |= R_ALL;
507 int topleft = c -> col_max * ui_rows_scrolled_down;
508 int botright = ( c -> col_max * ( ui_rows_scrolled_down + c -> row_max ) - 1 );
510 if ( index < topleft ) {
511 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
512 render_jobs_b |= R_ALL;
514 } else if ( index > botright ) {
515 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
516 render_jobs_b |= R_ALL;
522 } // while autoscrolling
524 if ( ui_rows_scrolled_down < 0 ) {
525 ui_rows_scrolled_down = 0;
526 } else if ( ui_rows_scrolled_down > icon_rows ) {
527 ui_rows_scrolled_down = icon_rows;
533 if ( render_jobs_b & R_BG ) {
535 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
538 dest -> w = sdl_realscreen -> w;
539 dest -> h = sdl_realscreen -> h;
540 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
545 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
548 dest -> w = sdl_realscreen -> w;
549 dest -> h = sdl_realscreen -> h;
550 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
557 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
558 static unsigned int tab_width;
559 static unsigned int tab_height;
560 static unsigned int tab_offset_x;
561 static unsigned int tab_offset_y;
562 static unsigned int text_offset_x;
563 static unsigned int text_offset_y;
564 static unsigned int text_width;
566 static unsigned char tab_first_run = 1;
567 if ( tab_first_run ) {
569 tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
570 tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
571 tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
572 tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
573 text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
574 text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
575 text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
578 unsigned int maxtab = ( c -> screen_width / tab_width ) < g_categorycount ? ( c -> screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift;
579 unsigned int maxtabspot = ( c -> screen_width / tab_width );
581 if ( g_categorycount > 0 ) {
583 // draw tabs with categories
584 for ( col = ui_catshift;
591 // if this is the first (leftmost) tab, we use different artwork
592 // than if the other tabs (so skinner can link lines up nicely.)
593 if ( col == ui_catshift ) {
594 // leftmost tab, special case
596 if ( col == ui_category ) {
597 s = g_imagecache [ IMG_TAB_SEL_L ].i;
599 s = g_imagecache [ IMG_TAB_UNSEL_L ].i;
602 } else if ( col == maxtab - 1 ) {
603 // rightmost tab, special case
605 if ( col == ui_category ) {
606 s = g_imagecache [ IMG_TAB_SEL_R ].i;
608 s = g_imagecache [ IMG_TAB_UNSEL_R ].i;
612 // normal (not leftmost) tab
614 if ( col == ui_category ) {
615 s = g_imagecache [ IMG_TAB_SEL ].i;
617 s = g_imagecache [ IMG_TAB_UNSEL ].i;
620 } // first col, or not first col?
627 if ( col == ui_category ) {
628 src.h = tab_selheight;
636 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
637 dest -> y = tab_offset_y;
640 ui_register_tab ( col, dest -> x, dest -> y, tab_width, tab_height );
642 if ( render_jobs_b & R_TABS ) {
643 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
644 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
648 if ( col == ui_category ) {
649 // no line for selected tab
651 if ( col - ui_catshift == 0 ) {
652 s = g_imagecache [ IMG_TAB_LINEL ].i;
653 } else if ( col - ui_catshift == maxtabspot - 1 ) {
654 s = g_imagecache [ IMG_TAB_LINER ].i;
656 s = g_imagecache [ IMG_TAB_LINE ].i;
658 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
659 dest -> y = tab_offset_y + tab_height;
660 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
666 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ] -> catname, c -> fontcolor );
669 src.w = rtext -> w < text_width ? rtext -> w : text_width;
671 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
672 dest -> y = tab_offset_y + text_offset_y;
673 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
674 SDL_FreeSurface ( rtext );
681 } // if we got categories
683 if ( render_jobs_b & R_TABS ) {
685 // draw tab lines under where tabs would be if we had categories
686 for ( /* foo */; col < maxtabspot; col++ ) {
689 if ( col - ui_catshift == 0 ) {
690 s = g_imagecache [ IMG_TAB_LINEL ].i;
691 } else if ( col - ui_catshift == maxtabspot - 1 ) {
692 s = g_imagecache [ IMG_TAB_LINER ].i;
694 s = g_imagecache [ IMG_TAB_LINE ].i;
696 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
697 dest -> y = tab_offset_y + tab_height;
698 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
707 // scroll bars and arrows
708 if ( render_jobs_b & R_BG ) {
709 unsigned char show_bar = 0;
712 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
713 dest -> x = c -> arrow_up_x;
714 dest -> y = c -> arrow_up_y;
715 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
722 if ( ui_rows_scrolled_down + c -> row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
723 dest -> x = c -> arrow_down_x;
724 dest -> y = c -> arrow_down_y;
725 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
732 // show scrollbar as well
735 src.w = c -> arrow_bar_clip_w;
736 src.h = c -> arrow_bar_clip_h;
737 dest -> x = c -> arrow_bar_x;
738 dest -> y = c -> arrow_bar_y;
739 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
743 } // r_bg, scroll bars
745 // render detail pane bg
746 if ( render_jobs_b & R_DETAIL && ui_detail_hidden == 0 ) {
748 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
751 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
752 src.x = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
753 src.y = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
754 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
755 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
756 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
757 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
758 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
762 // render detail pane
763 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
764 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
765 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
766 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
770 } // detailpane frame/bg
774 // anything to render?
775 if ( render_jobs_b & R_GRID && g_categorycount ) {
777 // if just rendering grid, and nothing else, better clear it first
778 if ( ! ( render_jobs_b & R_BG ) ) {
779 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
780 src.x = c -> grid_offset_x;
781 src.y = c -> grid_offset_y + c -> sel_icon_offset_y;
782 src.w = c -> col_max * c -> cell_width;
783 src.h = c -> row_max * c -> cell_height;
785 dest -> x = c -> grid_offset_x;
786 dest -> y = c -> grid_offset_y + c -> sel_icon_offset_y;
788 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
794 // any apps to render at all?
795 if ( g_categories [ ui_category ] -> refs ) {
797 // render grid differently based on view mode..
799 if ( ui_viewmode == uiv_list ) {
801 appiter = g_categories [ ui_category ] -> refs;
802 row = 0; // row under consideration (ie: could be scrolled off)
803 displayrow = 0; // rows displayed
805 while ( appiter != NULL ) {
807 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
808 if ( row >= ui_rows_scrolled_down ) {
810 // background hilight
811 SDL_Surface *hilight = ui_detail_hidden ? g_imagecache [ IMG_LIST_ALPHAMASK_W ].i : g_imagecache [ IMG_LIST_ALPHAMASK ].i;
812 if ( appiter == ui_selected ) {
815 src.w = hilight -> w;
816 src.h = c -> text_height_tab + c -> icon_offset_y;
817 dest -> x = c -> grid_offset_x + c -> text_clip_x;
818 dest -> y = c -> grid_offset_y + ( displayrow * ( c -> text_height_tab + c -> icon_offset_y ) ) - ( c -> icon_offset_y / 2 );
819 SDL_BlitSurface ( hilight, &src, sdl_realscreen, dest );
824 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
825 SDL_Surface *iconsurface = NULL;
827 // if icon not in cache, and its a pnd-file source, perhaps try to load it right now..
830 ( ! ( appiter -> ref -> object_flags & PND_DISCO_GENERATED ) )
833 // try to load any icons that..
834 // - are not yet loaded
835 // - did not fail a previous load attempt
836 // this way user can upfront load all icons, or defer all icons, or even defer all icons
837 // and still try to load visible ones 'just before needed'; so not at mmenu load time, but
838 // as needed (only the ones needed.)
840 if ( ( appiter -> ref -> pnd_icon_pos ) ||
841 ( appiter -> ref -> icon && appiter -> ref -> object_flags & PND_DISCO_LIBPND_DD )
846 if ( ! cache_icon ( appiter -> ref, ui_display_context.icon_max_width, ui_display_context.icon_max_width ) ) {
851 appiter -> ref -> pnd_icon_pos = 0;
852 if ( appiter -> ref -> icon ) {
853 free ( appiter -> ref -> icon );
854 appiter -> ref -> icon = NULL;
857 // pick up as if nothing happened..
858 ic = cache_query_icon ( appiter -> ref -> unique_id );
862 } // load icon during rendering?
865 iconsurface = ic -> itiny;
867 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
869 // no icon override; was this a pnd-file (show the unknown icon then), or was this generated from
870 // filesystem (file or directory icon)
871 if ( appiter -> ref -> object_flags & PND_DISCO_GENERATED ) {
872 if ( appiter -> ref -> object_type == pnd_object_type_directory ) {
874 // is this a subcat, a .., or a filesystem folder?
875 //iconsurface = g_imagecache [ IMG_FOLDER ].i;
876 if ( g_categories [ ui_category ] -> fspath ) {
877 iconsurface = g_imagecache [ IMG_FOLDER ].itiny;
878 } else if ( strcmp ( appiter -> ref -> title_en, ".." ) == 0 ) {
879 iconsurface = g_imagecache [ IMG_DOTDOTFOLDER ].itiny;
881 iconsurface = g_imagecache [ IMG_SUBCATFOLDER ].itiny;
885 iconsurface = g_imagecache [ IMG_EXECBIN ].itiny;
888 iconsurface = g_imagecache [ IMG_ICON_MISSING ].itiny;
894 dest -> x = c -> grid_offset_x + c -> text_clip_x;
895 dest -> y = c -> grid_offset_y + ( displayrow * ( c -> text_height_tab + c -> icon_offset_y ) ) - ( c -> icon_offset_y / 2 );
896 SDL_BlitSurface ( iconsurface, NULL, sdl_realscreen, dest );
900 if ( appiter -> ref -> title_en ) {
902 rtext = TTF_RenderText_Blended ( g_tab_font, appiter -> ref -> title_en, c -> fontcolor );
905 src.w = hilight -> w; //c -> text_width < rtext -> w ? c -> text_width : rtext -> w;
908 dest -> x = c -> grid_offset_x + c -> text_clip_x;
909 dest -> x += 30; // so all title-text line up, regardless of icon presence
912 dest -> x += 30; //((SDL_Surface*)ic -> i) -> w;
916 dest -> y = c -> grid_offset_y + ( displayrow * ( c -> text_height_tab + c -> icon_offset_y ) );
917 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
918 SDL_FreeSurface ( rtext );
922 } // visible or scrolled?
924 if ( row >= ui_rows_scrolled_down ) {
928 // are we done displaying rows?
929 if ( displayrow >= icon_visible_rows ) {
933 appiter = appiter -> next;
940 appiter = g_categories [ ui_category ] -> refs;
944 // until we run out of apps, or run out of space
945 while ( appiter != NULL ) {
947 for ( col = 0; col < c -> col_max && appiter != NULL; col++ ) {
949 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
950 if ( row >= ui_rows_scrolled_down ) {
952 // selected? show hilights
953 if ( appiter == ui_selected ) {
954 SDL_Surface *s = g_imagecache [ IMG_SELECTED_ALPHAMASK ].i;
956 //dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + ( ( icon_max_width - s -> w ) / 2 );
957 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> icon_offset_x + c -> sel_icon_offset_x;
958 //dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + ( ( icon_max_height - s -> h ) / 2 );
959 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> icon_offset_y + c -> sel_icon_offset_y;
960 SDL_BlitSurface ( s, NULL /* all */, sdl_realscreen, dest );
963 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_clip_x;
964 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> text_hilite_offset_y;
965 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
970 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
971 SDL_Surface *iconsurface;
973 // if icon not in cache, and its a pnd-file source, perhaps try to load it right now..
976 ( ! ( appiter -> ref -> object_flags & PND_DISCO_GENERATED ) )
979 // try to load any icons that..
980 // - are not yet loaded
981 // - did not fail a previous load attempt
982 // this way user can upfront load all icons, or defer all icons, or even defer all icons
983 // and still try to load visible ones 'just before needed'; so not at mmenu load time, but
984 // as needed (only the ones needed.)
986 if ( ( appiter -> ref -> pnd_icon_pos ) ||
987 ( appiter -> ref -> icon && appiter -> ref -> object_flags & PND_DISCO_LIBPND_DD )
992 if ( ! cache_icon ( appiter -> ref, ui_display_context.icon_max_width, ui_display_context.icon_max_width ) ) {
997 appiter -> ref -> pnd_icon_pos = 0;
998 if ( appiter -> ref -> icon ) {
999 free ( appiter -> ref -> icon );
1000 appiter -> ref -> icon = NULL;
1003 // pick up as if nothing happened..
1004 ic = cache_query_icon ( appiter -> ref -> unique_id );
1008 } // load icon during rendering?
1011 iconsurface = ic -> i;
1013 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
1015 // no icon override; was this a pnd-file (show the unknown icon then), or was this generated from
1016 // filesystem (file or directory icon)
1017 if ( appiter -> ref -> object_flags & PND_DISCO_GENERATED ) {
1018 if ( appiter -> ref -> object_type == pnd_object_type_directory ) {
1020 // is this a subcat, a .., or a filesystem folder?
1021 //iconsurface = g_imagecache [ IMG_FOLDER ].i;
1022 if ( g_categories [ ui_category ] -> fspath ) {
1023 iconsurface = g_imagecache [ IMG_FOLDER ].i;
1024 } else if ( strcmp ( appiter -> ref -> title_en, ".." ) == 0 ) {
1025 iconsurface = g_imagecache [ IMG_DOTDOTFOLDER ].i;
1027 iconsurface = g_imagecache [ IMG_SUBCATFOLDER ].i;
1031 iconsurface = g_imagecache [ IMG_EXECBIN ].i;
1034 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
1039 // got an icon I hope?
1040 if ( iconsurface ) {
1041 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
1047 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> icon_offset_x + (( c -> icon_max_width - iconsurface -> w ) / 2);
1048 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> icon_offset_y + (( c -> icon_max_height - iconsurface -> h ) / 2);
1050 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
1053 ui_register_app ( appiter, dest -> x, dest -> y, src.w, src.h );
1060 if ( appiter -> ref -> title_en ) {
1062 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, c -> fontcolor );
1065 src.w = c -> text_width < rtext -> w ? c -> text_width : rtext -> w;
1067 if ( rtext -> w > c -> text_width ) {
1068 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_clip_x;
1070 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_offset_x - ( rtext -> w / 2 );
1072 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> text_offset_y;
1073 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1074 SDL_FreeSurface ( rtext );
1078 } // display now? or scrolled away..
1081 appiter = appiter -> next;
1083 } // for column 1...X
1085 if ( row >= ui_rows_scrolled_down ) {
1091 // are we done displaying rows?
1092 if ( displayrow >= c -> row_max ) {
1101 // no apps to render?
1102 pnd_log ( pndn_rem, "No applications to render?\n" );
1103 } // apps to renser?
1107 // detail panel - show app details or blank-message
1108 if ( render_jobs_b & R_DETAIL && ui_detail_hidden == 0 ) {
1110 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
1111 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
1112 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
1114 unsigned int desty = cell_offset_y;
1116 if ( ui_selected ) {
1118 char buffer [ 256 ];
1121 if ( ui_selected -> ref -> title_en ) {
1123 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, c -> fontcolor );
1126 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
1128 dest -> x = cell_offset_x;
1130 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1131 SDL_FreeSurface ( rtext );
1138 if ( ui_selected -> ref -> main_category ) {
1140 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
1143 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
1146 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
1148 dest -> x = cell_offset_x;
1150 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1151 SDL_FreeSurface ( rtext );
1158 if ( ui_selected -> ref -> clockspeed ) {
1160 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
1163 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
1166 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
1168 dest -> x = cell_offset_x;
1170 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1171 SDL_FreeSurface ( rtext );
1176 // show sub-app# on right side of cpu clock?
1177 //if ( ui_selected -> ref -> subapp_number )
1179 sprintf ( buffer, "(app#%u)", ui_selected -> ref -> subapp_number );
1182 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1183 dest -> x = cell_offset_x + cell_width - rtext -> w;
1184 dest -> y = desty - src.h;
1185 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1186 SDL_FreeSurface ( rtext );
1191 #if 0 // merged into hint-line
1192 if ( ui_selected -> ref -> info_filename ) {
1194 sprintf ( buffer, "Documentation - hit Y" );
1197 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
1200 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
1202 dest -> x = cell_offset_x;
1204 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1205 SDL_FreeSurface ( rtext );
1212 if ( ui_selected -> ovrh ) {
1217 desty += 5; // a touch of spacing can't hurt
1219 for ( i = 1; i < 4; i++ ) {
1220 sprintf ( buffer, "Application-%u.note-%u", ui_selected -> ref -> subapp_number, i );
1221 n = pnd_conf_get_as_char ( ui_selected -> ovrh, buffer );
1225 rtext = TTF_RenderText_Blended ( g_detailtext_font, n, c -> fontcolor );
1228 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
1230 dest -> x = cell_offset_x;
1232 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1233 SDL_FreeSurface ( rtext );
1235 desty += rtext -> h;
1239 } // r_detail -> notes
1242 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
1243 SDL_Surface *previewpic;
1246 previewpic = ic -> i;
1248 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
1252 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
1253 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
1254 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
1255 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
1261 char *empty_message = "Press SELECT for menu";
1265 rtext = TTF_RenderText_Blended ( g_detailtext_font, empty_message, c -> fontcolor );
1269 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
1271 dest -> x = cell_offset_x;
1273 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1274 SDL_FreeSurface ( rtext );
1279 rtext = TTF_RenderText_Blended ( g_detailtext_font, "START or B to run app", c -> fontcolor );
1280 dest -> x = cell_offset_x;
1282 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1283 SDL_FreeSurface ( rtext );
1287 rtext = TTF_RenderText_Blended ( g_detailtext_font, "SPACE for app menu", c -> fontcolor );
1288 dest -> x = cell_offset_x;
1290 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1291 SDL_FreeSurface ( rtext );
1295 rtext = TTF_RenderText_Blended ( g_detailtext_font, "A to toggle details", c -> fontcolor );
1296 dest -> x = cell_offset_x;
1298 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1299 SDL_FreeSurface ( rtext );
1303 } // r_detail && selected?
1311 if ( render_jobs_b & R_BG ) {
1312 static int last_battlevel = 0;
1313 static unsigned char batterylevel = 0;
1314 char buffer [ 100 ];
1316 if ( time ( NULL ) - last_battlevel > 60 ) {
1317 batterylevel = pnd_device_get_battery_gauge_perc();
1318 last_battlevel = time ( NULL );
1321 sprintf ( buffer, "Battery: %u%%", batterylevel );
1324 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1325 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.battery_x", 20 );
1326 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
1327 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1328 SDL_FreeSurface ( rtext );
1333 if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
1335 unsigned int hintx, hinty;
1336 hintx = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
1337 hinty = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
1338 static unsigned int lastwidth = 3000;
1340 if ( ui_selected && ui_selected -> ref -> info_filename ) {
1341 buffer = "Documentation - hit Y";
1343 buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
1347 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1350 if ( ! ( render_jobs_b & R_BG ) ) {
1357 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, &src, sdl_realscreen, dest );
1359 lastwidth = rtext -> w;
1365 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1366 SDL_FreeSurface ( rtext );
1371 if ( render_jobs_b & R_BG &&
1372 pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 )
1376 time_t t = time ( NULL );
1377 struct tm *tm = localtime ( &t );
1378 strftime ( buffer, 50, "%a %H:%M %F", tm );
1381 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1382 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.clock_x", 700 );
1383 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.clock_y", 450 );
1384 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1385 SDL_FreeSurface ( rtext );
1389 // update all the rects and send it all to sdl
1390 // - at this point, we could probably just do 1 rect, of the
1391 // whole screen, and be faster :/
1392 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1396 void ui_process_input ( pnd_dbusnotify_handle dbh, pnd_notify_handle nh ) {
1399 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
1400 //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
1402 while ( ( ! ui_event ) &&
1403 /*block_p ?*/ SDL_WaitEvent ( &event ) /*: SDL_PollEvent ( &event )*/ )
1406 switch ( event.type ) {
1411 // the user-defined SDL events are all for threaded/delayed previews (and icons, which
1412 // generally are not used); if we're in wide mode, we can skip previews
1413 // to avoid slowing things down when they're not shown.
1415 if ( event.user.code == sdl_user_ticker ) {
1417 if ( ui_detail_hidden ) {
1418 break; // skip building previews when not showing them
1421 // timer went off, time to load something
1422 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1424 if ( ! ui_selected ) {
1428 // load the preview pics now!
1429 pnd_disco_t *iter = ui_selected -> ref;
1431 if ( iter -> preview_pic1 ) {
1433 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.threaded_preview", 0 ) ) {
1434 // load in bg thread, make user experience chuggy
1436 g_preview_thread = SDL_CreateThread ( (void*)ui_threaded_defered_preview, iter );
1438 if ( ! g_preview_thread ) {
1439 pnd_log ( pndn_error, "ERROR: Couldn't create preview thread\n" );
1443 // load it now, make user wait
1445 if ( ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
1446 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
1449 pnd_log ( pndn_debug, " Couldn't load preview pic: '%s' -> '%s'\n",
1450 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1455 } // got a preview at all?
1460 } else if ( event.user.code == sdl_user_finishedpreview ) {
1462 // if we just finished the one we happen to be looking at, better redraw now; otherwise, if
1463 // we finished another, no big woop
1464 if ( ui_selected && event.user.data1 == ui_selected -> ref ) {
1468 } else if ( event.user.code == sdl_user_finishedicon ) {
1469 // redraw, so we can show the newly loaded icon
1472 } else if ( event.user.code == sdl_user_checksd ) {
1473 // check if any inotify-type events occured, forcing us to rescan/re-disco the SDs
1475 unsigned char watch_dbus = 0;
1476 unsigned char watch_inotify = 0;
1479 watch_dbus = pnd_dbusnotify_rediscover_p ( dbh );
1483 watch_inotify = pnd_notify_rediscover_p ( nh );
1486 if ( watch_dbus || watch_inotify ) {
1487 pnd_log ( pndn_debug, "dbusnotify detected SD event\n" );
1488 applications_free();
1489 applications_scan();
1496 render_mask |= CHANGED_EVERYTHING;
1500 #if 0 // joystick motion
1501 case SDL_JOYAXISMOTION:
1503 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
1505 if ( event.jaxis.axis == 0 ) {
1507 if ( event.jaxis.value < 0 ) {
1509 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
1510 } else if ( event.jaxis.value > 0 ) {
1511 ui_push_right ( 0 );
1512 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
1514 } else if ( event.jaxis.axis == 1 ) {
1516 if ( event.jaxis.value < 0 ) {
1518 } else if ( event.jaxis.value > 0 ) {
1528 #if 0 // joystick buttons
1529 case SDL_JOYBUTTONDOWN:
1531 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
1533 if ( event.jbutton.button == 0 ) { // B
1535 } else if ( event.jbutton.button == 1 ) { // Y
1537 } else if ( event.jbutton.button == 2 ) { // X
1539 } else if ( event.jbutton.button == 3 ) { // A
1542 } else if ( event.jbutton.button == 4 ) { // Select
1543 ui_mask |= uisb_select;
1544 } else if ( event.jbutton.button == 5 ) { // Start
1545 ui_mask |= uisb_start;
1547 } else if ( event.jbutton.button == 7 ) { // L
1549 } else if ( event.jbutton.button == 8 ) { // R
1558 case SDL_JOYBUTTONUP:
1560 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
1562 if ( event.jbutton.button == 0 ) { // B
1565 } else if ( event.jbutton.button == 1 ) { // Y
1567 } else if ( event.jbutton.button == 2 ) { // X
1569 } else if ( event.jbutton.button == 3 ) { // A
1572 } else if ( event.jbutton.button == 4 ) { // Select
1573 ui_mask &= ~uisb_select;
1574 } else if ( event.jbutton.button == 5 ) { // Start
1575 ui_mask &= ~uisb_start;
1577 } else if ( event.jbutton.button == 7 ) { // L
1580 } else if ( event.jbutton.button == 8 ) { // R
1591 #if 1 // keyboard events
1595 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
1597 // SDLK_LALT -> Start
1598 // page up/down for y/x
1599 // home/end for a and b
1602 if ( event.key.keysym.sym == SDLK_RIGHT ) {
1603 ui_push_right ( 0 );
1605 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
1608 } else if ( event.key.keysym.sym == SDLK_UP ) {
1611 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1614 } else if ( event.key.keysym.sym == SDLK_END ) { // B
1617 } else if ( event.key.keysym.sym == SDLK_SPACE ) { // space
1618 if ( ui_selected ) {
1619 ui_menu_context ( ui_selected );
1621 // TBD: post an error?
1623 render_mask |= CHANGED_EVERYTHING;
1625 } else if ( event.key.keysym.sym == SDLK_TAB || event.key.keysym.sym == SDLK_HOME ) { // tab or A
1626 // if detail panel is togglable, then toggle it
1627 // if not, make sure its ruddy well shown!
1628 if ( ui_is_detail_hideable() ) {
1629 ui_toggle_detail_pane();
1631 ui_detail_hidden = 0;
1634 } else if ( event.key.keysym.sym == SDLK_RSHIFT || event.key.keysym.sym == SDLK_COMMA ) { // left trigger or comma
1637 } else if ( event.key.keysym.sym == SDLK_RCTRL || event.key.keysym.sym == SDLK_PERIOD ) { // right trigger or period
1641 } else if ( event.key.keysym.sym == SDLK_PAGEUP ) { // Y
1643 if ( ui_selected ) {
1644 ui_show_info ( pnd_run_script, ui_selected -> ref );
1647 } else if ( event.key.keysym.sym == SDLK_PAGEDOWN ) { // X
1650 // forget the selection, nolonger applies
1652 ui_set_selected ( ui_selected );
1654 if ( g_categories [ ui_category ] -> fspath ) {
1655 category_fs_restock ( g_categories [ ui_category ] );
1658 render_mask |= CHANGED_EVERYTHING;
1661 } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
1665 } else if ( event.key.keysym.sym == SDLK_LCTRL /*LALT*/ ) { // select button
1666 char *opts [ 20 ] = {
1667 "Toggle view icons<->list",
1668 "Reveal hidden category",
1670 "Configure Minimenu",
1671 "Manage custom app categories",
1672 "Rescan for applications",
1673 "Cache previews to SD now",
1674 "Run a terminal/console",
1675 "Run another GUI (xfce, etc)",
1677 "Select a Minimenu skin",
1680 int sel = ui_modal_single_menu ( opts, 12, "Minimenu", "Enter to select; other to return." );
1682 char buffer [ 100 ];
1684 if ( ui_viewmode == uiv_list ) {
1685 ui_viewmode = uiv_icons;
1687 ui_viewmode = uiv_list;
1689 } else if ( sel == 1 ) {
1692 } else if ( sel == 2 ) {
1693 // store conf on exit, so that last app/cat can be cached.. for ED :)
1694 conf_write ( g_conf, conf_determine_location ( g_conf ) );
1696 sprintf ( buffer, "sudo poweroff" );
1698 } else if ( sel == 3 ) {
1700 unsigned char restart = conf_run_menu ( NULL );
1701 conf_write ( g_conf, conf_determine_location ( g_conf ) );
1702 conf_write ( g_conf, CONF_PREF_TEMPPATH );
1704 emit_and_quit ( MM_RESTART );
1706 } else if ( sel == 4 ) {
1707 // manage custom categories
1708 ui_manage_categories();
1709 } else if ( sel == 5 ) {
1711 pnd_log ( pndn_debug, "Freeing up applications\n" );
1712 applications_free();
1713 pnd_log ( pndn_debug, "Rescanning applications\n" );
1714 applications_scan();
1715 } else if ( sel == 6 ) {
1716 // cache preview to SD now
1717 extern pnd_box_handle g_active_apps;
1718 pnd_box_handle h = g_active_apps;
1720 unsigned int maxwidth, maxheight;
1721 maxwidth = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 );
1722 maxheight = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 );
1724 pnd_disco_t *iter = pnd_box_get_head ( h );
1729 if ( ! cache_preview ( iter, maxwidth, maxheight ) ) {
1730 pnd_log ( pndn_debug, "Force cache: Couldn't load preview pic: '%s' -> '%s'\n",
1731 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1735 iter = pnd_box_get_next ( iter );
1738 } else if ( sel == 7 ) {
1741 argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
1745 ui_forkexec ( argv );
1748 } else if ( sel == 8 ) {
1749 char buffer [ PATH_MAX ];
1750 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/pandora/scripts/op_switchgui.sh" );
1751 emit_and_quit ( buffer );
1752 } else if ( sel == 9 ) {
1753 emit_and_quit ( MM_QUIT );
1754 } else if ( sel == 10 ) {
1756 if ( ui_pick_skin() ) {
1757 emit_and_quit ( MM_RESTART );
1759 } else if ( sel == 11 ) {
1761 char buffer [ PATH_MAX ];
1762 sprintf ( buffer, "%s/about.txt", g_skinpath );
1763 ui_aboutscreen ( buffer );
1767 render_mask |= CHANGED_EVERYTHING;
1770 // unknown SDLK_ keycode?
1772 // many SDLK_keycodes map to ASCII ("a" is ascii(a)), so try to jump to a filename of that name, in this category?
1773 // and if already there, try to jump to next, maybe?
1774 // future: look for sequence typing? ie: user types 'm' then 'a', look for 'ma*' instead of 'm' then 'a' matching
1775 if ( isalpha ( event.key.keysym.sym ) && g_categories [ ui_category ] -> refcount > 0 ) {
1776 mm_appref_t *app = g_categories [ ui_category ] -> refs;
1778 //fprintf ( stderr, "sel %s next %s\n", ui_selected -> ref -> title_en, ui_selected -> next -> ref -> title_en );
1780 // are we already matching the same char? and next item is also same char?
1781 if ( app && ui_selected && ui_selected -> next &&
1782 ui_selected -> ref -> title_en && ui_selected -> next -> ref -> title_en &&
1783 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( ui_selected -> next -> ref -> title_en [ 0 ] ) &&
1784 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym )
1787 // just skip down one
1788 app = ui_selected -> next;
1791 // walk the category, looking for a first-char match
1793 if ( app -> ref -> title_en && toupper ( app -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym ) ) {
1799 } // same start letter, or new run?
1801 // found something, or no?
1803 // looks like we found a potential match; try switching it to visible selection
1805 ui_set_selected ( ui_selected );
1810 } // SDLK_alphanumeric?
1816 if ( event.key.keysym.sym == SDLK_ESCAPE ) {
1817 emit_and_quit ( MM_QUIT );
1824 #if 1 // mouse / touchscreen
1826 case SDL_MOUSEBUTTONDOWN:
1827 if ( event.button.button == SDL_BUTTON_LEFT ) {
1828 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
1834 case SDL_MOUSEBUTTONUP:
1835 if ( event.button.button == SDL_BUTTON_LEFT ) {
1836 ui_touch_act ( event.button.x, event.button.y );
1849 } // switch event type
1856 void ui_push_left ( unsigned char forcecoil ) {
1858 if ( ui_viewmode == uiv_list ) {
1859 ui_context_t *c = &ui_display_context;
1861 int imax = ( c -> cell_height * c -> row_max ) / ( c -> text_height_tab + c -> icon_offset_y ); // visible rows
1862 for ( i = 0; i < imax; i++ ) {
1868 if ( ! ui_selected ) {
1869 ui_push_right ( 0 );
1873 // what column we in?
1874 unsigned int col = ui_determine_screen_col ( ui_selected );
1876 // are we already at first item?
1877 if ( forcecoil == 0 &&
1878 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1881 unsigned int i = ui_display_context.col_max - 1;
1882 while ( i && ui_selected -> next ) {
1883 ui_push_right ( 0 );
1887 } else if ( g_categories [ ui_category ] -> refs == ui_selected ) {
1888 // can't go any more left, we're at the head
1891 // figure out the previous item; yay for singly linked list :/
1892 mm_appref_t *i = g_categories [ ui_category ] -> refs;
1894 if ( i -> next == ui_selected ) {
1902 ui_set_selected ( ui_selected );
1907 void ui_push_right ( unsigned char forcecoil ) {
1909 if ( ui_viewmode == uiv_list ) {
1910 ui_context_t *c = &ui_display_context;
1912 int imax = ( c -> cell_height * c -> row_max ) / ( c -> text_height_tab + c -> icon_offset_y ); // visible rows
1913 for ( i = 0; i < imax; i++ ) {
1919 if ( ui_selected ) {
1921 // what column we in?
1922 unsigned int col = ui_determine_screen_col ( ui_selected );
1925 if ( forcecoil == 0 &&
1926 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1927 // and selected is far-right, or last icon in category (might not be far right)
1928 ( ( col == ui_display_context.col_max - 1 ) ||
1929 ( ui_selected -> next == NULL ) )
1933 //unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1934 while ( col /*i*/ ) {
1940 // just go to the next
1942 if ( ui_selected -> next ) {
1943 ui_selected = ui_selected -> next;
1949 ui_selected = g_categories [ ui_category ] -> refs;
1952 ui_set_selected ( ui_selected );
1957 void ui_push_up ( void ) {
1959 unsigned char col_max = ui_display_context.col_max;
1961 // not selected? well, no where to go..
1962 if ( ! ui_selected ) {
1966 if ( ui_viewmode == uiv_list ) {
1968 if ( g_categories [ ui_category ] -> refs == ui_selected ) {
1969 // can't go any more up, we're at the head
1972 // figure out the previous item; yay for singly linked list :/
1973 mm_appref_t *i = g_categories [ ui_category ] -> refs;
1975 if ( i -> next == ui_selected ) {
1984 // for list view.. we're done
1985 ui_set_selected ( ui_selected );
1990 unsigned int row = ui_determine_row ( ui_selected );
1993 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 0 ) == 0 )
1995 // wrap around instead
1997 unsigned int col = ui_determine_screen_col ( ui_selected );
2000 ui_selected = g_categories [ ui_category ] -> refs;
2001 while ( ui_selected -> next ) {
2002 ui_selected = ui_selected -> next;
2005 // try to move to same column
2006 unsigned int newcol = ui_determine_screen_col ( ui_selected );
2007 if ( newcol > col ) {
2015 // scroll down to show it
2016 int r = ui_determine_row ( ui_selected ) - 1;
2017 if ( r - ui_display_context.row_max > 0 ) {
2018 ui_rows_scrolled_down = (unsigned int) r;
2022 // stop at top/bottom
2034 void ui_push_down ( void ) {
2036 if ( ui_viewmode == uiv_list ) {
2038 if ( ui_selected ) {
2040 if ( ui_selected -> next ) {
2041 ui_selected = ui_selected -> next;
2045 ui_selected = g_categories [ ui_category ] -> refs; // frist!
2048 // list view? we're done.
2049 ui_set_selected ( ui_selected );
2053 unsigned char col_max = ui_display_context.col_max;
2055 if ( ui_selected ) {
2058 unsigned int row = ui_determine_row ( ui_selected );
2061 unsigned int icon_rows = g_categories [ ui_category ] -> refcount / col_max;
2062 if ( g_categories [ ui_category ] -> refcount % col_max > 0 ) {
2067 if ( row == ( icon_rows - 1 ) &&
2068 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 0 ) == 0 )
2071 unsigned char col = ui_determine_screen_col ( ui_selected );
2073 ui_selected = g_categories [ ui_category ] -> refs;
2076 ui_selected = ui_selected -> next;
2080 ui_rows_scrolled_down = 0;
2082 render_mask |= CHANGED_EVERYTHING;
2087 ui_push_right ( 1 );
2094 ui_push_right ( 0 );
2100 // 'backup' is currently 'X', for going back up in a folder/subcat without having to hit exec on the '..' entry
2101 void ui_push_backup ( void ) {
2103 // a subcat-as-dir, or a dir browser?
2104 if ( g_categories [ ui_category] -> fspath ) {
2105 // dir browser, just climb our way back up
2110 // lop off last word; if the thing ends with /, lop that one, then the next word.
2111 while ( ( c = strrchr ( g_categories [ ui_category] -> fspath, '/' ) ) ) {
2112 *c = '\0'; // lop off the last hunk
2113 if ( *(c+1) != '\0' ) {
2119 if ( g_categories [ ui_category] -> fspath [ 0 ] == '\0' ) {
2120 free ( g_categories [ ui_category] -> fspath );
2121 g_categories [ ui_category] -> fspath = strdup ( "/" );
2125 // a pnd subcat .. are we in one, or at the 'top'?
2126 char *pcatname = g_categories [ ui_category ] -> parent_catname;
2129 return; // we're at the 'top' already
2132 // set to first cat!
2135 // republish cats .. shoudl just be the one
2136 category_publish ( CFNORMAL, NULL );
2139 ui_category = category_index ( pcatname );
2141 // ensure tab visible?
2142 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2143 if ( ui_category > ui_catshift + ( ui_display_context.screen_width / tab_width ) - 1 ) {
2144 ui_catshift = ui_category - ( ui_display_context.screen_width / tab_width ) + 1;
2154 void ui_push_exec ( void ) {
2156 if ( ! ui_selected ) {
2160 // cache the category/app so we can come back to it another time
2161 if ( ui_selected ) {
2162 pnd_conf_set_char ( g_conf, "minimenu.last_known_app_uid", ui_selected -> ref -> unique_id );
2164 if ( g_categories [ 0 ] ) {
2165 pnd_conf_set_char ( g_conf, "minimenu.last_known_catname", g_categories [ ui_category ] -> catname );
2167 // and also the parent cat..
2168 if ( g_categories [ ui_category ] -> parent_catname ) {
2169 pnd_conf_set_char ( g_conf, "minimenu.last_known_parentcatname", g_categories [ ui_category ] -> parent_catname );
2171 char *kv = pnd_box_find_by_key ( g_conf, "minimenu.last_known_parentcatname" );
2173 pnd_box_delete_node ( g_conf, kv );
2179 // cache last known cat/app to /tmp, so we can use it again later
2180 conf_write ( g_conf, CONF_PREF_TEMPPATH );
2182 // was this icon generated from filesystem, or from pnd-file?
2183 if ( ui_selected -> ref -> object_flags & PND_DISCO_GENERATED ) {
2185 if ( ! ui_selected -> ref -> title_en ) {
2186 return; // no filename
2189 if ( ui_selected -> ref -> object_type == pnd_object_type_directory ) {
2191 // check if this guy is a dir-browser tab, or is a directory on a pnd tab
2192 if ( ! g_categories [ ui_category] -> fspath ) {
2193 // pnd subcat as dir
2195 // are we already in a subcat? if so, go back to parent; there is no grandparenting or deeper
2196 if ( g_categories [ ui_category ] -> parent_catname ) {
2201 // delve into subcat
2203 // set to first cat!
2207 // republish cats .. shoudl just be the one
2208 category_publish ( CFBYNAME, ui_selected -> ref -> object_path );
2212 // forget the selection, nolonger applies
2214 ui_set_selected ( ui_selected );
2216 render_mask |= CHANGED_EVERYTHING;
2220 // delve up/down the dir tree
2221 if ( strcmp ( ui_selected -> ref -> title_en, ".." ) == 0 ) {
2226 char *temp = malloc ( strlen ( g_categories [ ui_category] -> fspath ) + strlen ( ui_selected -> ref -> title_en ) + 1 + 1 );
2227 sprintf ( temp, "%s/%s", g_categories [ ui_category] -> fspath, ui_selected -> ref -> title_en );
2228 free ( g_categories [ ui_category] -> fspath );
2229 g_categories [ ui_category] -> fspath = temp;
2232 pnd_log ( pndn_debug, "Cat %s is now in path %s\n", g_categories [ ui_category ] -> catname, g_categories [ ui_category ]-> fspath );
2234 // forget the selection, nolonger applies
2236 ui_set_selected ( ui_selected );
2238 category_fs_restock ( g_categories [ ui_category ] );
2240 render_mask |= CHANGED_SELECTION;
2242 } // directory browser or pnd subcat?
2245 // just run it arbitrarily?
2247 // if this a pnd-file, or just some executable?
2248 if ( strcasestr ( ui_selected -> ref -> object_filename, PND_PACKAGE_FILEEXT ) ) {
2249 // looks like a pnd, now what do we do..
2250 pnd_box_handle h = pnd_disco_file ( ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
2253 pnd_disco_t *d = pnd_box_get_head ( h );
2254 pnd_apps_exec_disco ( pnd_run_script, d, PND_EXEC_OPTION_NORUN, NULL );
2255 char buffer [ PATH_MAX ];
2256 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
2257 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
2258 emit_and_quit ( buffer );
2260 emit_and_run ( buffer );
2267 // is it even executable? if we don't have handlers for non-executables yet (Jan 2011 we don't),
2268 // then don't even try to run things not-flagged as executable.. but wait most people are on
2269 // FAT filesystems, what a drag, we can't tell at the fs level.
2270 // ... but we can still invoke 'file' and grep out the good bits, at least.
2272 // open a stream reading 'file /path/to/file' and check output for 'executable'
2273 // -- not checking for "ARM" so it can pick up x86 (or whatever native) executables in build environment
2274 unsigned char is_executable = 0;
2278 char popenbuf [ FILENAME_MAX ];
2279 snprintf ( popenbuf, FILENAME_MAX, "%s %s/%s", MIMETYPE_EXE, g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
2282 if ( ! ( marceau = popen ( popenbuf, "r" ) ) ) {
2283 return; // error, we need some useful error handling and dialog boxes here
2286 if ( fgets ( popenbuf, FILENAME_MAX, marceau ) ) {
2287 //printf ( "File test returns: %s\n", popenbuf );
2288 if ( strstr ( popenbuf, "executable" ) != NULL ) {
2297 if ( ! is_executable ) {
2298 fprintf ( stderr, "ERROR: File to invoke is not executable, skipping. (%s)\n", ui_selected -> ref -> title_en );
2299 return; // need some error handling here
2302 #if 0 // eat up any pending SDL events and toss 'em?
2306 while ( SDL_PeepEvents ( &e, 1, SDL_GETEVENT, SDL_ALLEVENTS ) > 0 ) {
2316 // get CWD so we can restore it on return
2317 char cwd [ PATH_MAX ];
2318 getcwd ( cwd, PATH_MAX );
2320 // full path to executable so we don't rely on implicit "./"
2321 char execbuf [ FILENAME_MAX ];
2322 snprintf ( execbuf, FILENAME_MAX, "%s/%s", g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
2325 chdir ( g_categories [ ui_category ] -> fspath );
2326 exec_raw_binary ( execbuf /*ui_selected -> ref -> title_en*/ );
2329 // DEPRECATED / NOT TESTED
2330 // get mmwrapper to run it
2331 char buffer [ PATH_MAX ];
2332 sprintf ( buffer, "%s %s/%s\n", MM_RUN, g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
2333 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
2334 emit_and_quit ( buffer );
2336 emit_and_run ( buffer );
2345 // set app-run speed
2346 int use_run_speed = pnd_conf_get_as_int_d ( g_conf, "minimenu.use_run_speed", 0 );
2347 if ( use_run_speed > 0 ) {
2348 int mm_speed = pnd_conf_get_as_int_d ( g_conf, "minimenu.run_speed", -1 );
2349 if ( mm_speed > -1 ) {
2350 char buffer [ 512 ];
2351 snprintf ( buffer, 500, "sudo /usr/pandora/scripts/op_cpuspeed.sh %d", mm_speed );
2354 } // do speed change?
2356 // request app to run and quit mmenu
2357 pnd_apps_exec_disco ( pnd_run_script, ui_selected -> ref, PND_EXEC_OPTION_NORUN, NULL );
2358 char buffer [ PATH_MAX ];
2359 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
2360 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
2361 emit_and_quit ( buffer );
2363 emit_and_run ( buffer );
2370 void ui_push_ltrigger ( void ) {
2371 unsigned char oldcat = ui_category;
2372 unsigned int screen_width = ui_display_context.screen_width;
2373 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2375 if ( g_categorycount == 0 ) {
2379 if ( g_icon_thread_busy ) {
2380 ui_stop_defered_icon_thread();
2383 if ( ui_category > 0 ) {
2385 category_fs_restock ( g_categories [ ui_category ] );
2387 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
2388 ui_category = g_categorycount - 1;
2390 if ( ui_category >= ( screen_width / tab_width ) ) {
2391 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
2393 category_fs_restock ( g_categories [ ui_category ] );
2397 if ( oldcat != ui_category ) {
2399 ui_set_selected ( ui_selected );
2402 // make tab visible?
2403 if ( ui_catshift > 0 && ui_category == ui_catshift - 1 ) {
2408 ui_rows_scrolled_down = 0;
2410 render_mask |= CHANGED_CATEGORY;
2411 ui_start_defered_icon_thread();
2416 void ui_push_rtrigger ( void ) {
2417 unsigned char oldcat = ui_category;
2419 if ( g_categorycount == 0 ) {
2423 if ( g_icon_thread_busy ) {
2424 ui_stop_defered_icon_thread();
2427 unsigned int screen_width = ui_display_context.screen_width;
2428 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2430 if ( ui_category < ( g_categorycount - 1 ) ) {
2432 category_fs_restock ( g_categories [ ui_category ] );
2434 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
2437 category_fs_restock ( g_categories [ ui_category ] );
2441 if ( oldcat != ui_category ) {
2443 ui_set_selected ( ui_selected );
2446 // make tab visible?
2447 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2452 ui_rows_scrolled_down = 0;
2454 render_mask |= CHANGED_CATEGORY;
2455 ui_start_defered_icon_thread();
2460 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
2461 double scale = 1000000.0;
2462 double scalex = 1000000.0;
2463 double scaley = 1000000.0;
2464 SDL_Surface *scaled;
2466 scalex = (double)maxwidth / (double)s -> w;
2468 if ( maxheight == -1 ) {
2471 scaley = (double)maxheight / (double)s -> h;
2473 if ( scaley < scalex ) {
2481 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
2482 SDL_FreeSurface ( s );
2488 void ui_loadscreen ( void ) {
2493 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2497 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", ui_display_context.fontcolor );
2500 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
2501 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2502 SDL_FreeSurface ( rtext );
2507 void ui_discoverscreen ( unsigned char clearscreen ) {
2512 if ( clearscreen ) {
2513 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2515 // render background
2516 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2519 dest.w = sdl_realscreen -> w;
2520 dest.h = sdl_realscreen -> h;
2521 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
2522 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2529 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", ui_display_context.fontcolor );
2530 if ( clearscreen ) {
2537 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
2538 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2539 SDL_FreeSurface ( rtext );
2542 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
2543 dest.x = rtext -> w + 30;
2545 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
2546 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2552 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
2554 SDL_Rect rects [ 4 ];
2555 SDL_Rect *dest = rects;
2557 bzero ( dest, sizeof(SDL_Rect)* 4 );
2559 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
2560 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
2561 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
2562 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
2564 static unsigned int stepx = 0;
2567 if ( clearscreen ) {
2568 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2570 // render background
2571 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2574 dest -> w = sdl_realscreen -> w;
2575 dest -> h = sdl_realscreen -> h;
2576 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
2582 // render background
2583 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2586 src.w = sdl_realscreen -> w;
2590 dest -> w = sdl_realscreen -> w;
2591 dest -> h = sdl_realscreen -> h;
2592 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
2600 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
2601 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
2604 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2605 SDL_FreeSurface ( rtext );
2609 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
2610 dest -> x = rtext -> w + 30 + stepx;
2612 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
2618 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
2621 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2622 SDL_FreeSurface ( rtext );
2629 if ( stepx > 350 ) {
2633 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
2638 int ui_selected_index ( void ) {
2640 if ( ! ui_selected ) {
2641 return ( -1 ); // no index
2644 mm_appref_t *r = g_categories [ ui_category ] -> refs;
2647 if ( r == ui_selected ) {
2657 static mm_appref_t *timer_ref = NULL;
2658 void ui_set_selected ( mm_appref_t *r ) {
2660 render_mask |= CHANGED_SELECTION;
2662 // preview pic stuff
2665 if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
2666 return; // no desire to defer anything
2671 SDL_SetTimer ( 0, NULL );
2676 SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
2682 unsigned int ui_callback_f ( unsigned int t ) {
2684 if ( ui_selected != timer_ref ) {
2685 return ( 0 ); // user has moved it, who cares
2689 bzero ( &e, sizeof(SDL_Event) );
2690 e.type = SDL_USEREVENT;
2691 e.user.code = sdl_user_ticker;
2692 SDL_PushEvent ( &e );
2697 int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
2698 SDL_Rect rects [ 40 ];
2699 SDL_Rect *dest = rects;
2702 unsigned char max_visible = pnd_conf_get_as_int_d ( g_conf, "detailtext.max_visible" , 11 );
2703 unsigned char first_visible = 0;
2705 bzero ( rects, sizeof(SDL_Rect) * 40 );
2707 unsigned int sel = 0;
2709 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 };
2717 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2718 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2719 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
2720 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
2721 SDL_FillRect( sdl_realscreen, dest, 0 );
2723 // show dialog background
2724 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
2727 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> w;
2728 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> h;
2729 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2730 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2731 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2732 // repeat for darken?
2733 //SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2734 //SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2735 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2739 // show dialog frame
2740 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
2741 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2742 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2743 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
2744 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2750 rtext = TTF_RenderText_Blended ( g_tab_font, title, ui_display_context.fontcolor );
2751 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2752 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
2753 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2754 SDL_FreeSurface ( rtext );
2760 rtext = TTF_RenderText_Blended ( g_tab_font, footer, ui_display_context.fontcolor );
2761 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2762 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
2763 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
2765 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2766 SDL_FreeSurface ( rtext );
2771 for ( i = first_visible; i < first_visible + max_visible && i < argc; i++ ) {
2775 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
2777 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], ui_display_context.fontcolor );
2779 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2780 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 - first_visible ) );
2781 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2782 SDL_FreeSurface ( rtext );
2787 // update all the rects and send it all to sdl
2788 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
2792 while ( SDL_WaitEvent ( &event ) ) {
2794 switch ( event.type ) {
2799 if ( event.key.keysym.sym == SDLK_UP ) {
2803 if ( sel < first_visible ) {
2808 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
2810 if ( sel < argc - 1 ) {
2813 // ensure visibility
2814 if ( sel >= first_visible + max_visible ) {
2820 } else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_END ) { // return, or "B"
2824 } else if ( event.key.keysym.sym == SDLK_q ) {
2829 return ( -1 ); // nada
2844 unsigned char ui_determine_row ( mm_appref_t *a ) {
2845 unsigned int row = 0;
2847 mm_appref_t *i = g_categories [ ui_category ] -> refs;
2852 row /= ui_display_context.col_max;
2857 unsigned char ui_determine_screen_row ( mm_appref_t *a ) {
2858 return ( ui_determine_row ( a ) % ui_display_context.row_max );
2861 unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
2862 unsigned int col = 0;
2864 mm_appref_t *i = g_categories [ ui_category ] -> refs;
2869 col %= ui_display_context.col_max;
2874 unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ) {
2875 char *viewer, *searchpath;
2876 pnd_conf_handle desktoph;
2879 searchpath = pnd_conf_query_searchpath();
2881 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
2887 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
2890 return ( 0 ); // no way to view the file
2894 if ( ! p -> unique_id ) {
2898 if ( ! p -> info_filename ) {
2902 if ( ! p -> info_name ) {
2913 if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
2914 snprintf ( pargs, 1001, "%s %s",
2915 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
2920 char pndfile [ 1024 ];
2921 if ( p -> object_type == pnd_object_type_directory ) {
2922 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
2923 strncpy ( pndfile, p -> object_path, 1000 );
2924 } else if ( p -> object_type == pnd_object_type_pnd ) {
2925 // pnd_run.sh wants the full path and filename for the .pnd file
2926 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
2929 if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
2930 p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
2935 pnd_log ( pndn_debug, "Info Exec=%s\n", pnd_apps_exec_runline() );
2939 if ( ( x = fork() ) < 0 ) {
2940 pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
2945 execl ( "/bin/sh", "/bin/sh", "-c", pnd_apps_exec_runline(), (char*)NULL );
2946 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", pnd_apps_exec_runline() );
2958 #define MAXTOUCH 100
2959 ui_touch_t ui_touchrects [ MAXTOUCH ];
2960 unsigned char ui_touchrect_count = 0;
2962 void ui_register_reset ( void ) {
2963 bzero ( ui_touchrects, sizeof(ui_touch_t)*MAXTOUCH );
2964 ui_touchrect_count = 0;
2968 void ui_register_tab ( unsigned char catnum, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2970 if ( ui_touchrect_count == MAXTOUCH ) {
2974 ui_touchrects [ ui_touchrect_count ].r.x = x;
2975 ui_touchrects [ ui_touchrect_count ].r.y = y;
2976 ui_touchrects [ ui_touchrect_count ].r.w = w;
2977 ui_touchrects [ ui_touchrect_count ].r.h = h;
2978 ui_touchrects [ ui_touchrect_count ].catnum = catnum;
2979 ui_touchrect_count++;
2984 void ui_register_app ( mm_appref_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2986 if ( ui_touchrect_count == MAXTOUCH ) {
2990 ui_touchrects [ ui_touchrect_count ].r.x = x;
2991 ui_touchrects [ ui_touchrect_count ].r.y = y;
2992 ui_touchrects [ ui_touchrect_count ].r.w = w;
2993 ui_touchrects [ ui_touchrect_count ].r.h = h;
2994 ui_touchrects [ ui_touchrect_count ].ref = app;
2995 ui_touchrect_count++;
3000 void ui_touch_act ( unsigned int x, unsigned int y ) {
3005 for ( i = 0; i < ui_touchrect_count; i++ ) {
3006 t = &(ui_touchrects [ i ]);
3008 if ( x >= t -> r.x &&
3009 x <= t -> r.x + t -> r.w &&
3011 y <= t -> r.y + t -> r.h
3016 ui_selected = t -> ref;
3019 if ( ui_category != t -> catnum ) {
3022 ui_category = t -> catnum;
3023 render_mask |= CHANGED_CATEGORY;
3025 category_fs_restock ( g_categories [ ui_category ] );
3026 ui_start_defered_icon_thread();
3037 unsigned char ui_forkexec ( char *argv[] ) {
3038 char *fooby = argv[0];
3041 if ( ( x = fork() ) < 0 ) {
3042 pnd_log ( pndn_error, "ERROR: Couldn't fork() for '%s'\n", fooby );
3046 if ( x == 0 ) { // child
3047 execv ( fooby, argv );
3048 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", fooby );
3056 unsigned char ui_threaded_timer_create ( void ) {
3058 g_timer_thread = SDL_CreateThread ( (void*)ui_threaded_timer, NULL );
3060 if ( ! g_timer_thread ) {
3061 pnd_log ( pndn_error, "ERROR: Couldn't create timer thread\n" );
3068 int ui_threaded_timer ( pnd_disco_t *p ) {
3070 // this timer's job is to ..
3071 // - do nothing for quite awhile
3072 // - on wake, post event to SDL event queue, so that main thread will check if SD insert/eject occurred
3075 unsigned int delay_s = 2; // seconds
3080 //sleep ( delay_s );
3081 SDL_Delay ( delay_s * 1000 );
3083 // .. trigger SD check
3085 bzero ( &e, sizeof(SDL_Event) );
3086 e.type = SDL_USEREVENT;
3087 e.user.code = sdl_user_checksd;
3088 SDL_PushEvent ( &e );
3095 unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
3097 if ( ! cache_preview ( p, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
3098 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
3101 pnd_log ( pndn_debug, "THREAD: Couldn't load preview pic: '%s' -> '%s'\n",
3102 IFNULL(p->title_en,"No Name"), p -> preview_pic1 );
3105 // trigger that we completed
3107 bzero ( &e, sizeof(SDL_Event) );
3108 e.type = SDL_USEREVENT;
3109 e.user.code = sdl_user_finishedpreview;
3111 SDL_PushEvent ( &e );
3116 void ui_post_scan ( void ) {
3120 ui_rows_scrolled_down = 0;
3121 // set back to first tab, to be safe
3125 // do we have a preferred category to jump to? or a last known one?
3126 char *dc = pnd_conf_get_as_char ( g_conf, "categories.default_cat" );
3127 char *lastcat = pnd_conf_get_as_char ( g_conf, "minimenu.last_known_catname" );
3129 ( pnd_conf_get_as_int_d ( g_conf, "minimenu.start_selected", 0 ) && lastcat ) )
3131 char *catpick = NULL;
3133 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.start_selected", 0 ) && lastcat ) {
3136 // if this is a subcat, we have some doctoring to do :/ the hackishness is really
3137 // starting to show..
3138 if ( pnd_conf_get_as_char ( g_conf, "minimenu.last_known_parentcatname" ) ) {
3139 // in subcat view, we only have one cat
3142 // the cat name to search for is Child*Parent
3144 sprintf ( key, "%s*%s",
3145 pnd_conf_get_as_char ( g_conf, "minimenu.last_known_catname" )
3146 , pnd_conf_get_as_char ( g_conf, "minimenu.last_known_parentcatname" ) );
3147 category_publish ( CFBYNAME, key );
3148 // since we forced it by hand, no need to do a cat-scan below
3156 // attempt to find default cat; if we do find it, select it; otherwise
3157 // default behaviour will pick first cat (ie: usually All)
3161 for ( i = 0; i < g_categorycount; i++ ) {
3162 if ( strcasecmp ( g_categories [ i ] -> catname, catpick ) == 0 ) {
3164 // ensure visibility
3165 unsigned int screen_width = ui_display_context.screen_width;
3166 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
3167 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
3168 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
3174 if ( i == g_categorycount ) {
3175 pnd_log ( pndn_warning, " User defined default category or last known cat '%s' but not found, so using default behaviour\n", catpick );
3182 // if we're sent right to a dirbrowser tab, restock it now (normally we restock on entry)
3183 if ( g_categories [ ui_category ] && g_categories [ ui_category ] -> fspath ) {
3184 printf ( "Restock on start: '%s'\n", g_categories [ ui_category ] -> fspath );
3185 category_fs_restock ( g_categories [ ui_category ] );
3189 render_mask |= CHANGED_EVERYTHING;
3191 // if deferred icon load, kick off the thread now
3192 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 1 ) {
3193 ui_start_defered_icon_thread();
3194 } // deferred icon load
3199 unsigned char ui_threaded_defered_icon ( void *p ) {
3200 extern pnd_box_handle g_active_apps;
3202 unsigned char maxwidth, maxheight;
3203 maxwidth = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 );
3204 maxheight = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_height", 50 );
3208 g_icon_thread_busy = 1;
3210 // work at it in order within current category
3212 mm_appref_t *refiter = g_categories [ ui_category ] ? g_categories [ ui_category ] -> refs : NULL;
3213 while ( refiter && ! g_icon_thread_stop ) {
3214 iter = refiter -> ref;
3216 // has an icon that is not already cached?
3217 if ( ( iter -> pnd_icon_pos ) ||
3218 ( iter -> icon && iter -> object_flags & PND_DISCO_LIBPND_DD )
3223 if ( ! cache_icon ( iter, maxwidth, maxheight ) ) {
3224 //pnd_log ( pndn_warning, " Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
3228 // trigger that we completed
3230 bzero ( &e, sizeof(SDL_Event) );
3231 e.type = SDL_USEREVENT;
3232 e.user.code = sdl_user_finishedicon;
3233 SDL_PushEvent ( &e );
3235 //pnd_log ( pndn_warning, " Finished deferred load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
3236 //usleep ( pnd_conf_get_as_int_d ( g_conf, "minimenu.defer_icon_us", 50000 ) );
3241 iter -> pnd_icon_pos = 0;
3242 if ( iter -> icon ) {
3243 free ( iter -> icon );
3244 iter -> icon = NULL;
3247 // let user do something..
3252 refiter = refiter -> next;
3256 g_icon_thread_busy = 0;
3261 void ui_show_hourglass ( unsigned char updaterect ) {
3264 SDL_Surface *s = g_imagecache [ IMG_HOURGLASS ].i;
3266 dest.x = ( 800 - s -> w ) / 2;
3267 dest.y = ( 480 - s -> h ) / 2;
3269 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, &dest );
3272 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
3278 unsigned char ui_pick_skin ( void ) {
3280 char *skins [ MAXSKINS ];
3283 char *searchpath = pnd_conf_get_as_char ( g_conf, "minimenu.skin_searchpath" );
3284 char tempname [ 100 ];
3288 skins [ iter++ ] = "No skin change";
3292 DIR *d = opendir ( buffer );
3297 while ( ( dd = readdir ( d ) ) ) {
3299 if ( dd -> d_name [ 0 ] == '.' ) {
3301 } else if ( ( dd -> d_type == DT_DIR || dd -> d_type == DT_UNKNOWN ) &&
3304 snprintf ( tempname, 100, "Skin: %s", dd -> d_name );
3305 skins [ iter++ ] = strdup ( tempname );
3316 int sel = ui_modal_single_menu ( skins, iter, "Skins", "Enter to select; other to return." );
3318 // did they pick one?
3322 char *s = strdup ( pnd_conf_get_as_char ( g_conf, "minimenu.skin_selected" ) );
3323 s = pnd_expand_tilde ( s );
3325 f = fopen ( s, "w" );
3330 fprintf ( f, "%s\n", skins [ sel ] + 6 );
3340 void ui_aboutscreen ( char *textpath ) {
3347 #define ROWS SCRH / ( PIXELH + MARGINH )
3348 #define COLS SCRW / ( PIXELW + MARGINW )
3350 unsigned char pixelboard [ ROWS * COLS ]; // pixel heat
3351 bzero ( pixelboard, ROWS * COLS );
3356 SDL_Color rtextc = { 200, 200, 200, 100 };
3359 char *textloop [ 500 ];
3360 unsigned int textmax = 0;
3361 bzero ( textloop, 500 * sizeof(char*) );
3364 char cbuffer [ 50000 ];
3365 bzero ( cbuffer, 50000 );
3366 unsigned int crevealed = 0;
3368 FILE *f = fopen ( textpath, "r" );
3371 pnd_log ( pndn_error, "ERROR: Couldn't open about text: %s\n", textpath );
3375 char textbuf [ 100 ];
3376 while ( fgets ( textbuf, 100, f ) ) {
3378 // add to full buffer
3379 strncat ( cbuffer, textbuf, 50000 );
3382 if ( strchr ( textbuf, '\n' ) ) {
3383 * strchr ( textbuf, '\n' ) = '\0';
3386 // add to pixel loop
3387 if ( 1||textbuf [ 0 ] ) {
3388 textloop [ textmax ] = strdup ( textbuf );
3396 unsigned int textiter = 0;
3397 while ( textiter < textmax ) {
3398 char *text = textloop [ textiter ];
3402 // render to surface
3403 rtext = TTF_RenderText_Blended ( g_grid_font, text, rtextc );
3405 // render font to pixelboard
3406 unsigned int px, py;
3408 unsigned int *pixels = rtext -> pixels;
3409 unsigned char cr, cg, cb, ca;
3410 for ( py = 0; py < rtext -> h; py ++ ) {
3411 for ( px = 0; px < ( rtext -> w > COLS ? COLS : rtext -> w ); px++ ) {
3413 SDL_GetRGBA ( pixels [ ( py * rtext -> pitch / 4 ) + px ],
3414 rtext -> format, &cr, &cg, &cb, &ca );
3418 ph = pixelboard + ( /*y offset */ 30 * COLS ) + ( py * COLS ) + px /* / 2 */;
3425 if ( *ph + ca < 250 ) {
3436 unsigned int runcount = 10;
3437 while ( runcount-- ) {
3440 SDL_FillRect( sdl_realscreen, NULL /* whole */, 0 );
3442 // render pixelboard
3445 for ( y = 0; y < ROWS; y++ ) {
3446 for ( x = 0; x < COLS; x++ ) {
3448 if ( 1||pixelboard [ ( y * COLS ) + x ] ) {
3451 r.x = x * ( PIXELW + MARGINW );
3452 r.y = y * ( PIXELH + MARGINH );
3456 c = SDL_MapRGB ( sdl_realscreen -> format, 100 /* r */, 0 /* g */, pixelboard [ ( y * COLS ) + x ] );
3458 SDL_FillRect( sdl_realscreen, &r /* whole */, c );
3466 unsigned char *pc = pixelboard;
3467 for ( y = 0; y < ROWS; y++ ) {
3468 for ( x = 0; x < COLS; x++ ) {
3478 // slide pixels upwards
3479 memmove ( pixelboard, pixelboard + COLS, ( COLS * ROWS ) - COLS );
3481 // render actual readable text
3484 // display up to cursor
3486 unsigned int cdraw = 0;
3490 if ( crevealed > 200 ) {
3491 cdraw = crevealed - 200;
3497 for ( ; cdraw < crevealed; cdraw++ ) {
3498 ctb [ 0 ] = cbuffer [ cdraw ];
3500 // move over or down
3501 if ( cbuffer [ cdraw ] == '\n' ) {
3506 if ( dest.y > 450 ) {
3512 cs = TTF_RenderText_Blended ( g_tab_font, ctb, rtextc );
3514 SDL_BlitSurface ( cs, NULL /* all */, sdl_realscreen, &dest );
3515 SDL_FreeSurface ( cs );
3525 SDL_FillRect ( sdl_realscreen, &dest /* whole */, 220 );
3527 // increment cursor to next character
3528 if ( cbuffer [ crevealed ] != '\0' ) {
3532 } // draw cursor text
3536 SDL_UpdateRect ( sdl_realscreen, 0, 0, 0, 0 ); // whole screen
3540 // any button? if so, about
3546 if ( SDL_PeepEvents ( &e, 1, SDL_GETEVENT, SDL_EVENTMASK(/*SDL_KEYUP|*/SDL_KEYDOWN) ) > 0 ) {
3555 SDL_FreeSurface ( rtext );
3559 } // while more text
3563 for ( i = 0; i < textmax; i++ ) {
3564 if ( textloop [ i ] ) {
3565 free ( textloop [ i ] );
3573 void ui_revealscreen ( void ) {
3574 char *labels [ 500 ];
3575 unsigned int labelmax = 0;
3577 char fulllabel [ 200 ];
3579 if ( ! category_count ( CFHIDDEN ) ) {
3580 return; // nothing to do
3583 // switch to hidden categories
3584 category_publish ( CFHIDDEN, NULL );
3586 // build up labels to show in menu
3587 for ( i = 0; i < g_categorycount; i++ ) {
3589 if ( g_categories [ i ] -> parent_catname ) {
3590 sprintf ( fulllabel, "%s [%s]", g_categories [ i ] -> catname, g_categories [ i ] -> parent_catname );
3592 sprintf ( fulllabel, "%s", g_categories [ i ] -> catname );
3595 labels [ labelmax++ ] = strdup ( fulllabel );
3599 int sel = ui_modal_single_menu ( labels, labelmax, "Temporary Category Reveal",
3600 "Enter to select; other to return." );
3602 // if selected, try to set this guy to visible
3605 // fix up category name, if its been hacked
3606 #if 0 // prepending and .. wtf crap is this
3607 if ( strchr ( g_categories [ sel ] -> catname, '.' ) ) {
3608 char *t = g_categories [ sel ] -> catname;
3609 g_categories [ sel ] -> catname = strdup ( strchr ( g_categories [ sel ] -> catname, '.' ) + 1 );
3614 // reflag this guy to be visible
3615 g_categories [ sel ] -> catflags = CFNORMAL;
3617 // switch to the new category.. cache name.
3618 char *switch_to_name = g_categories [ sel ] -> catname;
3620 // republish categories
3621 category_publish ( CFNORMAL, NULL );
3623 // switch to the new category.. with the cached name!
3624 ui_category = category_index ( switch_to_name );
3626 // ensure visibility
3627 unsigned int screen_width = ui_display_context.screen_width;
3628 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
3629 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
3630 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
3635 // republish categories
3636 category_publish ( CFNORMAL, NULL );
3639 render_mask |= CHANGED_CATEGORY;
3640 ui_start_defered_icon_thread();
3645 void ui_recache_context ( ui_context_t *c ) {
3647 c -> screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
3649 c -> font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
3650 c -> font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
3651 c -> font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
3652 c -> font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
3654 c -> grid_offset_x = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_x" );
3655 c -> grid_offset_y = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_y" );
3657 c -> icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
3658 c -> icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
3659 c -> icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
3660 c -> icon_max_height = pnd_conf_get_as_int ( g_conf, "grid.icon_max_height" );
3661 c -> sel_icon_offset_x = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_x", 0 );
3662 c -> sel_icon_offset_y = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_y", 0 );
3664 c -> text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
3665 c -> text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
3666 c -> text_offset_x = pnd_conf_get_as_int ( g_conf, "grid.text_offset_x" );
3667 c -> text_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_offset_y" );
3668 c -> text_hilite_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
3670 c -> row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 4 );
3671 c -> col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
3673 c -> cell_width = pnd_conf_get_as_int ( g_conf, "grid.cell_width" );
3674 c -> cell_height = pnd_conf_get_as_int ( g_conf, "grid.cell_height" );
3676 c -> arrow_bar_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
3677 c -> arrow_bar_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
3678 c -> arrow_bar_clip_w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
3679 c -> arrow_bar_clip_h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
3680 c -> arrow_up_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
3681 c -> arrow_up_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
3682 c -> arrow_down_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
3683 c -> arrow_down_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
3686 SDL_Color tmp = { c -> font_rgba_r, c -> font_rgba_g, c -> font_rgba_b, c -> font_rgba_a };
3687 c -> fontcolor = tmp;
3689 // determine font height
3690 if ( g_grid_font ) {
3692 rtext = TTF_RenderText_Blended ( g_grid_font, "M", c -> fontcolor );
3693 c -> text_height = rtext -> h;
3695 c -> text_height = 10;
3700 rtext = TTF_RenderText_Blended ( g_tab_font, "M", c -> fontcolor );
3701 c -> text_height_tab = rtext -> h;
3703 c -> text_height_tab = 15;
3706 // now that we've got 'normal' (detail pane shown) param's, lets check if detail pane
3707 // is hidden; if so, override some values with those alternate skin values where possible.
3708 if ( ui_detail_hidden ) {
3709 // if detail panel is hidden, and theme cannot support it, unhide the bloody thing. (This may help
3710 // when someone is amid theme hacking or changing.)
3711 if ( ! ui_is_detail_hideable() ) {
3712 ui_detail_hidden = 0;
3716 if ( ui_detail_hidden ) {
3718 c -> row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max_w", c -> row_max );
3719 c -> col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max_w", c -> col_max );
3721 c -> cell_width = pnd_conf_get_as_int_d ( g_conf, "grid.cell_width_w", c -> cell_width );
3722 c -> cell_height = pnd_conf_get_as_int_d ( g_conf, "grid.cell_height_w", c -> cell_height );
3724 c -> arrow_bar_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x_w", 450 );
3725 c -> arrow_bar_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y_w", 100 );
3726 c -> arrow_up_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x_w", 450 );
3727 c -> arrow_up_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y_w", 80 );
3728 c -> arrow_down_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x_w", 450 );
3729 c -> arrow_down_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y_w", 80 );
3731 } // if detail hidden.. still.
3733 } // if detail hidden
3738 unsigned char ui_is_detail_hideable ( void ) {
3740 // if skin has a bit of info for wide-mode, we assume wide-mode is available
3741 if ( pnd_conf_get_as_char ( g_conf, "grid.row_max_w" ) != NULL ) {
3749 void ui_toggle_detail_pane ( void ) {
3751 // no bitmask trickery here; I like it to be stand-out obvious at 3am.
3753 if ( ui_detail_hidden ) {
3754 ui_detail_hidden = 0;
3756 ui_detail_hidden = 1;
3759 // repull skin config
3760 ui_recache_context ( &ui_display_context );
3763 render_mask |= CHANGED_EVERYTHING;
3768 void ui_menu_context ( mm_appref_t *a ) {
3770 unsigned char rescan_apps = 0;
3771 unsigned char context_alive = 1;
3776 context_file_delete,
3779 context_app_recategorize,
3780 context_app_recategorize_sub,
3782 context_app_cpuspeed,
3790 char *verbiage[] = {
3791 "Done (return to grid)", // context_done
3792 "Get info about file/dir", // context_file_info
3793 "Delete file/dir", // context_file_delete
3794 "Get info", // context_app_info
3795 "Hide application", // hide
3796 "Recategorize", // recategorize
3797 "Recategorize subcategory", // recategorize
3798 "Change displayed title", // rename
3799 "Set CPU speed for launch", // cpuspeed
3800 "Run application", // run
3801 "Edit notes line 1", // notes1
3802 "Edit notes line 2", // notes2
3803 "Edit notes line 3", // notes3
3806 unsigned short int menu [ context_menu_max ];
3807 char *menustring [ context_menu_max ];
3808 unsigned char menumax = 0;
3811 menu [ menumax ] = context_done; menustring [ menumax++ ] = verbiage [ context_done ];
3813 // hook up appropriate menu options based on tab-type and object-type
3814 if ( g_categories [ ui_category ] -> fspath ) {
3816 menu [ menumax ] = context_file_info; menustring [ menumax++ ] = verbiage [ context_file_info ];
3817 menu [ menumax ] = context_file_delete; menustring [ menumax++ ] = verbiage [ context_file_delete ];
3820 if ( a -> ref -> object_type == pnd_object_type_directory ) {
3821 return; // don't do anything if the guy is a subcat-as-folder
3824 //menu [ menumax ] = context_app_info; menustring [ menumax++ ] = verbiage [ context_app_info ];
3825 menu [ menumax ] = context_app_run; menustring [ menumax++ ] = verbiage [ context_app_run ];
3826 menu [ menumax ] = context_app_hide; menustring [ menumax++ ] = verbiage [ context_app_hide ];
3827 menu [ menumax ] = context_app_recategorize; menustring [ menumax++ ] = verbiage [ context_app_recategorize ];
3828 menu [ menumax ] = context_app_recategorize_sub; menustring [ menumax++ ] = verbiage [ context_app_recategorize_sub ];
3829 menu [ menumax ] = context_app_rename; menustring [ menumax++ ] = verbiage [ context_app_rename ];
3830 menu [ menumax ] = context_app_cpuspeed; menustring [ menumax++ ] = verbiage [ context_app_cpuspeed ];
3831 menu [ menumax ] = context_app_notes1; menustring [ menumax++ ] = verbiage [ context_app_notes1 ];
3832 menu [ menumax ] = context_app_notes2; menustring [ menumax++ ] = verbiage [ context_app_notes2 ];
3833 menu [ menumax ] = context_app_notes3; menustring [ menumax++ ] = verbiage [ context_app_notes3 ];
3837 while ( context_alive ) {
3839 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 */ );
3846 switch ( menu [ sel ] ) {
3852 case context_file_info:
3855 case context_file_delete:
3856 //ui_menu_twoby ( "Delete - Are you sure?", "B/enter; other to cancel", "Delete", "Do not delete" );
3859 case context_app_info:
3862 case context_app_hide:
3865 char confkey [ 1000 ];
3866 snprintf ( confkey, 999, "%s.%s", "appshow", a -> ref -> unique_id );
3869 pnd_conf_set_char ( g_conf, confkey, "0" );
3871 // write conf, so it will take next time
3872 conf_write ( g_conf, conf_determine_location ( g_conf ) );
3873 conf_write ( g_conf, CONF_PREF_TEMPPATH );
3875 // can we just 'hide' this guy without reloading all apps? (this is for you, EvilDragon)
3878 // DOESN'T WORK YET; other parts of app are still hanging onto some values and blow up
3880 char *uid = strdup ( a -> ref -> unique_id );
3882 for ( i = 0; i < g_categorycount; i++ ) {
3883 mm_appref_t *p = g_categories [ i ] -> refs;
3888 if ( strcmp ( p -> ref -> unique_id, uid ) == 0 ) {
3890 if ( g_categories [ i ] -> refcount ) {
3891 g_categories [ i ] -> refcount--;
3896 } // while for each appref
3897 } // for each cat/tab
3902 // request rescan and wrap up
3906 context_alive = 0; // nolonger visible, so lets just get out
3912 case context_app_recategorize:
3915 unsigned char optmax = 0;
3918 // show custom categories
3919 if ( mmcustom_setup() ) {
3921 for ( i = 0; i < mmcustom_count; i++ ) {
3922 if ( mmcustom_complete [ i ].parent_cat == NULL ) {
3923 opts [ optmax++ ] = mmcustom_complete [ i ].cat;
3929 // show FD categories
3930 i = 2; // skip first two - Other and NoParentCategory
3933 if ( ! freedesktop_complete [ i ].cat ) {
3937 if ( ! freedesktop_complete [ i ].parent_cat ) {
3938 opts [ optmax++ ] = freedesktop_complete [ i ].cat;
3945 char prompt [ 101 ];
3946 snprintf ( prompt, 100, "Pick category [%s]", a -> ref -> main_category ? a -> ref -> main_category : "NoParentCategory" );
3948 int sel = ui_modal_single_menu ( opts, optmax, prompt /*"Select parent category"*/, "Enter to select; other to skip." );
3951 char confirm [ 1001 ];
3952 snprintf ( confirm, 1000, "Confirm: %s", opts [ sel ] );
3954 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm categorization", "Do not set category" ) == 1 ) {
3955 ovr_replace_or_add ( a, "maincategory", opts [ sel ] );
3957 // when changing main cat, reset subcat, otherwise you go from Game/Emu to Network/Emu and get sent to Other right away
3958 ovr_replace_or_add ( a, "maincategorysub1", freedesktop_complete [ 2 ].cat );
3963 if ( mmcustom_is_ready() ) {
3964 mmcustom_shutdown();
3970 case context_app_recategorize_sub:
3973 unsigned char optmax = 0;
3974 unsigned char i = 0;
3976 char *whichparentarewe;
3977 if ( g_categories [ ui_category ] -> parent_catname ) {
3978 whichparentarewe = g_categories [ ui_category ] -> parent_catname;
3980 whichparentarewe = g_categories [ ui_category ] -> catname;
3983 // add NoSubcategory magic one
3984 opts [ optmax++ ] = freedesktop_complete [ 2 ].cat;
3986 // add custom categories
3987 if ( mmcustom_setup() ) {
3989 for ( i = 0; i < mmcustom_count; i++ ) {
3990 if ( mmcustom_complete [ i ].parent_cat && strcmp ( mmcustom_complete [ i ].parent_cat, whichparentarewe ) == 0 ) {
3991 opts [ optmax++ ] = mmcustom_complete [ i ].cat;
3997 // add FD categories
4000 if ( ! freedesktop_complete [ i ].cat ) {
4004 if ( ( freedesktop_complete [ i ].parent_cat ) &&
4005 ( strcasecmp ( freedesktop_complete [ i ].parent_cat, whichparentarewe ) == 0 )
4008 opts [ optmax++ ] = freedesktop_complete [ i ].cat;
4014 char prompt [ 101 ];
4015 //snprintf ( prompt, 100, "Currently: %s", a -> ref -> main_category1 ? a -> ref -> main_category1 : "NoSubcategory" );
4016 snprintf ( prompt, 100, "%s [%s]", a -> ref -> main_category1 ? a -> ref -> main_category1 : "NoSubcategory", whichparentarewe );
4018 int sel = ui_modal_single_menu ( opts, optmax, prompt /*"Select subcategory"*/, "Enter to select; other to skip." );
4021 char confirm [ 1001 ];
4022 snprintf ( confirm, 1000, "Confirm: %s", opts [ sel ] );
4024 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm sub-categorization", "Do not set sub-category" ) == 1 ) {
4025 ovr_replace_or_add ( a, "maincategorysub1", opts [ sel ] );
4031 if ( mmcustom_is_ready() ) {
4032 mmcustom_shutdown();
4038 case context_app_rename:
4040 char namebuf [ 101 ];
4041 unsigned char changed;
4043 changed = ui_menu_get_text_line ( "Rename application", "Use keyboard; Enter when done.",
4044 a -> ref -> title_en ? a -> ref -> title_en : "blank", namebuf, 30, 0 /* alphanumeric */ );
4047 char confirm [ 1001 ];
4048 snprintf ( confirm, 1000, "Confirm: %s", namebuf );
4050 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm rename", "Do not rename" ) == 1 ) {
4051 ovr_replace_or_add ( a, "title", namebuf );
4061 case context_app_cpuspeed:
4063 char namebuf [ 101 ];
4064 unsigned char changed;
4066 changed = ui_menu_get_text_line ( "Specify runspeed", "Use keyboard; Enter when done.",
4067 a -> ref -> clockspeed ? a -> ref -> clockspeed : "500", namebuf, 6, 1 /* numeric */ );
4070 char confirm [ 1001 ];
4071 snprintf ( confirm, 1000, "Confirm: %s", namebuf );
4073 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm clockspeed", "Do not set" ) == 1 ) {
4074 ovr_replace_or_add ( a, "clockspeed", namebuf );
4084 case context_app_run:
4088 case context_app_notes1:
4089 case context_app_notes2:
4090 case context_app_notes3:
4092 char namebuf [ 101 ] = "";
4095 unsigned char notenum;
4098 if ( menu [ sel ] == context_app_notes1 ) {
4100 } else if ( menu [ sel ] == context_app_notes2 ) {
4102 } else if ( menu [ sel ] == context_app_notes3 ) {
4106 // figure out key for looking up existing, and for storing replacement
4107 snprintf ( key, 500, "Application-%u.note-%u", a -> ref -> subapp_number, notenum );
4109 // do we have existing value?
4111 char *existing = pnd_conf_get_as_char ( a -> ovrh, key );
4113 strncpy ( namebuf, existing, 100 );
4117 unsigned char changed;
4119 changed = ui_menu_get_text_line ( "Enter replacement note", "Use keyboard; Enter when done.",
4120 namebuf, namebuf, 30, 0 /* not-numeric-forced */ );
4123 ovr_replace_or_add ( a, strchr ( key, '.' ) + 1, namebuf );
4135 } // if useful return
4140 if ( rescan_apps ) {
4141 applications_free();
4142 applications_scan();
4148 unsigned char ui_menu_oneby ( char *title, char *footer, char *one ) {
4151 int sel = ui_modal_single_menu ( opts, 1, title, footer );
4158 unsigned char ui_menu_twoby ( char *title, char *footer, char *one, char *two ) {
4162 int sel = ui_modal_single_menu ( opts, 2, title, footer );
4169 unsigned char ui_menu_get_text_line ( char *title, char *footer, char *initialvalue,
4170 char *r_buffer, unsigned char maxlen, unsigned char numbersonlyp )
4172 SDL_Rect rects [ 40 ];
4173 SDL_Rect *dest = rects;
4177 char hacktext [ 1024 ];
4178 unsigned char shifted = 0;
4180 bzero ( rects, sizeof(SDL_Rect) * 40 );
4182 if ( initialvalue ) {
4183 if ( initialvalue == r_buffer ) {
4184 // already good to go
4186 strncpy ( r_buffer, initialvalue, maxlen );
4189 bzero ( r_buffer, maxlen );
4195 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
4196 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
4197 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
4198 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
4199 SDL_FillRect( sdl_realscreen, dest, 0 );
4201 // show dialog background
4202 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
4205 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> w;
4206 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> h;
4207 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
4208 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
4209 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
4213 // show dialog frame
4214 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
4215 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
4216 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
4217 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
4223 rtext = TTF_RenderText_Blended ( g_tab_font, title, ui_display_context.fontcolor );
4224 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
4225 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
4226 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
4227 SDL_FreeSurface ( rtext );
4233 rtext = TTF_RenderText_Blended ( g_tab_font, footer, ui_display_context.fontcolor );
4234 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
4235 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
4236 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
4238 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
4239 SDL_FreeSurface ( rtext );
4243 // show text line - and embed cursor
4244 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
4245 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( 0/*i*/ + 1 - 0/*first_visible*/ ) );
4247 strncpy ( hacktext, r_buffer, 1000 );
4248 strncat ( hacktext, "\n", 1000 ); // add [] in most fonts
4250 rtext = TTF_RenderText_Blended ( g_tab_font, hacktext, ui_display_context.fontcolor );
4251 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
4252 SDL_FreeSurface ( rtext );
4255 // update all the rects and send it all to sdl
4256 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
4261 while ( SDL_WaitEvent ( &event ) ) {
4263 switch ( event.type ) {
4266 if ( event.key.keysym.sym == SDLK_LSHIFT || event.key.keysym.sym == SDLK_RSHIFT ) {
4273 if ( event.key.keysym.sym == SDLK_LEFT || event.key.keysym.sym == SDLK_BACKSPACE ) {
4274 if ( strlen ( r_buffer ) > 0 ) {
4275 char *eol = strchr ( r_buffer, '\0' );
4276 *( eol - 1 ) = '\0';
4279 } else if ( event.key.keysym.sym == SDLK_UP ) {
4280 r_buffer [ 0 ] = '\0'; // truncate!
4282 } else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_END ) { // return, or "B"
4283 // on Enter/Return or B, if the buffer has 1 or more chars, we return it as valid.. otherwise, invalid.
4284 if ( strlen ( r_buffer ) > 0 ) {
4289 } else if ( event.key.keysym.sym == SDLK_LSHIFT || event.key.keysym.sym == SDLK_RSHIFT ) {
4292 } else if ( event.key.keysym.sym == SDLK_ESCAPE ||
4293 event.key.keysym.sym == SDLK_PAGEUP ||
4294 event.key.keysym.sym == SDLK_PAGEDOWN ||
4295 event.key.keysym.sym == SDLK_HOME
4302 if ( isprint(event.key.keysym.sym) ) {
4304 unsigned char good = 1;
4306 if ( numbersonlyp && ( ! isdigit(event.key.keysym.sym) ) ) {
4310 if ( maxlen && strlen(r_buffer) >= maxlen ) {
4315 char b [ 2 ] = { '\0', '\0' };
4317 b [ 0 ] = toupper ( event.key.keysym.sym );
4319 b [ 0 ] = event.key.keysym.sym;
4321 strncat ( r_buffer, b, maxlen );
4334 } // while waiting for input
4341 unsigned char ovr_replace_or_add ( mm_appref_t *a, char *keybase, char *newvalue ) {
4342 //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 );
4344 char fullpath [ PATH_MAX ];
4346 sprintf ( fullpath, "%s/%s", a -> ref -> object_path, a -> ref -> object_filename );
4347 char *dot = strrchr ( fullpath, '.' );
4349 sprintf ( dot, PXML_SAMEPATH_OVERRIDE_FILEEXT );
4351 pnd_log ( pndn_error, "ERROR: Bad pnd-path in disco_t! %s\n", fullpath );
4355 struct stat statbuf;
4357 if ( stat ( fullpath, &statbuf ) == 0 ) {
4361 h = pnd_conf_fetch_by_path ( fullpath );
4364 return ( 0 ); // fail!
4368 snprintf ( key, 100, "Application-%u.%s", a -> ref -> subapp_number, keybase );
4370 pnd_conf_set_char ( h, key, newvalue );
4372 return ( pnd_conf_write ( h, fullpath ) );
4375 // file needs to be created - easy!
4377 FILE *f = fopen ( fullpath, "w" );
4380 fprintf ( f, "Application-%u.%s\t%s\n", a -> ref -> subapp_number, keybase, newvalue );
4384 return ( 0 ); // fail!
4392 void ui_manage_categories ( void ) {
4393 unsigned char require_app_scan = 0;
4395 if ( ! mmcustom_setup() ) {
4399 char *opts [ 20 ] = {
4400 "List custom categories",
4401 "List custom subcategories",
4402 "Register custom category",
4403 "Register custom subcategory",
4404 "Unregister custom category",
4405 "Unregister custom subcategory",
4411 int sel = ui_modal_single_menu ( opts, 7, "Custom Categories", "B to select; other to cancel." );
4415 case 0: // list custom
4416 ui_pick_custom_category ( 0 );
4419 case 1: // list custom sub
4420 if ( mmcustom_count ) {
4422 char *maincat = ui_pick_custom_category ( 2 );
4425 unsigned int subcount = mmcustom_count_subcats ( maincat );
4426 char titlebuf [ 201 ];
4428 snprintf ( titlebuf, 200, "Category: %s", maincat );
4430 if ( subcount == 0 ) {
4431 ui_menu_oneby ( titlebuf, "B/Enter to accept", "Category has no subcategories." );
4434 char **list = malloc ( subcount * sizeof(char*) );
4436 unsigned int counter = 0;
4438 for ( i = 0; i < mmcustom_count; i++ ) {
4439 if ( mmcustom_complete [ i ].parent_cat && strcasecmp ( mmcustom_complete [ i ].parent_cat, maincat ) == 0 ) {
4440 list [ counter++ ] = mmcustom_complete [ i ].cat;
4444 ui_modal_single_menu ( list, counter, titlebuf, "Any button to exit." );
4448 } // more than 0 subcats?
4450 } // user picked a main cat?
4453 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4457 case 2: // register custom
4459 unsigned char changed;
4460 char namebuf [ 101 ] = "";
4462 changed = ui_menu_get_text_line ( "Enter unique category name", "Use keyboard; Enter when done.",
4463 "Pandora", namebuf, 30, 0 /* alphanumeric */ );
4465 // did the user enter something?
4468 // for now, force use of '*' into something else as we use * internally :/ (FIXME)
4471 while ( ( fixme = strchr ( namebuf, '*' ) ) ) {
4476 // and if so, is it existant already or not?
4477 if ( mmcustom_query ( namebuf, NULL ) ) {
4478 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a registered category." );
4479 } else if ( freedesktop_category_query ( namebuf, NULL ) ) {
4480 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a Standard category." );
4483 char confirm [ 1001 ];
4484 snprintf ( confirm, 1000, "Confirm: %s", namebuf );
4486 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm new category", "Do not register" ) == 1 ) {
4487 // register, save, recycle the current list
4488 mmcustom_register ( namebuf, NULL );
4489 mmcustom_write ( NULL );
4490 mmcustom_shutdown();
4496 } // entered something?
4501 case 3: // register custom sub
4502 if ( 1 /*mmcustom_count -- we allow FD cats now, so this isn't applicable error */ ) {
4504 char *maincat = ui_pick_custom_category ( 1 /* include FD */ );
4507 char titlebuf [ 201 ];
4509 snprintf ( titlebuf, 200, "Subcat of: %s", maincat );
4511 unsigned char changed;
4512 char namebuf [ 101 ] = "";
4514 changed = ui_menu_get_text_line ( titlebuf, "Use keyboard; Enter when done.", "Submarine", namebuf, 30, 0 /* alphanumeric */ );
4516 // did the user enter something?
4519 // for now, force use of '*' into something else as we use * internally :/ (FIXME)
4522 while ( ( fixme = strchr ( namebuf, '*' ) ) ) {
4527 // and if so, is it existant already or not?
4528 if ( mmcustom_query ( namebuf, maincat ) ) {
4529 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a subcategory." );
4530 } else if ( freedesktop_category_query ( namebuf, maincat ) ) {
4531 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a Standard subcategory." );
4534 char confirm [ 1001 ];
4535 snprintf ( confirm, 1000, "Confirm: %s [%s]", namebuf, maincat );
4537 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm new category", "Do not register" ) == 1 ) {
4538 // register, save, recycle the current list
4539 mmcustom_register ( namebuf, maincat );
4540 mmcustom_write ( NULL );
4541 mmcustom_shutdown();
4547 } // entered something?
4549 } // selected parent cat?
4552 ui_menu_oneby ( "Warning", "B/Enter to accept", "No categories registered." );
4556 case 4: // unreg custom
4557 if ( mmcustom_count ) {
4558 char *maincat = ui_pick_custom_category ( 0 );
4561 char confirm [ 1001 ];
4562 snprintf ( confirm, 1000, "Confirm remove: %s", maincat );
4564 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm unregister", "Do not unregister" ) == 1 ) {
4565 // register, save, recycle the current list
4566 mmcustom_unregister ( maincat, NULL );
4567 mmcustom_write ( NULL );
4568 mmcustom_shutdown();
4575 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4579 case 5: // unreg custom sub
4580 if ( mmcustom_count ) {
4581 char *maincat = ui_pick_custom_category ( 2 );
4584 unsigned int subcount = mmcustom_count_subcats ( maincat );
4585 char titlebuf [ 201 ];
4587 snprintf ( titlebuf, 200, "Category: %s", maincat );
4589 if ( subcount == 0 ) {
4590 ui_menu_oneby ( titlebuf, "B/Enter to accept", "Category has no subcategories." );
4593 char **list = malloc ( subcount * sizeof(char*) );
4595 unsigned int counter = 0;
4597 for ( i = 0; i < mmcustom_count; i++ ) {
4598 if ( mmcustom_complete [ i ].parent_cat && strcasecmp ( mmcustom_complete [ i ].parent_cat, maincat ) == 0 ) {
4599 list [ counter++ ] = mmcustom_complete [ i ].cat;
4603 int sel = ui_modal_single_menu ( list, counter, titlebuf, "B to selct; other to exit." );
4606 char confirm [ 1001 ];
4607 snprintf ( confirm, 1000, "Confirm remove: %s", list [ sel ] );
4609 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm unregister", "Do not unregister" ) == 1 ) {
4610 // register, save, recycle the current list
4611 mmcustom_unregister ( list [ sel ], maincat );
4612 mmcustom_write ( NULL );
4613 mmcustom_shutdown();
4621 } // more than 0 subcats?
4623 } // user picked a main cat?
4626 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4633 if ( sel < 0 || sel > 5 ) {
4637 } // while running the menu
4639 // shut down custom cats
4640 mmcustom_shutdown();
4643 if ( require_app_scan ) {
4644 applications_free();
4645 applications_scan();
4649 render_mask |= CHANGED_EVERYTHING;
4654 // mode 0 == custom main only; 1 == custom main + FD main; 2 == custom main + FD mains-with-custom-subs
4655 char *ui_pick_custom_category ( unsigned char mode ) {
4658 unsigned int counter = 0;
4660 // alloc space for list, depending on scope
4662 list = malloc ( (mmcustom_count+freedesktop_count()) * sizeof(char*) );
4664 list = malloc ( mmcustom_count * sizeof(char*) );
4668 for ( i = 0; i < mmcustom_count; i++ ) {
4669 if ( mmcustom_complete [ i ].parent_cat == NULL ) {
4670 list [ counter++ ] = mmcustom_complete [ i ].cat;
4680 if ( ! freedesktop_complete [ i ].cat ) {
4685 if ( freedesktop_complete [ i ].parent_cat == NULL ) {
4687 // mode 1 == include them all
4688 // mode 2 == include them if they have a custom subcat
4689 if ( ( mode == 1 ) ||
4690 ( mmcustom_subcount ( freedesktop_complete [ i ].cat ) ) )
4692 list [ counter++ ] = freedesktop_complete [ i ].cat;
4702 // we actually showing anything?
4704 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4709 int sel = ui_modal_single_menu ( list, counter, "Custom Categories", "Any button to exit." );
4716 char *foo = list [ sel ];
4722 void ui_start_defered_icon_thread ( void ) {
4724 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) != 1 ) {
4728 if ( g_icon_thread_busy ) {
4729 //fprintf ( stderr, "REM: Waiting for thread to stop..\n" );
4730 ui_stop_defered_icon_thread();
4733 //fprintf ( stderr, "WARN: Starting new icon caching thread..\n" );
4734 g_icon_thread = SDL_CreateThread ( (void*)ui_threaded_defered_icon, NULL );
4736 if ( ! g_icon_thread ) {
4737 pnd_log ( pndn_error, "ERROR: Couldn't create icon thread\n" );
4743 void ui_stop_defered_icon_thread ( void ) {
4744 time_t started = time ( NULL );
4746 // ask thread to stop, then wait for it (if two run at same time, or if we change
4747 // category content under neath it, could be bad..)
4748 g_icon_thread_stop = 1;
4749 while ( g_icon_thread_busy ) {
4750 time ( NULL ); // spin
4752 g_icon_thread_stop = 0;
4754 fprintf ( stderr, "REM: Thread stoppage took %u seconds.\n", (int) ( time ( NULL ) - started ) );