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_list; // 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
98 static int ui_selected_index ( void );
99 static void ui_start_defered_icon_thread ( void );
100 static void ui_stop_defered_icon_thread ( void );
102 unsigned char ui_setup ( void ) {
107 SDL_Init ( SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE );
109 SDL_JoystickOpen ( 0 ); // turn on joy-0
111 SDL_WM_SetCaption ( "mmenu", "mmenu" );
113 // hide the mouse cursor if we can
114 if ( SDL_ShowCursor ( -1 ) == 1 ) {
115 SDL_ShowCursor ( 0 );
121 unsigned int svm = SDL_SWSURFACE /*| SDL_FULLSCREEN*/ /* 0*/;
122 if ( pnd_conf_get_as_int_d ( g_conf, "display.fullscreen", 0 ) > 0 ) {
123 svm |= SDL_FULLSCREEN;
127 SDL_SetVideoMode ( 800 * g_scale, 480 * g_scale, 16 /*bpp*/, svm );
129 if ( ! sdl_realscreen ) {
130 pnd_log ( pndn_error, "ERROR: Couldn't open SDL real screen; dieing." );
134 pnd_log ( pndn_debug, "Pixel format:" );
135 pnd_log ( pndn_debug, "bpp b: %u\n", sdl_realscreen -> format -> BitsPerPixel );
136 pnd_log ( pndn_debug, "bpp B: %u\n", sdl_realscreen -> format -> BytesPerPixel );
137 pnd_log ( pndn_debug, "R mask: %08x\n", sdl_realscreen -> format -> Rmask );
138 pnd_log ( pndn_debug, "G mask: %08x\n", sdl_realscreen -> format -> Gmask );
139 pnd_log ( pndn_debug, "B mask: %08x\n", sdl_realscreen -> format -> Bmask );
145 /* Set 16-bit stereo audio at 22Khz */
146 fmt.freq = 44100; //22050;
147 fmt.format = AUDIO_S16; //AUDIO_S16;
149 fmt.samples = 2048; /* A good value for games */
150 fmt.callback = mixaudio;
153 /* Open the audio device and start playing sound! */
154 if ( SDL_OpenAudio ( &fmt, NULL ) < 0 ) {
155 zotlog ( "Unable to open audio: %s\n", SDL_GetError() );
159 SDL_PauseAudio ( 0 );
164 SDL_EnableKeyRepeat ( 500, 125 /* 150 */ );
167 //IMG_Init ( IMG_INIT_JPG | IMG_INIT_PNG );
173 if ( TTF_Init() == -1 ) {
174 pnd_log ( pndn_error, "ERROR: Couldn't set up SDL TTF lib\n" );
175 return ( 0 ); // couldn't set up SDL TTF
178 char fullpath [ PATH_MAX ];
180 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "minimenu.font" ) );
181 g_big_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
182 if ( ! g_big_font ) {
183 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
184 pnd_conf_get_as_char ( g_conf, "minimenu.font" ), pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
185 return ( 0 ); // couldn't set up SDL TTF
189 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "grid.font" ) );
190 g_grid_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
191 if ( ! g_grid_font ) {
192 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
193 pnd_conf_get_as_char ( g_conf, "grid.font" ), pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
194 return ( 0 ); // couldn't set up SDL TTF
198 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "detailtext.font" ) );
199 g_detailtext_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
200 if ( ! g_detailtext_font ) {
201 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
202 pnd_conf_get_as_char ( g_conf, "detailtext.font" ), pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
203 return ( 0 ); // couldn't set up SDL TTF
207 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "tabs.font" ) );
208 g_tab_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
209 if ( ! g_tab_font ) {
210 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
211 pnd_conf_get_as_char ( g_conf, "tabs.font" ), pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
212 return ( 0 ); // couldn't set up SDL TTF
215 // determine display context
216 if ( pnd_conf_get_as_int_d ( g_conf, "display.show_detail_pane", 1 ) > 0 ) {
217 ui_detail_hidden = 0;
219 ui_detail_hidden = 1;
221 ui_recache_context ( &ui_display_context );
226 mm_imgcache_t g_imagecache [ IMG_TRUEMAX ] = {
227 { IMG_BACKGROUND_800480, "graphics.IMG_BACKGROUND_800480" },
228 { IMG_BACKGROUND_TABMASK, "graphics.IMG_BACKGROUND_TABMASK" },
229 { IMG_DETAIL_PANEL, "graphics.IMG_DETAIL_PANEL" },
230 { IMG_DETAIL_BG, "graphics.IMG_DETAIL_BG" },
231 { IMG_SELECTED_ALPHAMASK, "graphics.IMG_SELECTED_ALPHAMASK" },
232 { IMG_TAB_SEL, "graphics.IMG_TAB_SEL" },
233 { IMG_TAB_SEL_L, "graphics.IMG_TAB_SEL_L" },
234 { IMG_TAB_SEL_R, "graphics.IMG_TAB_SEL_R" },
235 { IMG_TAB_UNSEL, "graphics.IMG_TAB_UNSEL" },
236 { IMG_TAB_UNSEL_L, "graphics.IMG_TAB_UNSEL_L" },
237 { IMG_TAB_UNSEL_R, "graphics.IMG_TAB_UNSEL_R" },
238 { IMG_TAB_LINE, "graphics.IMG_TAB_LINE" },
239 { IMG_TAB_LINEL, "graphics.IMG_TAB_LINEL" },
240 { IMG_TAB_LINER, "graphics.IMG_TAB_LINER" },
241 { IMG_ICON_MISSING, "graphics.IMG_ICON_MISSING" },
242 { IMG_SELECTED_HILITE, "graphics.IMG_SELECTED_HILITE" },
243 { IMG_PREVIEW_MISSING, "graphics.IMG_PREVIEW_MISSING" },
244 { IMG_ARROW_UP, "graphics.IMG_ARROW_UP", },
245 { IMG_ARROW_DOWN, "graphics.IMG_ARROW_DOWN", },
246 { IMG_ARROW_SCROLLBAR, "graphics.IMG_ARROW_SCROLLBAR", },
247 { IMG_HOURGLASS, "graphics.IMG_HOURGLASS", },
248 { IMG_FOLDER, "graphics.IMG_FOLDER", },
249 { IMG_EXECBIN, "graphics.IMG_EXECBIN", },
250 { IMG_SUBCATFOLDER, "graphics.IMG_SUBCATFOLDER", "graphics.IMG_FOLDER", },
251 { IMG_DOTDOTFOLDER, "graphics.IMG_DOTDOTFOLDER", "graphics.IMG_FOLDER", },
253 { IMG_LIST_ALPHAMASK, NULL }, // generated
254 { IMG_LIST_ALPHAMASK_W, NULL }, // generated
257 unsigned char ui_imagecache ( char *basepath ) {
259 char fullpath [ PATH_MAX ];
264 for ( i = 0; i < IMG_MAX; i++ ) {
266 if ( g_imagecache [ i ].id != i ) {
267 pnd_log ( pndn_error, "ERROR: Internal table mismatch during caching [%u]\n", i );
271 for ( try = 0; try < 2; try++ ) {
276 filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].confname );
278 if ( g_imagecache [ i ].alt_confname ) {
279 filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].alt_confname );
286 pnd_log ( pndn_error, "ERROR: (Try %u) Missing filename in conf for key: %s\n", try + 1, g_imagecache [ i ].confname );
287 if ( try == 0 ) { continue; } else { return ( 0 ); }
290 if ( filename [ 0 ] == '/' ) {
291 strncpy ( fullpath, filename, PATH_MAX );
293 sprintf ( fullpath, "%s/%s", basepath, filename );
296 if ( ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
297 break; // no retry needed
299 pnd_log ( pndn_error, "ERROR: (Try %u) Couldn't load static cache image: %s\n", try + 1, fullpath );
300 if ( try == 0 ) { continue; } else { return ( 0 ); }
310 //g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = SDL_CreateRGBSurface ( SDL_SWSURFACE, 60, 60, 32, 0xFF0000, 0x00FF00, 0xFF, 0xFF000000 );
311 //boxRGBA ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, 0, 0, 60, 60, 100, 100, 100, 250 );
313 SDL_Surface *p = g_imagecache [ IMG_SELECTED_ALPHAMASK ].i;
314 g_imagecache [ IMG_LIST_ALPHAMASK ].i = SDL_ConvertSurface ( p, p -> format, p -> flags );
315 g_imagecache [ IMG_LIST_ALPHAMASK_W ].i = SDL_ConvertSurface ( p, p -> format, p -> flags );
317 g_imagecache [ IMG_LIST_ALPHAMASK ].i =
318 ui_scale_image ( g_imagecache [ IMG_LIST_ALPHAMASK ].i,
319 pnd_conf_get_as_int ( g_conf, "grid.col_max" ) * pnd_conf_get_as_int ( g_conf, "grid.cell_width" ) , -1 );
321 g_imagecache [ IMG_LIST_ALPHAMASK_W ].i =
322 ui_scale_image ( g_imagecache [ IMG_LIST_ALPHAMASK_W ].i,
323 pnd_conf_get_as_int ( g_conf, "grid.col_max_w" ) * pnd_conf_get_as_int ( g_conf, "grid.cell_width_w" ) , -1 );
329 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 );
330 // scale text hilight
331 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 );
332 // scale preview no-pic
333 g_imagecache [ IMG_PREVIEW_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_PREVIEW_MISSING ].i,
334 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ),
335 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 50 ) );
337 // set alpha on detail panel
338 //SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
343 void ui_render ( void ) {
346 // divide width: 550 / 250
347 // divide left side: 5 columns == 110px width
348 // 20px buffer either side == 70px wide icon + 20 + 20?
350 // what jobs to do during render?
354 #define R_TABS (1<<1)
355 #define R_DETAIL (1<<2)
356 #define R_GRID (1<<3)
358 #define R_ALL (R_BG|R_TABS|R_DETAIL|R_GRID)
360 unsigned int render_jobs_b = 0;
362 if ( render_mask & CHANGED_EVERYTHING ) {
363 render_jobs_b |= R_ALL;
366 if ( render_mask & CHANGED_SELECTION ) {
367 render_jobs_b |= R_GRID;
368 render_jobs_b |= R_DETAIL;
371 if ( render_mask & CHANGED_CATEGORY ) {
372 render_jobs_b |= R_ALL;
375 render_mask = CHANGED_NOTHING;
379 unsigned int icon_rows;
380 unsigned int icon_visible_rows = 0; // list view, max number of visible rows
383 SDL_Rect rects [ MAXRECTS ], src;
384 SDL_Rect *dest = rects;
385 bzero ( dest, sizeof(SDL_Rect)*MAXRECTS );
387 unsigned int row, displayrow, col;
388 mm_appref_t *appiter;
390 ui_context_t *c = &ui_display_context; // for convenience and shorthand
392 // on demand icon loading
393 static int load_visible = -1;
394 if ( load_visible == -1 ) {
395 load_visible = pnd_conf_get_as_int_d ( g_conf, "minimenu.load_visible_icons", 0 );
399 // if no selected app yet, select the first one
400 if ( ! ui_selected && pnd_conf_get_as_int_d ( g_conf, "minimenu.start_selected", 0 ) ) {
402 // pick first visible app
403 ui_selected = g_categories [ ui_category ] -> refs;
405 // change.. so we pick first visible if option is set .. but now we also try to restore
406 // selection to the last app selected in previous session (if there is one.)
407 char *previous_unique_id = pnd_conf_get_as_char ( g_conf, "minimenu.last_known_app_uid" );
409 if ( previous_unique_id ) {
411 // 1) we should already be in the right category, since its set in ui_post_scan to minimenu.last_known_catname
412 // 2) so we just pick the app in question..
413 mm_appref_t *previter = g_categories [ ui_category ] -> refs;
415 if ( strcmp ( previter -> ref -> unique_id, previous_unique_id ) == 0 ) {
418 previter = previter -> next;
422 ui_selected = previter;
430 // how many total rows do we need?
431 if ( g_categorycount ) {
433 if ( ui_viewmode == uiv_list ) {
434 // in list view, dimension of grid area is ..
435 // grid height == cell-height * row-max
436 // font height == display_context -> text_height
437 // padding == icon_offset_y
438 // max visible --> row-max == grid height / ( font-height + padding )
440 icon_rows = g_categories [ ui_category ] -> refcount; // one app per row
441 icon_visible_rows = ( c -> cell_height * c -> row_max ) / ( c -> text_height + c -> icon_offset_y );
445 icon_rows = g_categories [ ui_category ] -> refcount / c -> col_max;
446 if ( g_categories [ ui_category ] -> refcount % c -> col_max > 0 ) {
454 icon_visible_rows = 0;
457 // reset touchscreen regions
458 if ( render_jobs_b ) {
462 // ensure selection is visible
465 unsigned char autoscrolled = 1;
466 while ( autoscrolled ) {
469 int index = ui_selected_index();
471 if ( ui_viewmode == uiv_list ) {
473 if ( index >= ui_rows_scrolled_down + icon_visible_rows ) {
474 ui_rows_scrolled_down += 1;
476 render_jobs_b |= R_ALL;
477 } else if ( index < ui_rows_scrolled_down ) {
478 ui_rows_scrolled_down -= 1;
480 render_jobs_b |= R_ALL;
486 int topleft = c -> col_max * ui_rows_scrolled_down;
487 int botright = ( c -> col_max * ( ui_rows_scrolled_down + c -> row_max ) - 1 );
489 if ( index < topleft ) {
490 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
491 render_jobs_b |= R_ALL;
493 } else if ( index > botright ) {
494 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
495 render_jobs_b |= R_ALL;
501 } // while autoscrolling
503 if ( ui_rows_scrolled_down < 0 ) {
504 ui_rows_scrolled_down = 0;
505 } else if ( ui_rows_scrolled_down > icon_rows ) {
506 ui_rows_scrolled_down = icon_rows;
512 if ( render_jobs_b & R_BG ) {
514 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
517 dest -> w = sdl_realscreen -> w;
518 dest -> h = sdl_realscreen -> h;
519 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
524 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
527 dest -> w = sdl_realscreen -> w;
528 dest -> h = sdl_realscreen -> h;
529 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
536 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
537 static unsigned int tab_width;
538 static unsigned int tab_height;
539 static unsigned int tab_offset_x;
540 static unsigned int tab_offset_y;
541 static unsigned int text_offset_x;
542 static unsigned int text_offset_y;
543 static unsigned int text_width;
545 static unsigned char tab_first_run = 1;
546 if ( tab_first_run ) {
548 tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
549 tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
550 tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
551 tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
552 text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
553 text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
554 text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
557 unsigned int maxtab = ( c -> screen_width / tab_width ) < g_categorycount ? ( c -> screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift;
558 unsigned int maxtabspot = ( c -> screen_width / tab_width );
560 if ( g_categorycount > 0 ) {
562 // draw tabs with categories
563 for ( col = ui_catshift;
570 // if this is the first (leftmost) tab, we use different artwork
571 // than if the other tabs (so skinner can link lines up nicely.)
572 if ( col == ui_catshift ) {
573 // leftmost tab, special case
575 if ( col == ui_category ) {
576 s = g_imagecache [ IMG_TAB_SEL_L ].i;
578 s = g_imagecache [ IMG_TAB_UNSEL_L ].i;
581 } else if ( col == maxtab - 1 ) {
582 // rightmost tab, special case
584 if ( col == ui_category ) {
585 s = g_imagecache [ IMG_TAB_SEL_R ].i;
587 s = g_imagecache [ IMG_TAB_UNSEL_R ].i;
591 // normal (not leftmost) tab
593 if ( col == ui_category ) {
594 s = g_imagecache [ IMG_TAB_SEL ].i;
596 s = g_imagecache [ IMG_TAB_UNSEL ].i;
599 } // first col, or not first col?
606 if ( col == ui_category ) {
607 src.h = tab_selheight;
615 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
616 dest -> y = tab_offset_y;
619 ui_register_tab ( col, dest -> x, dest -> y, tab_width, tab_height );
621 if ( render_jobs_b & R_TABS ) {
622 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
623 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
627 if ( col == ui_category ) {
628 // no line for selected tab
630 if ( col - ui_catshift == 0 ) {
631 s = g_imagecache [ IMG_TAB_LINEL ].i;
632 } else if ( col - ui_catshift == maxtabspot - 1 ) {
633 s = g_imagecache [ IMG_TAB_LINER ].i;
635 s = g_imagecache [ IMG_TAB_LINE ].i;
637 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
638 dest -> y = tab_offset_y + tab_height;
639 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
645 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ] -> catname, c -> fontcolor );
648 src.w = rtext -> w < text_width ? rtext -> w : text_width;
650 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
651 dest -> y = tab_offset_y + text_offset_y;
652 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
653 SDL_FreeSurface ( rtext );
660 } // if we got categories
662 if ( render_jobs_b & R_TABS ) {
664 // draw tab lines under where tabs would be if we had categories
665 for ( /* foo */; col < maxtabspot; col++ ) {
668 if ( col - ui_catshift == 0 ) {
669 s = g_imagecache [ IMG_TAB_LINEL ].i;
670 } else if ( col - ui_catshift == maxtabspot - 1 ) {
671 s = g_imagecache [ IMG_TAB_LINER ].i;
673 s = g_imagecache [ IMG_TAB_LINE ].i;
675 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
676 dest -> y = tab_offset_y + tab_height;
677 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
686 // scroll bars and arrows
687 if ( render_jobs_b & R_BG ) {
688 unsigned char show_bar = 0;
691 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
692 dest -> x = c -> arrow_up_x;
693 dest -> y = c -> arrow_up_y;
694 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
701 if ( ui_rows_scrolled_down + c -> row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
702 dest -> x = c -> arrow_down_x;
703 dest -> y = c -> arrow_down_y;
704 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
711 // show scrollbar as well
714 src.w = c -> arrow_bar_clip_w;
715 src.h = c -> arrow_bar_clip_h;
716 dest -> x = c -> arrow_bar_x;
717 dest -> y = c -> arrow_bar_y;
718 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
722 } // r_bg, scroll bars
724 // render detail pane bg
725 if ( render_jobs_b & R_DETAIL && ui_detail_hidden == 0 ) {
727 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
730 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
731 src.x = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
732 src.y = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
733 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
734 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
735 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
736 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
737 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
741 // render detail pane
742 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
743 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
744 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
745 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
749 } // detailpane frame/bg
753 // anything to render?
754 if ( render_jobs_b & R_GRID && g_categorycount ) {
756 // if just rendering grid, and nothing else, better clear it first
757 if ( ! ( render_jobs_b & R_BG ) ) {
758 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
759 src.x = c -> grid_offset_x;
760 src.y = c -> grid_offset_y + c -> sel_icon_offset_y;
761 src.w = c -> col_max * c -> cell_width;
762 src.h = c -> row_max * c -> cell_height;
764 dest -> x = c -> grid_offset_x;
765 dest -> y = c -> grid_offset_y + c -> sel_icon_offset_y;
767 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
773 // any apps to render at all?
774 if ( g_categories [ ui_category ] -> refs ) {
776 // render grid differently based on view mode..
778 if ( ui_viewmode == uiv_list ) {
780 appiter = g_categories [ ui_category ] -> refs;
781 row = 0; // row under consideration (ie: could be scrolled off)
782 displayrow = 0; // rows displayed
784 while ( appiter != NULL ) {
786 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
787 if ( row >= ui_rows_scrolled_down ) {
789 // background hilight
790 SDL_Surface *hilight = ui_detail_hidden ? g_imagecache [ IMG_LIST_ALPHAMASK_W ].i : g_imagecache [ IMG_LIST_ALPHAMASK ].i;
791 if ( appiter == ui_selected ) {
794 src.w = hilight -> w;
795 src.h = c -> text_height + c -> icon_offset_y;
796 dest -> x = c -> grid_offset_x + c -> text_clip_x;
797 dest -> y = c -> grid_offset_y + ( displayrow * ( c -> text_height + c -> icon_offset_y ) ) - ( c -> icon_offset_y / 2 );
798 SDL_BlitSurface ( hilight, &src, sdl_realscreen, dest );
803 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
805 dest -> x = c -> grid_offset_x + c -> text_clip_x;
806 dest -> y = c -> grid_offset_y + ( displayrow * ( c -> text_height + c -> icon_offset_y ) ) - ( c -> icon_offset_y / 2 );
807 SDL_BlitSurface ( ic -> itiny, NULL, sdl_realscreen, dest );
811 if ( appiter -> ref -> title_en ) {
813 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, c -> fontcolor );
816 src.w = hilight -> w; //c -> text_width < rtext -> w ? c -> text_width : rtext -> w;
819 dest -> x = c -> grid_offset_x + c -> text_clip_x;
820 dest -> x += 20; // so all title-text line up, regardless of icon presence
823 dest -> x += 20; //((SDL_Surface*)ic -> i) -> w;
827 dest -> y = c -> grid_offset_y + ( displayrow * ( c -> text_height + c -> icon_offset_y ) );
828 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
829 SDL_FreeSurface ( rtext );
833 } // visible or scrolled?
835 if ( row >= ui_rows_scrolled_down ) {
839 // are we done displaying rows?
840 if ( displayrow >= icon_visible_rows ) {
844 appiter = appiter -> next;
851 appiter = g_categories [ ui_category ] -> refs;
855 // until we run out of apps, or run out of space
856 while ( appiter != NULL ) {
858 for ( col = 0; col < c -> col_max && appiter != NULL; col++ ) {
860 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
861 if ( row >= ui_rows_scrolled_down ) {
863 // selected? show hilights
864 if ( appiter == ui_selected ) {
865 SDL_Surface *s = g_imagecache [ IMG_SELECTED_ALPHAMASK ].i;
867 //dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + ( ( icon_max_width - s -> w ) / 2 );
868 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> icon_offset_x + c -> sel_icon_offset_x;
869 //dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + ( ( icon_max_height - s -> h ) / 2 );
870 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> icon_offset_y + c -> sel_icon_offset_y;
871 SDL_BlitSurface ( s, NULL /* all */, sdl_realscreen, dest );
874 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_clip_x;
875 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> text_hilite_offset_y;
876 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
881 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
882 SDL_Surface *iconsurface;
884 // if icon not in cache, and its a pnd-file source, perhaps try to load it right now..
887 ( ! ( appiter -> ref -> object_flags & PND_DISCO_GENERATED ) )
890 // try to load any icons that..
891 // - are not yet loaded
892 // - did not fail a previous load attempt
893 // this way user can upfront load all icons, or defer all icons, or even defer all icons
894 // and still try to load visible ones 'just before needed'; so not at mmenu load time, but
895 // as needed (only the ones needed.)
897 if ( ( appiter -> ref -> pnd_icon_pos ) ||
898 ( appiter -> ref -> icon && appiter -> ref -> object_flags & PND_DISCO_LIBPND_DD )
903 if ( ! cache_icon ( appiter -> ref, ui_display_context.icon_max_width, ui_display_context.icon_max_width ) ) {
908 appiter -> ref -> pnd_icon_pos = 0;
909 if ( appiter -> ref -> icon ) {
910 free ( appiter -> ref -> icon );
911 appiter -> ref -> icon = NULL;
914 // pick up as if nothing happened..
915 ic = cache_query_icon ( appiter -> ref -> unique_id );
919 } // load icon during rendering?
922 iconsurface = ic -> i;
924 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
926 // no icon override; was this a pnd-file (show the unknown icon then), or was this generated from
927 // filesystem (file or directory icon)
928 if ( appiter -> ref -> object_flags & PND_DISCO_GENERATED ) {
929 if ( appiter -> ref -> object_type == pnd_object_type_directory ) {
931 // is this a subcat, a .., or a filesystem folder?
932 //iconsurface = g_imagecache [ IMG_FOLDER ].i;
933 if ( g_categories [ ui_category ] -> fspath ) {
934 iconsurface = g_imagecache [ IMG_FOLDER ].i;
935 } else if ( strcmp ( appiter -> ref -> title_en, ".." ) == 0 ) {
936 iconsurface = g_imagecache [ IMG_DOTDOTFOLDER ].i;
938 iconsurface = g_imagecache [ IMG_SUBCATFOLDER ].i;
942 iconsurface = g_imagecache [ IMG_EXECBIN ].i;
945 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
950 // got an icon I hope?
952 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
958 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> icon_offset_x + (( c -> icon_max_width - iconsurface -> w ) / 2);
959 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> icon_offset_y + (( c -> icon_max_height - iconsurface -> h ) / 2);
961 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
964 ui_register_app ( appiter, dest -> x, dest -> y, src.w, src.h );
971 if ( appiter -> ref -> title_en ) {
973 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, c -> fontcolor );
976 src.w = c -> text_width < rtext -> w ? c -> text_width : rtext -> w;
978 if ( rtext -> w > c -> text_width ) {
979 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_clip_x;
981 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_offset_x - ( rtext -> w / 2 );
983 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> text_offset_y;
984 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
985 SDL_FreeSurface ( rtext );
989 } // display now? or scrolled away..
992 appiter = appiter -> next;
994 } // for column 1...X
996 if ( row >= ui_rows_scrolled_down ) {
1002 // are we done displaying rows?
1003 if ( displayrow >= c -> row_max ) {
1012 // no apps to render?
1013 pnd_log ( pndn_rem, "No applications to render?\n" );
1014 } // apps to renser?
1018 // detail panel - show app details or blank-message
1019 if ( render_jobs_b & R_DETAIL && ui_detail_hidden == 0 ) {
1021 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
1022 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
1023 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
1025 unsigned int desty = cell_offset_y;
1027 if ( ui_selected ) {
1029 char buffer [ 256 ];
1032 if ( ui_selected -> ref -> title_en ) {
1034 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, c -> fontcolor );
1037 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
1039 dest -> x = cell_offset_x;
1041 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1042 SDL_FreeSurface ( rtext );
1049 if ( ui_selected -> ref -> main_category ) {
1051 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
1054 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
1057 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
1059 dest -> x = cell_offset_x;
1061 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1062 SDL_FreeSurface ( rtext );
1069 if ( ui_selected -> ref -> clockspeed ) {
1071 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
1074 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
1077 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
1079 dest -> x = cell_offset_x;
1081 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1082 SDL_FreeSurface ( rtext );
1087 // show sub-app# on right side of cpu clock?
1088 //if ( ui_selected -> ref -> subapp_number )
1090 sprintf ( buffer, "(app#%u)", ui_selected -> ref -> subapp_number );
1093 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1094 dest -> x = cell_offset_x + cell_width - rtext -> w;
1095 dest -> y = desty - src.h;
1096 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1097 SDL_FreeSurface ( rtext );
1102 #if 0 // merged into hint-line
1103 if ( ui_selected -> ref -> info_filename ) {
1105 sprintf ( buffer, "Documentation - hit Y" );
1108 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
1111 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
1113 dest -> x = cell_offset_x;
1115 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1116 SDL_FreeSurface ( rtext );
1123 if ( ui_selected -> ovrh ) {
1128 desty += 5; // a touch of spacing can't hurt
1130 for ( i = 1; i < 4; i++ ) {
1131 sprintf ( buffer, "Application-%u.note-%u", ui_selected -> ref -> subapp_number, i );
1132 n = pnd_conf_get_as_char ( ui_selected -> ovrh, buffer );
1136 rtext = TTF_RenderText_Blended ( g_detailtext_font, n, c -> fontcolor );
1139 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
1141 dest -> x = cell_offset_x;
1143 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1144 SDL_FreeSurface ( rtext );
1146 desty += rtext -> h;
1150 } // r_detail -> notes
1153 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
1154 SDL_Surface *previewpic;
1157 previewpic = ic -> i;
1159 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
1163 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
1164 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
1165 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
1166 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
1172 char *empty_message = "Press SELECT for menu";
1176 rtext = TTF_RenderText_Blended ( g_detailtext_font, empty_message, c -> fontcolor );
1180 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
1182 dest -> x = cell_offset_x;
1184 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1185 SDL_FreeSurface ( rtext );
1190 rtext = TTF_RenderText_Blended ( g_detailtext_font, "START or B to run app", c -> fontcolor );
1191 dest -> x = cell_offset_x;
1193 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1194 SDL_FreeSurface ( rtext );
1198 rtext = TTF_RenderText_Blended ( g_detailtext_font, "SPACE for app menu", c -> fontcolor );
1199 dest -> x = cell_offset_x;
1201 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1202 SDL_FreeSurface ( rtext );
1206 rtext = TTF_RenderText_Blended ( g_detailtext_font, "A to toggle details", c -> fontcolor );
1207 dest -> x = cell_offset_x;
1209 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1210 SDL_FreeSurface ( rtext );
1214 } // r_detail && selected?
1222 if ( render_jobs_b & R_BG ) {
1223 static int last_battlevel = 0;
1224 static unsigned char batterylevel = 0;
1225 char buffer [ 100 ];
1227 if ( time ( NULL ) - last_battlevel > 60 ) {
1228 batterylevel = pnd_device_get_battery_gauge_perc();
1229 last_battlevel = time ( NULL );
1232 sprintf ( buffer, "Battery: %u%%", batterylevel );
1235 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1236 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.battery_x", 20 );
1237 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
1238 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1239 SDL_FreeSurface ( rtext );
1244 if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
1246 unsigned int hintx, hinty;
1247 hintx = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
1248 hinty = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
1249 static unsigned int lastwidth = 3000;
1251 if ( ui_selected && ui_selected -> ref -> info_filename ) {
1252 buffer = "Documentation - hit Y";
1254 buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
1258 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1261 if ( ! ( render_jobs_b & R_BG ) ) {
1268 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, &src, sdl_realscreen, dest );
1270 lastwidth = rtext -> w;
1276 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1277 SDL_FreeSurface ( rtext );
1282 if ( render_jobs_b & R_BG &&
1283 pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 )
1287 time_t t = time ( NULL );
1288 struct tm *tm = localtime ( &t );
1289 strftime ( buffer, 50, "%a %H:%M %F", tm );
1292 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1293 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.clock_x", 700 );
1294 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.clock_y", 450 );
1295 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1296 SDL_FreeSurface ( rtext );
1300 // update all the rects and send it all to sdl
1301 // - at this point, we could probably just do 1 rect, of the
1302 // whole screen, and be faster :/
1303 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1307 void ui_process_input ( pnd_dbusnotify_handle dbh, pnd_notify_handle nh ) {
1310 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
1311 //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
1313 while ( ( ! ui_event ) &&
1314 /*block_p ?*/ SDL_WaitEvent ( &event ) /*: SDL_PollEvent ( &event )*/ )
1317 switch ( event.type ) {
1322 // the user-defined SDL events are all for threaded/delayed previews (and icons, which
1323 // generally are not used); if we're in wide mode, we can skip previews
1324 // to avoid slowing things down when they're not shown.
1326 if ( event.user.code == sdl_user_ticker ) {
1328 if ( ui_detail_hidden ) {
1329 break; // skip building previews when not showing them
1332 // timer went off, time to load something
1333 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1335 if ( ! ui_selected ) {
1339 // load the preview pics now!
1340 pnd_disco_t *iter = ui_selected -> ref;
1342 if ( iter -> preview_pic1 ) {
1344 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.threaded_preview", 0 ) ) {
1345 // load in bg thread, make user experience chuggy
1347 g_preview_thread = SDL_CreateThread ( (void*)ui_threaded_defered_preview, iter );
1349 if ( ! g_preview_thread ) {
1350 pnd_log ( pndn_error, "ERROR: Couldn't create preview thread\n" );
1354 // load it now, make user wait
1356 if ( ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
1357 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
1360 pnd_log ( pndn_debug, " Couldn't load preview pic: '%s' -> '%s'\n",
1361 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1366 } // got a preview at all?
1371 } else if ( event.user.code == sdl_user_finishedpreview ) {
1373 // if we just finished the one we happen to be looking at, better redraw now; otherwise, if
1374 // we finished another, no big woop
1375 if ( ui_selected && event.user.data1 == ui_selected -> ref ) {
1379 } else if ( event.user.code == sdl_user_finishedicon ) {
1380 // redraw, so we can show the newly loaded icon
1383 } else if ( event.user.code == sdl_user_checksd ) {
1384 // check if any inotify-type events occured, forcing us to rescan/re-disco the SDs
1386 unsigned char watch_dbus = 0;
1387 unsigned char watch_inotify = 0;
1390 watch_dbus = pnd_dbusnotify_rediscover_p ( dbh );
1394 watch_inotify = pnd_notify_rediscover_p ( nh );
1397 if ( watch_dbus || watch_inotify ) {
1398 pnd_log ( pndn_debug, "dbusnotify detected SD event\n" );
1399 applications_free();
1400 applications_scan();
1407 render_mask |= CHANGED_EVERYTHING;
1411 #if 0 // joystick motion
1412 case SDL_JOYAXISMOTION:
1414 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
1416 if ( event.jaxis.axis == 0 ) {
1418 if ( event.jaxis.value < 0 ) {
1420 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
1421 } else if ( event.jaxis.value > 0 ) {
1422 ui_push_right ( 0 );
1423 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
1425 } else if ( event.jaxis.axis == 1 ) {
1427 if ( event.jaxis.value < 0 ) {
1429 } else if ( event.jaxis.value > 0 ) {
1439 #if 0 // joystick buttons
1440 case SDL_JOYBUTTONDOWN:
1442 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
1444 if ( event.jbutton.button == 0 ) { // B
1446 } else if ( event.jbutton.button == 1 ) { // Y
1448 } else if ( event.jbutton.button == 2 ) { // X
1450 } else if ( event.jbutton.button == 3 ) { // A
1453 } else if ( event.jbutton.button == 4 ) { // Select
1454 ui_mask |= uisb_select;
1455 } else if ( event.jbutton.button == 5 ) { // Start
1456 ui_mask |= uisb_start;
1458 } else if ( event.jbutton.button == 7 ) { // L
1460 } else if ( event.jbutton.button == 8 ) { // R
1469 case SDL_JOYBUTTONUP:
1471 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
1473 if ( event.jbutton.button == 0 ) { // B
1476 } else if ( event.jbutton.button == 1 ) { // Y
1478 } else if ( event.jbutton.button == 2 ) { // X
1480 } else if ( event.jbutton.button == 3 ) { // A
1483 } else if ( event.jbutton.button == 4 ) { // Select
1484 ui_mask &= ~uisb_select;
1485 } else if ( event.jbutton.button == 5 ) { // Start
1486 ui_mask &= ~uisb_start;
1488 } else if ( event.jbutton.button == 7 ) { // L
1491 } else if ( event.jbutton.button == 8 ) { // R
1502 #if 1 // keyboard events
1506 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
1508 // SDLK_LALT -> Start
1509 // page up/down for y/x
1510 // home/end for a and b
1513 if ( event.key.keysym.sym == SDLK_RIGHT ) {
1514 ui_push_right ( 0 );
1516 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
1519 } else if ( event.key.keysym.sym == SDLK_UP ) {
1522 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1525 } else if ( event.key.keysym.sym == SDLK_END ) { // B
1528 } else if ( event.key.keysym.sym == SDLK_SPACE ) { // space
1529 if ( ui_selected ) {
1530 ui_menu_context ( ui_selected );
1532 // TBD: post an error?
1534 render_mask |= CHANGED_EVERYTHING;
1536 } else if ( event.key.keysym.sym == SDLK_TAB || event.key.keysym.sym == SDLK_HOME ) { // tab or A
1537 // if detail panel is togglable, then toggle it
1538 // if not, make sure its ruddy well shown!
1539 if ( ui_is_detail_hideable() ) {
1540 ui_toggle_detail_pane();
1542 ui_detail_hidden = 0;
1545 } else if ( event.key.keysym.sym == SDLK_RSHIFT || event.key.keysym.sym == SDLK_COMMA ) { // left trigger or comma
1548 } else if ( event.key.keysym.sym == SDLK_RCTRL || event.key.keysym.sym == SDLK_PERIOD ) { // right trigger or period
1552 } else if ( event.key.keysym.sym == SDLK_PAGEUP ) { // Y
1554 if ( ui_selected ) {
1555 ui_show_info ( pnd_run_script, ui_selected -> ref );
1558 } else if ( event.key.keysym.sym == SDLK_PAGEDOWN ) { // X
1561 // forget the selection, nolonger applies
1563 ui_set_selected ( ui_selected );
1565 if ( g_categories [ ui_category ] -> fspath ) {
1566 category_fs_restock ( g_categories [ ui_category ] );
1569 render_mask |= CHANGED_EVERYTHING;
1572 } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
1576 } else if ( event.key.keysym.sym == SDLK_LCTRL /*LALT*/ ) { // select button
1577 char *opts [ 20 ] = {
1578 "Reveal hidden category",
1580 "Configure Minimenu",
1581 "Manage custom app categories",
1582 "Rescan for applications",
1583 "Cache previews to SD now",
1584 "Run a terminal/console",
1585 "Run another GUI (xfce, etc)",
1587 "Select a Minimenu skin",
1590 int sel = ui_modal_single_menu ( opts, 11, "Minimenu", "Enter to select; other to return." );
1592 char buffer [ 100 ];
1596 } else if ( sel == 1 ) {
1597 // store conf on exit, so that last app/cat can be cached.. for ED :)
1598 conf_write ( g_conf, conf_determine_location ( g_conf ) );
1600 sprintf ( buffer, "sudo poweroff" );
1602 } else if ( sel == 2 ) {
1604 unsigned char restart = conf_run_menu ( NULL );
1605 conf_write ( g_conf, conf_determine_location ( g_conf ) );
1606 conf_write ( g_conf, CONF_PREF_TEMPPATH );
1608 emit_and_quit ( MM_RESTART );
1610 } else if ( sel == 3 ) {
1611 // manage custom categories
1612 ui_manage_categories();
1613 } else if ( sel == 4 ) {
1615 pnd_log ( pndn_debug, "Freeing up applications\n" );
1616 applications_free();
1617 pnd_log ( pndn_debug, "Rescanning applications\n" );
1618 applications_scan();
1619 } else if ( sel == 5 ) {
1620 // cache preview to SD now
1621 extern pnd_box_handle g_active_apps;
1622 pnd_box_handle h = g_active_apps;
1624 unsigned int maxwidth, maxheight;
1625 maxwidth = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 );
1626 maxheight = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 );
1628 pnd_disco_t *iter = pnd_box_get_head ( h );
1633 if ( ! cache_preview ( iter, maxwidth, maxheight ) ) {
1634 pnd_log ( pndn_debug, "Force cache: Couldn't load preview pic: '%s' -> '%s'\n",
1635 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1639 iter = pnd_box_get_next ( iter );
1642 } else if ( sel == 6 ) {
1645 argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
1649 ui_forkexec ( argv );
1652 } else if ( sel == 7 ) {
1653 char buffer [ PATH_MAX ];
1654 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/pandora/scripts/op_switchgui.sh" );
1655 emit_and_quit ( buffer );
1656 } else if ( sel == 8 ) {
1657 emit_and_quit ( MM_QUIT );
1658 } else if ( sel == 9 ) {
1660 if ( ui_pick_skin() ) {
1661 emit_and_quit ( MM_RESTART );
1663 } else if ( sel == 10 ) {
1665 char buffer [ PATH_MAX ];
1666 sprintf ( buffer, "%s/about.txt", g_skinpath );
1667 ui_aboutscreen ( buffer );
1671 render_mask |= CHANGED_EVERYTHING;
1674 // unknown SDLK_ keycode?
1676 // many SDLK_keycodes map to ASCII ("a" is ascii(a)), so try to jump to a filename of that name, in this category?
1677 // and if already there, try to jump to next, maybe?
1678 // future: look for sequence typing? ie: user types 'm' then 'a', look for 'ma*' instead of 'm' then 'a' matching
1679 if ( isalpha ( event.key.keysym.sym ) && g_categories [ ui_category ] -> refcount > 0 ) {
1680 mm_appref_t *app = g_categories [ ui_category ] -> refs;
1682 //fprintf ( stderr, "sel %s next %s\n", ui_selected -> ref -> title_en, ui_selected -> next -> ref -> title_en );
1684 // are we already matching the same char? and next item is also same char?
1685 if ( app && ui_selected && ui_selected -> next &&
1686 ui_selected -> ref -> title_en && ui_selected -> next -> ref -> title_en &&
1687 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( ui_selected -> next -> ref -> title_en [ 0 ] ) &&
1688 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym )
1691 // just skip down one
1692 app = ui_selected -> next;
1695 // walk the category, looking for a first-char match
1697 if ( app -> ref -> title_en && toupper ( app -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym ) ) {
1703 } // same start letter, or new run?
1705 // found something, or no?
1707 // looks like we found a potential match; try switching it to visible selection
1709 ui_set_selected ( ui_selected );
1714 } // SDLK_alphanumeric?
1720 if ( event.key.keysym.sym == SDLK_ESCAPE ) {
1721 emit_and_quit ( MM_QUIT );
1728 #if 1 // mouse / touchscreen
1730 case SDL_MOUSEBUTTONDOWN:
1731 if ( event.button.button == SDL_BUTTON_LEFT ) {
1732 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
1738 case SDL_MOUSEBUTTONUP:
1739 if ( event.button.button == SDL_BUTTON_LEFT ) {
1740 ui_touch_act ( event.button.x, event.button.y );
1753 } // switch event type
1760 void ui_push_left ( unsigned char forcecoil ) {
1762 if ( ui_viewmode == uiv_list ) {
1763 ui_context_t *c = &ui_display_context;
1765 int imax = ( c -> cell_height * c -> row_max ) / ( c -> text_height + c -> icon_offset_y ); // visible rows
1766 for ( i = 0; i < imax; i++ ) {
1772 if ( ! ui_selected ) {
1773 ui_push_right ( 0 );
1777 // what column we in?
1778 unsigned int col = ui_determine_screen_col ( ui_selected );
1780 // are we already at first item?
1781 if ( forcecoil == 0 &&
1782 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1785 unsigned int i = ui_display_context.col_max - 1;
1786 while ( i && ui_selected -> next ) {
1787 ui_push_right ( 0 );
1791 } else if ( g_categories [ ui_category ] -> refs == ui_selected ) {
1792 // can't go any more left, we're at the head
1795 // figure out the previous item; yay for singly linked list :/
1796 mm_appref_t *i = g_categories [ ui_category ] -> refs;
1798 if ( i -> next == ui_selected ) {
1806 ui_set_selected ( ui_selected );
1811 void ui_push_right ( unsigned char forcecoil ) {
1813 if ( ui_viewmode == uiv_list ) {
1814 ui_context_t *c = &ui_display_context;
1816 int imax = ( c -> cell_height * c -> row_max ) / ( c -> text_height + c -> icon_offset_y ); // visible rows
1817 for ( i = 0; i < imax; i++ ) {
1823 if ( ui_selected ) {
1825 // what column we in?
1826 unsigned int col = ui_determine_screen_col ( ui_selected );
1829 if ( forcecoil == 0 &&
1830 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1831 // and selected is far-right, or last icon in category (might not be far right)
1832 ( ( col == ui_display_context.col_max - 1 ) ||
1833 ( ui_selected -> next == NULL ) )
1837 //unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1838 while ( col /*i*/ ) {
1844 // just go to the next
1846 if ( ui_selected -> next ) {
1847 ui_selected = ui_selected -> next;
1853 ui_selected = g_categories [ ui_category ] -> refs;
1856 ui_set_selected ( ui_selected );
1861 void ui_push_up ( void ) {
1863 unsigned char col_max = ui_display_context.col_max;
1865 // not selected? well, no where to go..
1866 if ( ! ui_selected ) {
1870 if ( ui_viewmode == uiv_list ) {
1872 if ( g_categories [ ui_category ] -> refs == ui_selected ) {
1873 // can't go any more up, we're at the head
1876 // figure out the previous item; yay for singly linked list :/
1877 mm_appref_t *i = g_categories [ ui_category ] -> refs;
1879 if ( i -> next == ui_selected ) {
1888 // for list view.. we're done
1889 ui_set_selected ( ui_selected );
1894 unsigned int row = ui_determine_row ( ui_selected );
1897 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 0 ) == 0 )
1899 // wrap around instead
1901 unsigned int col = ui_determine_screen_col ( ui_selected );
1904 ui_selected = g_categories [ ui_category ] -> refs;
1905 while ( ui_selected -> next ) {
1906 ui_selected = ui_selected -> next;
1909 // try to move to same column
1910 unsigned int newcol = ui_determine_screen_col ( ui_selected );
1911 if ( newcol > col ) {
1919 // scroll down to show it
1920 int r = ui_determine_row ( ui_selected ) - 1;
1921 if ( r - ui_display_context.row_max > 0 ) {
1922 ui_rows_scrolled_down = (unsigned int) r;
1926 // stop at top/bottom
1938 void ui_push_down ( void ) {
1940 if ( ui_viewmode == uiv_list ) {
1942 if ( ui_selected ) {
1944 if ( ui_selected -> next ) {
1945 ui_selected = ui_selected -> next;
1949 ui_selected = g_categories [ ui_category ] -> refs; // frist!
1952 // list view? we're done.
1953 ui_set_selected ( ui_selected );
1957 unsigned char col_max = ui_display_context.col_max;
1959 if ( ui_selected ) {
1962 unsigned int row = ui_determine_row ( ui_selected );
1965 unsigned int icon_rows = g_categories [ ui_category ] -> refcount / col_max;
1966 if ( g_categories [ ui_category ] -> refcount % col_max > 0 ) {
1971 if ( row == ( icon_rows - 1 ) &&
1972 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 0 ) == 0 )
1975 unsigned char col = ui_determine_screen_col ( ui_selected );
1977 ui_selected = g_categories [ ui_category ] -> refs;
1980 ui_selected = ui_selected -> next;
1984 ui_rows_scrolled_down = 0;
1986 render_mask |= CHANGED_EVERYTHING;
1991 ui_push_right ( 1 );
1998 ui_push_right ( 0 );
2004 // 'backup' is currently 'X', for going back up in a folder/subcat without having to hit exec on the '..' entry
2005 void ui_push_backup ( void ) {
2007 // a subcat-as-dir, or a dir browser?
2008 if ( g_categories [ ui_category] -> fspath ) {
2009 // dir browser, just climb our way back up
2014 // lop off last word; if the thing ends with /, lop that one, then the next word.
2015 while ( ( c = strrchr ( g_categories [ ui_category] -> fspath, '/' ) ) ) {
2016 *c = '\0'; // lop off the last hunk
2017 if ( *(c+1) != '\0' ) {
2023 if ( g_categories [ ui_category] -> fspath [ 0 ] == '\0' ) {
2024 free ( g_categories [ ui_category] -> fspath );
2025 g_categories [ ui_category] -> fspath = strdup ( "/" );
2029 // a pnd subcat .. are we in one, or at the 'top'?
2030 char *pcatname = g_categories [ ui_category ] -> parent_catname;
2033 return; // we're at the 'top' already
2036 // set to first cat!
2039 // republish cats .. shoudl just be the one
2040 category_publish ( CFNORMAL, NULL );
2043 ui_category = category_index ( pcatname );
2045 // ensure tab visible?
2046 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2047 if ( ui_category > ui_catshift + ( ui_display_context.screen_width / tab_width ) - 1 ) {
2048 ui_catshift = ui_category - ( ui_display_context.screen_width / tab_width ) + 1;
2058 void ui_push_exec ( void ) {
2060 if ( ! ui_selected ) {
2064 // cache the category/app so we can come back to it another time
2065 if ( ui_selected ) {
2066 pnd_conf_set_char ( g_conf, "minimenu.last_known_app_uid", ui_selected -> ref -> unique_id );
2068 if ( g_categories [ 0 ] ) {
2069 pnd_conf_set_char ( g_conf, "minimenu.last_known_catname", g_categories [ ui_category ] -> catname );
2071 // and also the parent cat..
2072 if ( g_categories [ ui_category ] -> parent_catname ) {
2073 pnd_conf_set_char ( g_conf, "minimenu.last_known_parentcatname", g_categories [ ui_category ] -> parent_catname );
2075 char *kv = pnd_box_find_by_key ( g_conf, "minimenu.last_known_parentcatname" );
2077 pnd_box_delete_node ( g_conf, kv );
2083 // cache last known cat/app to /tmp, so we can use it again later
2084 conf_write ( g_conf, CONF_PREF_TEMPPATH );
2086 // was this icon generated from filesystem, or from pnd-file?
2087 if ( ui_selected -> ref -> object_flags & PND_DISCO_GENERATED ) {
2089 if ( ! ui_selected -> ref -> title_en ) {
2090 return; // no filename
2093 if ( ui_selected -> ref -> object_type == pnd_object_type_directory ) {
2095 // check if this guy is a dir-browser tab, or is a directory on a pnd tab
2096 if ( ! g_categories [ ui_category] -> fspath ) {
2097 // pnd subcat as dir
2099 // are we already in a subcat? if so, go back to parent; there is no grandparenting or deeper
2100 if ( g_categories [ ui_category ] -> parent_catname ) {
2105 // delve into subcat
2107 // set to first cat!
2111 // republish cats .. shoudl just be the one
2112 category_publish ( CFBYNAME, ui_selected -> ref -> object_path );
2116 // forget the selection, nolonger applies
2118 ui_set_selected ( ui_selected );
2120 render_mask |= CHANGED_EVERYTHING;
2124 // delve up/down the dir tree
2125 if ( strcmp ( ui_selected -> ref -> title_en, ".." ) == 0 ) {
2130 char *temp = malloc ( strlen ( g_categories [ ui_category] -> fspath ) + strlen ( ui_selected -> ref -> title_en ) + 1 + 1 );
2131 sprintf ( temp, "%s/%s", g_categories [ ui_category] -> fspath, ui_selected -> ref -> title_en );
2132 free ( g_categories [ ui_category] -> fspath );
2133 g_categories [ ui_category] -> fspath = temp;
2136 pnd_log ( pndn_debug, "Cat %s is now in path %s\n", g_categories [ ui_category ] -> catname, g_categories [ ui_category ]-> fspath );
2138 // forget the selection, nolonger applies
2140 ui_set_selected ( ui_selected );
2142 category_fs_restock ( g_categories [ ui_category ] );
2144 render_mask |= CHANGED_SELECTION;
2146 } // directory browser or pnd subcat?
2149 // just run it arbitrarily?
2151 // if this a pnd-file, or just some executable?
2152 if ( strcasestr ( ui_selected -> ref -> object_filename, PND_PACKAGE_FILEEXT ) ) {
2153 // looks like a pnd, now what do we do..
2154 pnd_box_handle h = pnd_disco_file ( ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
2157 pnd_disco_t *d = pnd_box_get_head ( h );
2158 pnd_apps_exec_disco ( pnd_run_script, d, PND_EXEC_OPTION_NORUN, NULL );
2159 char buffer [ PATH_MAX ];
2160 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
2161 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
2162 emit_and_quit ( buffer );
2164 emit_and_run ( buffer );
2171 // is it even executable? if we don't have handlers for non-executables yet (Jan 2011 we don't),
2172 // then don't even try to run things not-flagged as executable.. but wait most people are on
2173 // FAT filesystems, what a drag, we can't tell at the fs level.
2174 // ... but we can still invoke 'file' and grep out the good bits, at least.
2176 // open a stream reading 'file /path/to/file' and check output for 'executable'
2177 // -- not checking for "ARM" so it can pick up x86 (or whatever native) executables in build environment
2178 unsigned char is_executable = 0;
2182 char popenbuf [ FILENAME_MAX ];
2183 snprintf ( popenbuf, FILENAME_MAX, "%s %s/%s", MIMETYPE_EXE, g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
2186 if ( ! ( marceau = popen ( popenbuf, "r" ) ) ) {
2187 return; // error, we need some useful error handling and dialog boxes here
2190 if ( fgets ( popenbuf, FILENAME_MAX, marceau ) ) {
2191 //printf ( "File test returns: %s\n", popenbuf );
2192 if ( strstr ( popenbuf, "executable" ) != NULL ) {
2201 if ( ! is_executable ) {
2202 fprintf ( stderr, "ERROR: File to invoke is not executable, skipping. (%s)\n", ui_selected -> ref -> title_en );
2203 return; // need some error handling here
2206 #if 0 // eat up any pending SDL events and toss 'em?
2210 while ( SDL_PeepEvents ( &e, 1, SDL_GETEVENT, SDL_ALLEVENTS ) > 0 ) {
2220 // get CWD so we can restore it on return
2221 char cwd [ PATH_MAX ];
2222 getcwd ( cwd, PATH_MAX );
2224 // full path to executable so we don't rely on implicit "./"
2225 char execbuf [ FILENAME_MAX ];
2226 snprintf ( execbuf, FILENAME_MAX, "%s/%s", g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
2229 chdir ( g_categories [ ui_category ] -> fspath );
2230 exec_raw_binary ( execbuf /*ui_selected -> ref -> title_en*/ );
2233 // DEPRECATED / NOT TESTED
2234 // get mmwrapper to run it
2235 char buffer [ PATH_MAX ];
2236 sprintf ( buffer, "%s %s/%s\n", MM_RUN, g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
2237 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
2238 emit_and_quit ( buffer );
2240 emit_and_run ( buffer );
2249 // set app-run speed
2250 int use_run_speed = pnd_conf_get_as_int_d ( g_conf, "minimenu.use_run_speed", 0 );
2251 if ( use_run_speed > 0 ) {
2252 int mm_speed = pnd_conf_get_as_int_d ( g_conf, "minimenu.run_speed", -1 );
2253 if ( mm_speed > -1 ) {
2254 char buffer [ 512 ];
2255 snprintf ( buffer, 500, "sudo /usr/pandora/scripts/op_cpuspeed.sh %d", mm_speed );
2258 } // do speed change?
2260 // request app to run and quit mmenu
2261 pnd_apps_exec_disco ( pnd_run_script, ui_selected -> ref, PND_EXEC_OPTION_NORUN, NULL );
2262 char buffer [ PATH_MAX ];
2263 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
2264 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
2265 emit_and_quit ( buffer );
2267 emit_and_run ( buffer );
2274 void ui_push_ltrigger ( void ) {
2275 unsigned char oldcat = ui_category;
2276 unsigned int screen_width = ui_display_context.screen_width;
2277 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2279 if ( g_categorycount == 0 ) {
2283 if ( g_icon_thread_busy ) {
2284 ui_stop_defered_icon_thread();
2287 if ( ui_category > 0 ) {
2289 category_fs_restock ( g_categories [ ui_category ] );
2291 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
2292 ui_category = g_categorycount - 1;
2294 if ( ui_category >= ( screen_width / tab_width ) ) {
2295 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
2297 category_fs_restock ( g_categories [ ui_category ] );
2301 if ( oldcat != ui_category ) {
2303 ui_set_selected ( ui_selected );
2306 // make tab visible?
2307 if ( ui_catshift > 0 && ui_category == ui_catshift - 1 ) {
2312 ui_rows_scrolled_down = 0;
2314 render_mask |= CHANGED_CATEGORY;
2315 ui_start_defered_icon_thread();
2320 void ui_push_rtrigger ( void ) {
2321 unsigned char oldcat = ui_category;
2323 if ( g_categorycount == 0 ) {
2327 if ( g_icon_thread_busy ) {
2328 ui_stop_defered_icon_thread();
2331 unsigned int screen_width = ui_display_context.screen_width;
2332 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2334 if ( ui_category < ( g_categorycount - 1 ) ) {
2336 category_fs_restock ( g_categories [ ui_category ] );
2338 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
2341 category_fs_restock ( g_categories [ ui_category ] );
2345 if ( oldcat != ui_category ) {
2347 ui_set_selected ( ui_selected );
2350 // make tab visible?
2351 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2356 ui_rows_scrolled_down = 0;
2358 render_mask |= CHANGED_CATEGORY;
2359 ui_start_defered_icon_thread();
2364 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
2365 double scale = 1000000.0;
2366 double scalex = 1000000.0;
2367 double scaley = 1000000.0;
2368 SDL_Surface *scaled;
2370 scalex = (double)maxwidth / (double)s -> w;
2372 if ( maxheight == -1 ) {
2375 scaley = (double)maxheight / (double)s -> h;
2377 if ( scaley < scalex ) {
2385 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
2386 SDL_FreeSurface ( s );
2392 void ui_loadscreen ( void ) {
2397 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2401 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", ui_display_context.fontcolor );
2404 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
2405 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2406 SDL_FreeSurface ( rtext );
2411 void ui_discoverscreen ( unsigned char clearscreen ) {
2416 if ( clearscreen ) {
2417 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2419 // render background
2420 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2423 dest.w = sdl_realscreen -> w;
2424 dest.h = sdl_realscreen -> h;
2425 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
2426 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2433 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", ui_display_context.fontcolor );
2434 if ( clearscreen ) {
2441 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
2442 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2443 SDL_FreeSurface ( rtext );
2446 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
2447 dest.x = rtext -> w + 30;
2449 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
2450 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2456 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
2458 SDL_Rect rects [ 4 ];
2459 SDL_Rect *dest = rects;
2461 bzero ( dest, sizeof(SDL_Rect)* 4 );
2463 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
2464 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
2465 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
2466 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
2468 static unsigned int stepx = 0;
2471 if ( clearscreen ) {
2472 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2474 // render background
2475 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2478 dest -> w = sdl_realscreen -> w;
2479 dest -> h = sdl_realscreen -> h;
2480 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
2486 // render background
2487 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2490 src.w = sdl_realscreen -> w;
2494 dest -> w = sdl_realscreen -> w;
2495 dest -> h = sdl_realscreen -> h;
2496 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
2504 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
2505 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
2508 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2509 SDL_FreeSurface ( rtext );
2513 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
2514 dest -> x = rtext -> w + 30 + stepx;
2516 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
2522 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
2525 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2526 SDL_FreeSurface ( rtext );
2533 if ( stepx > 350 ) {
2537 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
2542 int ui_selected_index ( void ) {
2544 if ( ! ui_selected ) {
2545 return ( -1 ); // no index
2548 mm_appref_t *r = g_categories [ ui_category ] -> refs;
2551 if ( r == ui_selected ) {
2561 static mm_appref_t *timer_ref = NULL;
2562 void ui_set_selected ( mm_appref_t *r ) {
2564 render_mask |= CHANGED_SELECTION;
2566 // preview pic stuff
2569 if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
2570 return; // no desire to defer anything
2575 SDL_SetTimer ( 0, NULL );
2580 SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
2586 unsigned int ui_callback_f ( unsigned int t ) {
2588 if ( ui_selected != timer_ref ) {
2589 return ( 0 ); // user has moved it, who cares
2593 bzero ( &e, sizeof(SDL_Event) );
2594 e.type = SDL_USEREVENT;
2595 e.user.code = sdl_user_ticker;
2596 SDL_PushEvent ( &e );
2601 int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
2602 SDL_Rect rects [ 40 ];
2603 SDL_Rect *dest = rects;
2606 unsigned char max_visible = pnd_conf_get_as_int_d ( g_conf, "detailtext.max_visible" , 11 );
2607 unsigned char first_visible = 0;
2609 bzero ( rects, sizeof(SDL_Rect) * 40 );
2611 unsigned int sel = 0;
2613 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 };
2621 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2622 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2623 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
2624 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
2625 SDL_FillRect( sdl_realscreen, dest, 0 );
2627 // show dialog background
2628 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
2631 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> w;
2632 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> h;
2633 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2634 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2635 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2636 // repeat for darken?
2637 //SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2638 //SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2639 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2643 // show dialog frame
2644 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
2645 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2646 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2647 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
2648 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2654 rtext = TTF_RenderText_Blended ( g_tab_font, title, ui_display_context.fontcolor );
2655 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2656 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
2657 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2658 SDL_FreeSurface ( rtext );
2664 rtext = TTF_RenderText_Blended ( g_tab_font, footer, ui_display_context.fontcolor );
2665 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2666 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
2667 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
2669 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2670 SDL_FreeSurface ( rtext );
2675 for ( i = first_visible; i < first_visible + max_visible && i < argc; i++ ) {
2679 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
2681 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], ui_display_context.fontcolor );
2683 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2684 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 - first_visible ) );
2685 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2686 SDL_FreeSurface ( rtext );
2691 // update all the rects and send it all to sdl
2692 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
2696 while ( SDL_WaitEvent ( &event ) ) {
2698 switch ( event.type ) {
2703 if ( event.key.keysym.sym == SDLK_UP ) {
2707 if ( sel < first_visible ) {
2712 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
2714 if ( sel < argc - 1 ) {
2717 // ensure visibility
2718 if ( sel >= first_visible + max_visible ) {
2724 } else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_END ) { // return, or "B"
2728 } else if ( event.key.keysym.sym == SDLK_q ) {
2733 return ( -1 ); // nada
2748 unsigned char ui_determine_row ( mm_appref_t *a ) {
2749 unsigned int row = 0;
2751 mm_appref_t *i = g_categories [ ui_category ] -> refs;
2756 row /= ui_display_context.col_max;
2761 unsigned char ui_determine_screen_row ( mm_appref_t *a ) {
2762 return ( ui_determine_row ( a ) % ui_display_context.row_max );
2765 unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
2766 unsigned int col = 0;
2768 mm_appref_t *i = g_categories [ ui_category ] -> refs;
2773 col %= ui_display_context.col_max;
2778 unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ) {
2779 char *viewer, *searchpath;
2780 pnd_conf_handle desktoph;
2783 searchpath = pnd_conf_query_searchpath();
2785 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
2791 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
2794 return ( 0 ); // no way to view the file
2798 if ( ! p -> unique_id ) {
2802 if ( ! p -> info_filename ) {
2806 if ( ! p -> info_name ) {
2817 if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
2818 snprintf ( pargs, 1001, "%s %s",
2819 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
2824 char pndfile [ 1024 ];
2825 if ( p -> object_type == pnd_object_type_directory ) {
2826 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
2827 strncpy ( pndfile, p -> object_path, 1000 );
2828 } else if ( p -> object_type == pnd_object_type_pnd ) {
2829 // pnd_run.sh wants the full path and filename for the .pnd file
2830 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
2833 if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
2834 p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
2839 pnd_log ( pndn_debug, "Info Exec=%s\n", pnd_apps_exec_runline() );
2843 if ( ( x = fork() ) < 0 ) {
2844 pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
2849 execl ( "/bin/sh", "/bin/sh", "-c", pnd_apps_exec_runline(), (char*)NULL );
2850 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", pnd_apps_exec_runline() );
2862 #define MAXTOUCH 100
2863 ui_touch_t ui_touchrects [ MAXTOUCH ];
2864 unsigned char ui_touchrect_count = 0;
2866 void ui_register_reset ( void ) {
2867 bzero ( ui_touchrects, sizeof(ui_touch_t)*MAXTOUCH );
2868 ui_touchrect_count = 0;
2872 void ui_register_tab ( unsigned char catnum, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2874 if ( ui_touchrect_count == MAXTOUCH ) {
2878 ui_touchrects [ ui_touchrect_count ].r.x = x;
2879 ui_touchrects [ ui_touchrect_count ].r.y = y;
2880 ui_touchrects [ ui_touchrect_count ].r.w = w;
2881 ui_touchrects [ ui_touchrect_count ].r.h = h;
2882 ui_touchrects [ ui_touchrect_count ].catnum = catnum;
2883 ui_touchrect_count++;
2888 void ui_register_app ( mm_appref_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2890 if ( ui_touchrect_count == MAXTOUCH ) {
2894 ui_touchrects [ ui_touchrect_count ].r.x = x;
2895 ui_touchrects [ ui_touchrect_count ].r.y = y;
2896 ui_touchrects [ ui_touchrect_count ].r.w = w;
2897 ui_touchrects [ ui_touchrect_count ].r.h = h;
2898 ui_touchrects [ ui_touchrect_count ].ref = app;
2899 ui_touchrect_count++;
2904 void ui_touch_act ( unsigned int x, unsigned int y ) {
2909 for ( i = 0; i < ui_touchrect_count; i++ ) {
2910 t = &(ui_touchrects [ i ]);
2912 if ( x >= t -> r.x &&
2913 x <= t -> r.x + t -> r.w &&
2915 y <= t -> r.y + t -> r.h
2920 ui_selected = t -> ref;
2923 if ( ui_category != t -> catnum ) {
2926 ui_category = t -> catnum;
2927 render_mask |= CHANGED_CATEGORY;
2929 category_fs_restock ( g_categories [ ui_category ] );
2930 ui_start_defered_icon_thread();
2941 unsigned char ui_forkexec ( char *argv[] ) {
2942 char *fooby = argv[0];
2945 if ( ( x = fork() ) < 0 ) {
2946 pnd_log ( pndn_error, "ERROR: Couldn't fork() for '%s'\n", fooby );
2950 if ( x == 0 ) { // child
2951 execv ( fooby, argv );
2952 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", fooby );
2960 unsigned char ui_threaded_timer_create ( void ) {
2962 g_timer_thread = SDL_CreateThread ( (void*)ui_threaded_timer, NULL );
2964 if ( ! g_timer_thread ) {
2965 pnd_log ( pndn_error, "ERROR: Couldn't create timer thread\n" );
2972 int ui_threaded_timer ( pnd_disco_t *p ) {
2974 // this timer's job is to ..
2975 // - do nothing for quite awhile
2976 // - on wake, post event to SDL event queue, so that main thread will check if SD insert/eject occurred
2979 unsigned int delay_s = 2; // seconds
2984 //sleep ( delay_s );
2985 SDL_Delay ( delay_s * 1000 );
2987 // .. trigger SD check
2989 bzero ( &e, sizeof(SDL_Event) );
2990 e.type = SDL_USEREVENT;
2991 e.user.code = sdl_user_checksd;
2992 SDL_PushEvent ( &e );
2999 unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
3001 if ( ! cache_preview ( p, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
3002 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
3005 pnd_log ( pndn_debug, "THREAD: Couldn't load preview pic: '%s' -> '%s'\n",
3006 IFNULL(p->title_en,"No Name"), p -> preview_pic1 );
3009 // trigger that we completed
3011 bzero ( &e, sizeof(SDL_Event) );
3012 e.type = SDL_USEREVENT;
3013 e.user.code = sdl_user_finishedpreview;
3015 SDL_PushEvent ( &e );
3020 void ui_post_scan ( void ) {
3024 ui_rows_scrolled_down = 0;
3025 // set back to first tab, to be safe
3029 // do we have a preferred category to jump to? or a last known one?
3030 char *dc = pnd_conf_get_as_char ( g_conf, "categories.default_cat" );
3031 char *lastcat = pnd_conf_get_as_char ( g_conf, "minimenu.last_known_catname" );
3033 ( pnd_conf_get_as_int_d ( g_conf, "minimenu.start_selected", 0 ) && lastcat ) )
3035 char *catpick = NULL;
3037 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.start_selected", 0 ) && lastcat ) {
3040 // if this is a subcat, we have some doctoring to do :/ the hackishness is really
3041 // starting to show..
3042 if ( pnd_conf_get_as_char ( g_conf, "minimenu.last_known_parentcatname" ) ) {
3043 // in subcat view, we only have one cat
3046 // the cat name to search for is Child*Parent
3048 sprintf ( key, "%s*%s",
3049 pnd_conf_get_as_char ( g_conf, "minimenu.last_known_catname" )
3050 , pnd_conf_get_as_char ( g_conf, "minimenu.last_known_parentcatname" ) );
3051 category_publish ( CFBYNAME, key );
3052 // since we forced it by hand, no need to do a cat-scan below
3060 // attempt to find default cat; if we do find it, select it; otherwise
3061 // default behaviour will pick first cat (ie: usually All)
3065 for ( i = 0; i < g_categorycount; i++ ) {
3066 if ( strcasecmp ( g_categories [ i ] -> catname, catpick ) == 0 ) {
3068 // ensure visibility
3069 unsigned int screen_width = ui_display_context.screen_width;
3070 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
3071 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
3072 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
3078 if ( i == g_categorycount ) {
3079 pnd_log ( pndn_warning, " User defined default category or last known cat '%s' but not found, so using default behaviour\n", catpick );
3086 // if we're sent right to a dirbrowser tab, restock it now (normally we restock on entry)
3087 if ( g_categories [ ui_category ] && g_categories [ ui_category ] -> fspath ) {
3088 printf ( "Restock on start: '%s'\n", g_categories [ ui_category ] -> fspath );
3089 category_fs_restock ( g_categories [ ui_category ] );
3093 render_mask |= CHANGED_EVERYTHING;
3095 // if deferred icon load, kick off the thread now
3096 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 1 ) {
3097 ui_start_defered_icon_thread();
3098 } // deferred icon load
3103 unsigned char ui_threaded_defered_icon ( void *p ) {
3104 extern pnd_box_handle g_active_apps;
3106 unsigned char maxwidth, maxheight;
3107 maxwidth = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 );
3108 maxheight = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_height", 50 );
3112 g_icon_thread_busy = 1;
3114 // work at it in order within current category
3116 mm_appref_t *refiter = g_categories [ ui_category ] ? g_categories [ ui_category ] -> refs : NULL;
3117 while ( refiter && ! g_icon_thread_stop ) {
3118 iter = refiter -> ref;
3120 // has an icon that is not already cached?
3121 if ( ( iter -> pnd_icon_pos ) ||
3122 ( iter -> icon && iter -> object_flags & PND_DISCO_LIBPND_DD )
3127 if ( ! cache_icon ( iter, maxwidth, maxheight ) ) {
3128 //pnd_log ( pndn_warning, " Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
3132 // trigger that we completed
3134 bzero ( &e, sizeof(SDL_Event) );
3135 e.type = SDL_USEREVENT;
3136 e.user.code = sdl_user_finishedicon;
3137 SDL_PushEvent ( &e );
3139 //pnd_log ( pndn_warning, " Finished deferred load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
3140 //usleep ( pnd_conf_get_as_int_d ( g_conf, "minimenu.defer_icon_us", 50000 ) );
3145 iter -> pnd_icon_pos = 0;
3146 if ( iter -> icon ) {
3147 free ( iter -> icon );
3148 iter -> icon = NULL;
3151 // let user do something..
3156 refiter = refiter -> next;
3160 g_icon_thread_busy = 0;
3165 void ui_show_hourglass ( unsigned char updaterect ) {
3168 SDL_Surface *s = g_imagecache [ IMG_HOURGLASS ].i;
3170 dest.x = ( 800 - s -> w ) / 2;
3171 dest.y = ( 480 - s -> h ) / 2;
3173 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, &dest );
3176 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
3182 unsigned char ui_pick_skin ( void ) {
3184 char *skins [ MAXSKINS ];
3187 char *searchpath = pnd_conf_get_as_char ( g_conf, "minimenu.skin_searchpath" );
3188 char tempname [ 100 ];
3192 skins [ iter++ ] = "No skin change";
3196 DIR *d = opendir ( buffer );
3201 while ( ( dd = readdir ( d ) ) ) {
3203 if ( dd -> d_name [ 0 ] == '.' ) {
3205 } else if ( ( dd -> d_type == DT_DIR || dd -> d_type == DT_UNKNOWN ) &&
3208 snprintf ( tempname, 100, "Skin: %s", dd -> d_name );
3209 skins [ iter++ ] = strdup ( tempname );
3220 int sel = ui_modal_single_menu ( skins, iter, "Skins", "Enter to select; other to return." );
3222 // did they pick one?
3226 char *s = strdup ( pnd_conf_get_as_char ( g_conf, "minimenu.skin_selected" ) );
3227 s = pnd_expand_tilde ( s );
3229 f = fopen ( s, "w" );
3234 fprintf ( f, "%s\n", skins [ sel ] + 6 );
3244 void ui_aboutscreen ( char *textpath ) {
3251 #define ROWS SCRH / ( PIXELH + MARGINH )
3252 #define COLS SCRW / ( PIXELW + MARGINW )
3254 unsigned char pixelboard [ ROWS * COLS ]; // pixel heat
3255 bzero ( pixelboard, ROWS * COLS );
3260 SDL_Color rtextc = { 200, 200, 200, 100 };
3263 char *textloop [ 500 ];
3264 unsigned int textmax = 0;
3265 bzero ( textloop, 500 * sizeof(char*) );
3268 char cbuffer [ 50000 ];
3269 bzero ( cbuffer, 50000 );
3270 unsigned int crevealed = 0;
3272 FILE *f = fopen ( textpath, "r" );
3275 pnd_log ( pndn_error, "ERROR: Couldn't open about text: %s\n", textpath );
3279 char textbuf [ 100 ];
3280 while ( fgets ( textbuf, 100, f ) ) {
3282 // add to full buffer
3283 strncat ( cbuffer, textbuf, 50000 );
3286 if ( strchr ( textbuf, '\n' ) ) {
3287 * strchr ( textbuf, '\n' ) = '\0';
3290 // add to pixel loop
3291 if ( 1||textbuf [ 0 ] ) {
3292 textloop [ textmax ] = strdup ( textbuf );
3300 unsigned int textiter = 0;
3301 while ( textiter < textmax ) {
3302 char *text = textloop [ textiter ];
3306 // render to surface
3307 rtext = TTF_RenderText_Blended ( g_grid_font, text, rtextc );
3309 // render font to pixelboard
3310 unsigned int px, py;
3312 unsigned int *pixels = rtext -> pixels;
3313 unsigned char cr, cg, cb, ca;
3314 for ( py = 0; py < rtext -> h; py ++ ) {
3315 for ( px = 0; px < ( rtext -> w > COLS ? COLS : rtext -> w ); px++ ) {
3317 SDL_GetRGBA ( pixels [ ( py * rtext -> pitch / 4 ) + px ],
3318 rtext -> format, &cr, &cg, &cb, &ca );
3322 ph = pixelboard + ( /*y offset */ 30 * COLS ) + ( py * COLS ) + px /* / 2 */;
3329 if ( *ph + ca < 250 ) {
3340 unsigned int runcount = 10;
3341 while ( runcount-- ) {
3344 SDL_FillRect( sdl_realscreen, NULL /* whole */, 0 );
3346 // render pixelboard
3349 for ( y = 0; y < ROWS; y++ ) {
3350 for ( x = 0; x < COLS; x++ ) {
3352 if ( 1||pixelboard [ ( y * COLS ) + x ] ) {
3355 r.x = x * ( PIXELW + MARGINW );
3356 r.y = y * ( PIXELH + MARGINH );
3360 c = SDL_MapRGB ( sdl_realscreen -> format, 100 /* r */, 0 /* g */, pixelboard [ ( y * COLS ) + x ] );
3362 SDL_FillRect( sdl_realscreen, &r /* whole */, c );
3370 unsigned char *pc = pixelboard;
3371 for ( y = 0; y < ROWS; y++ ) {
3372 for ( x = 0; x < COLS; x++ ) {
3382 // slide pixels upwards
3383 memmove ( pixelboard, pixelboard + COLS, ( COLS * ROWS ) - COLS );
3385 // render actual readable text
3388 // display up to cursor
3390 unsigned int cdraw = 0;
3394 if ( crevealed > 200 ) {
3395 cdraw = crevealed - 200;
3401 for ( ; cdraw < crevealed; cdraw++ ) {
3402 ctb [ 0 ] = cbuffer [ cdraw ];
3404 // move over or down
3405 if ( cbuffer [ cdraw ] == '\n' ) {
3410 if ( dest.y > 450 ) {
3416 cs = TTF_RenderText_Blended ( g_tab_font, ctb, rtextc );
3418 SDL_BlitSurface ( cs, NULL /* all */, sdl_realscreen, &dest );
3419 SDL_FreeSurface ( cs );
3429 SDL_FillRect ( sdl_realscreen, &dest /* whole */, 220 );
3431 // increment cursor to next character
3432 if ( cbuffer [ crevealed ] != '\0' ) {
3436 } // draw cursor text
3440 SDL_UpdateRect ( sdl_realscreen, 0, 0, 0, 0 ); // whole screen
3444 // any button? if so, about
3450 if ( SDL_PeepEvents ( &e, 1, SDL_GETEVENT, SDL_EVENTMASK(/*SDL_KEYUP|*/SDL_KEYDOWN) ) > 0 ) {
3459 SDL_FreeSurface ( rtext );
3463 } // while more text
3467 for ( i = 0; i < textmax; i++ ) {
3468 if ( textloop [ i ] ) {
3469 free ( textloop [ i ] );
3477 void ui_revealscreen ( void ) {
3478 char *labels [ 500 ];
3479 unsigned int labelmax = 0;
3481 char fulllabel [ 200 ];
3483 if ( ! category_count ( CFHIDDEN ) ) {
3484 return; // nothing to do
3487 // switch to hidden categories
3488 category_publish ( CFHIDDEN, NULL );
3490 // build up labels to show in menu
3491 for ( i = 0; i < g_categorycount; i++ ) {
3493 if ( g_categories [ i ] -> parent_catname ) {
3494 sprintf ( fulllabel, "%s [%s]", g_categories [ i ] -> catname, g_categories [ i ] -> parent_catname );
3496 sprintf ( fulllabel, "%s", g_categories [ i ] -> catname );
3499 labels [ labelmax++ ] = strdup ( fulllabel );
3503 int sel = ui_modal_single_menu ( labels, labelmax, "Temporary Category Reveal",
3504 "Enter to select; other to return." );
3506 // if selected, try to set this guy to visible
3509 // fix up category name, if its been hacked
3510 #if 0 // prepending and .. wtf crap is this
3511 if ( strchr ( g_categories [ sel ] -> catname, '.' ) ) {
3512 char *t = g_categories [ sel ] -> catname;
3513 g_categories [ sel ] -> catname = strdup ( strchr ( g_categories [ sel ] -> catname, '.' ) + 1 );
3518 // reflag this guy to be visible
3519 g_categories [ sel ] -> catflags = CFNORMAL;
3521 // switch to the new category.. cache name.
3522 char *switch_to_name = g_categories [ sel ] -> catname;
3524 // republish categories
3525 category_publish ( CFNORMAL, NULL );
3527 // switch to the new category.. with the cached name!
3528 ui_category = category_index ( switch_to_name );
3530 // ensure visibility
3531 unsigned int screen_width = ui_display_context.screen_width;
3532 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
3533 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
3534 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
3539 // republish categories
3540 category_publish ( CFNORMAL, NULL );
3543 render_mask |= CHANGED_CATEGORY;
3544 ui_start_defered_icon_thread();
3549 void ui_recache_context ( ui_context_t *c ) {
3551 c -> screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
3553 c -> font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
3554 c -> font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
3555 c -> font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
3556 c -> font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
3558 c -> grid_offset_x = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_x" );
3559 c -> grid_offset_y = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_y" );
3561 c -> icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
3562 c -> icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
3563 c -> icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
3564 c -> icon_max_height = pnd_conf_get_as_int ( g_conf, "grid.icon_max_height" );
3565 c -> sel_icon_offset_x = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_x", 0 );
3566 c -> sel_icon_offset_y = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_y", 0 );
3568 c -> text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
3569 c -> text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
3570 c -> text_offset_x = pnd_conf_get_as_int ( g_conf, "grid.text_offset_x" );
3571 c -> text_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_offset_y" );
3572 c -> text_hilite_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
3574 c -> row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 4 );
3575 c -> col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
3577 c -> cell_width = pnd_conf_get_as_int ( g_conf, "grid.cell_width" );
3578 c -> cell_height = pnd_conf_get_as_int ( g_conf, "grid.cell_height" );
3580 c -> arrow_bar_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
3581 c -> arrow_bar_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
3582 c -> arrow_bar_clip_w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
3583 c -> arrow_bar_clip_h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
3584 c -> arrow_up_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
3585 c -> arrow_up_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
3586 c -> arrow_down_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
3587 c -> arrow_down_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
3590 SDL_Color tmp = { c -> font_rgba_r, c -> font_rgba_g, c -> font_rgba_b, c -> font_rgba_a };
3591 c -> fontcolor = tmp;
3593 // determine font height
3594 if ( g_grid_font ) {
3596 rtext = TTF_RenderText_Blended ( g_grid_font, "M", c -> fontcolor );
3597 c -> text_height = rtext -> h;
3599 c -> text_height = 10;
3602 // now that we've got 'normal' (detail pane shown) param's, lets check if detail pane
3603 // is hidden; if so, override some values with those alternate skin values where possible.
3604 if ( ui_detail_hidden ) {
3605 // if detail panel is hidden, and theme cannot support it, unhide the bloody thing. (This may help
3606 // when someone is amid theme hacking or changing.)
3607 if ( ! ui_is_detail_hideable() ) {
3608 ui_detail_hidden = 0;
3612 if ( ui_detail_hidden ) {
3614 c -> row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max_w", c -> row_max );
3615 c -> col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max_w", c -> col_max );
3617 c -> cell_width = pnd_conf_get_as_int_d ( g_conf, "grid.cell_width_w", c -> cell_width );
3618 c -> cell_height = pnd_conf_get_as_int_d ( g_conf, "grid.cell_height_w", c -> cell_height );
3620 c -> arrow_bar_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x_w", 450 );
3621 c -> arrow_bar_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y_w", 100 );
3622 c -> arrow_up_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x_w", 450 );
3623 c -> arrow_up_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y_w", 80 );
3624 c -> arrow_down_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x_w", 450 );
3625 c -> arrow_down_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y_w", 80 );
3627 } // if detail hidden.. still.
3629 } // if detail hidden
3634 unsigned char ui_is_detail_hideable ( void ) {
3636 // if skin has a bit of info for wide-mode, we assume wide-mode is available
3637 if ( pnd_conf_get_as_char ( g_conf, "grid.row_max_w" ) != NULL ) {
3645 void ui_toggle_detail_pane ( void ) {
3647 // no bitmask trickery here; I like it to be stand-out obvious at 3am.
3649 if ( ui_detail_hidden ) {
3650 ui_detail_hidden = 0;
3652 ui_detail_hidden = 1;
3655 // repull skin config
3656 ui_recache_context ( &ui_display_context );
3659 render_mask |= CHANGED_EVERYTHING;
3664 void ui_menu_context ( mm_appref_t *a ) {
3666 unsigned char rescan_apps = 0;
3667 unsigned char context_alive = 1;
3672 context_file_delete,
3675 context_app_recategorize,
3676 context_app_recategorize_sub,
3678 context_app_cpuspeed,
3686 char *verbiage[] = {
3687 "Done (return to grid)", // context_done
3688 "Get info about file/dir", // context_file_info
3689 "Delete file/dir", // context_file_delete
3690 "Get info", // context_app_info
3691 "Hide application", // hide
3692 "Recategorize", // recategorize
3693 "Recategorize subcategory", // recategorize
3694 "Change displayed title", // rename
3695 "Set CPU speed for launch", // cpuspeed
3696 "Run application", // run
3697 "Edit notes line 1", // notes1
3698 "Edit notes line 2", // notes2
3699 "Edit notes line 3", // notes3
3702 unsigned short int menu [ context_menu_max ];
3703 char *menustring [ context_menu_max ];
3704 unsigned char menumax = 0;
3707 menu [ menumax ] = context_done; menustring [ menumax++ ] = verbiage [ context_done ];
3709 // hook up appropriate menu options based on tab-type and object-type
3710 if ( g_categories [ ui_category ] -> fspath ) {
3712 menu [ menumax ] = context_file_info; menustring [ menumax++ ] = verbiage [ context_file_info ];
3713 menu [ menumax ] = context_file_delete; menustring [ menumax++ ] = verbiage [ context_file_delete ];
3716 if ( a -> ref -> object_type == pnd_object_type_directory ) {
3717 return; // don't do anything if the guy is a subcat-as-folder
3720 //menu [ menumax ] = context_app_info; menustring [ menumax++ ] = verbiage [ context_app_info ];
3721 menu [ menumax ] = context_app_run; menustring [ menumax++ ] = verbiage [ context_app_run ];
3722 menu [ menumax ] = context_app_hide; menustring [ menumax++ ] = verbiage [ context_app_hide ];
3723 menu [ menumax ] = context_app_recategorize; menustring [ menumax++ ] = verbiage [ context_app_recategorize ];
3724 menu [ menumax ] = context_app_recategorize_sub; menustring [ menumax++ ] = verbiage [ context_app_recategorize_sub ];
3725 menu [ menumax ] = context_app_rename; menustring [ menumax++ ] = verbiage [ context_app_rename ];
3726 menu [ menumax ] = context_app_cpuspeed; menustring [ menumax++ ] = verbiage [ context_app_cpuspeed ];
3727 menu [ menumax ] = context_app_notes1; menustring [ menumax++ ] = verbiage [ context_app_notes1 ];
3728 menu [ menumax ] = context_app_notes2; menustring [ menumax++ ] = verbiage [ context_app_notes2 ];
3729 menu [ menumax ] = context_app_notes3; menustring [ menumax++ ] = verbiage [ context_app_notes3 ];
3733 while ( context_alive ) {
3735 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 */ );
3742 switch ( menu [ sel ] ) {
3748 case context_file_info:
3751 case context_file_delete:
3752 //ui_menu_twoby ( "Delete - Are you sure?", "B/enter; other to cancel", "Delete", "Do not delete" );
3755 case context_app_info:
3758 case context_app_hide:
3761 char confkey [ 1000 ];
3762 snprintf ( confkey, 999, "%s.%s", "appshow", a -> ref -> unique_id );
3765 pnd_conf_set_char ( g_conf, confkey, "0" );
3767 // write conf, so it will take next time
3768 conf_write ( g_conf, conf_determine_location ( g_conf ) );
3769 conf_write ( g_conf, CONF_PREF_TEMPPATH );
3771 // can we just 'hide' this guy without reloading all apps? (this is for you, EvilDragon)
3774 // DOESN'T WORK YET; other parts of app are still hanging onto some values and blow up
3776 char *uid = strdup ( a -> ref -> unique_id );
3778 for ( i = 0; i < g_categorycount; i++ ) {
3779 mm_appref_t *p = g_categories [ i ] -> refs;
3784 if ( strcmp ( p -> ref -> unique_id, uid ) == 0 ) {
3786 if ( g_categories [ i ] -> refcount ) {
3787 g_categories [ i ] -> refcount--;
3792 } // while for each appref
3793 } // for each cat/tab
3798 // request rescan and wrap up
3802 context_alive = 0; // nolonger visible, so lets just get out
3808 case context_app_recategorize:
3811 unsigned char optmax = 0;
3814 // show custom categories
3815 if ( mmcustom_setup() ) {
3817 for ( i = 0; i < mmcustom_count; i++ ) {
3818 if ( mmcustom_complete [ i ].parent_cat == NULL ) {
3819 opts [ optmax++ ] = mmcustom_complete [ i ].cat;
3825 // show FD categories
3826 i = 2; // skip first two - Other and NoParentCategory
3829 if ( ! freedesktop_complete [ i ].cat ) {
3833 if ( ! freedesktop_complete [ i ].parent_cat ) {
3834 opts [ optmax++ ] = freedesktop_complete [ i ].cat;
3841 char prompt [ 101 ];
3842 snprintf ( prompt, 100, "Pick category [%s]", a -> ref -> main_category ? a -> ref -> main_category : "NoParentCategory" );
3844 int sel = ui_modal_single_menu ( opts, optmax, prompt /*"Select parent category"*/, "Enter to select; other to skip." );
3847 char confirm [ 1001 ];
3848 snprintf ( confirm, 1000, "Confirm: %s", opts [ sel ] );
3850 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm categorization", "Do not set category" ) == 1 ) {
3851 ovr_replace_or_add ( a, "maincategory", opts [ sel ] );
3853 // when changing main cat, reset subcat, otherwise you go from Game/Emu to Network/Emu and get sent to Other right away
3854 ovr_replace_or_add ( a, "maincategorysub1", freedesktop_complete [ 2 ].cat );
3859 if ( mmcustom_is_ready() ) {
3860 mmcustom_shutdown();
3866 case context_app_recategorize_sub:
3869 unsigned char optmax = 0;
3870 unsigned char i = 0;
3872 char *whichparentarewe;
3873 if ( g_categories [ ui_category ] -> parent_catname ) {
3874 whichparentarewe = g_categories [ ui_category ] -> parent_catname;
3876 whichparentarewe = g_categories [ ui_category ] -> catname;
3879 // add NoSubcategory magic one
3880 opts [ optmax++ ] = freedesktop_complete [ 2 ].cat;
3882 // add custom categories
3883 if ( mmcustom_setup() ) {
3885 for ( i = 0; i < mmcustom_count; i++ ) {
3886 if ( mmcustom_complete [ i ].parent_cat && strcmp ( mmcustom_complete [ i ].parent_cat, whichparentarewe ) == 0 ) {
3887 opts [ optmax++ ] = mmcustom_complete [ i ].cat;
3893 // add FD categories
3896 if ( ! freedesktop_complete [ i ].cat ) {
3900 if ( ( freedesktop_complete [ i ].parent_cat ) &&
3901 ( strcasecmp ( freedesktop_complete [ i ].parent_cat, whichparentarewe ) == 0 )
3904 opts [ optmax++ ] = freedesktop_complete [ i ].cat;
3910 char prompt [ 101 ];
3911 //snprintf ( prompt, 100, "Currently: %s", a -> ref -> main_category1 ? a -> ref -> main_category1 : "NoSubcategory" );
3912 snprintf ( prompt, 100, "%s [%s]", a -> ref -> main_category1 ? a -> ref -> main_category1 : "NoSubcategory", whichparentarewe );
3914 int sel = ui_modal_single_menu ( opts, optmax, prompt /*"Select subcategory"*/, "Enter to select; other to skip." );
3917 char confirm [ 1001 ];
3918 snprintf ( confirm, 1000, "Confirm: %s", opts [ sel ] );
3920 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm sub-categorization", "Do not set sub-category" ) == 1 ) {
3921 ovr_replace_or_add ( a, "maincategorysub1", opts [ sel ] );
3927 if ( mmcustom_is_ready() ) {
3928 mmcustom_shutdown();
3934 case context_app_rename:
3936 char namebuf [ 101 ];
3937 unsigned char changed;
3939 changed = ui_menu_get_text_line ( "Rename application", "Use keyboard; Enter when done.",
3940 a -> ref -> title_en ? a -> ref -> title_en : "blank", namebuf, 30, 0 /* alphanumeric */ );
3943 char confirm [ 1001 ];
3944 snprintf ( confirm, 1000, "Confirm: %s", namebuf );
3946 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm rename", "Do not rename" ) == 1 ) {
3947 ovr_replace_or_add ( a, "title", namebuf );
3957 case context_app_cpuspeed:
3959 char namebuf [ 101 ];
3960 unsigned char changed;
3962 changed = ui_menu_get_text_line ( "Specify runspeed", "Use keyboard; Enter when done.",
3963 a -> ref -> clockspeed ? a -> ref -> clockspeed : "500", namebuf, 6, 1 /* numeric */ );
3966 char confirm [ 1001 ];
3967 snprintf ( confirm, 1000, "Confirm: %s", namebuf );
3969 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm clockspeed", "Do not set" ) == 1 ) {
3970 ovr_replace_or_add ( a, "clockspeed", namebuf );
3980 case context_app_run:
3984 case context_app_notes1:
3985 case context_app_notes2:
3986 case context_app_notes3:
3988 char namebuf [ 101 ] = "";
3991 unsigned char notenum;
3994 if ( menu [ sel ] == context_app_notes1 ) {
3996 } else if ( menu [ sel ] == context_app_notes2 ) {
3998 } else if ( menu [ sel ] == context_app_notes3 ) {
4002 // figure out key for looking up existing, and for storing replacement
4003 snprintf ( key, 500, "Application-%u.note-%u", a -> ref -> subapp_number, notenum );
4005 // do we have existing value?
4007 char *existing = pnd_conf_get_as_char ( a -> ovrh, key );
4009 strncpy ( namebuf, existing, 100 );
4013 unsigned char changed;
4015 changed = ui_menu_get_text_line ( "Enter replacement note", "Use keyboard; Enter when done.",
4016 namebuf, namebuf, 30, 0 /* not-numeric-forced */ );
4019 ovr_replace_or_add ( a, strchr ( key, '.' ) + 1, namebuf );
4031 } // if useful return
4036 if ( rescan_apps ) {
4037 applications_free();
4038 applications_scan();
4044 unsigned char ui_menu_oneby ( char *title, char *footer, char *one ) {
4047 int sel = ui_modal_single_menu ( opts, 1, title, footer );
4054 unsigned char ui_menu_twoby ( char *title, char *footer, char *one, char *two ) {
4058 int sel = ui_modal_single_menu ( opts, 2, title, footer );
4065 unsigned char ui_menu_get_text_line ( char *title, char *footer, char *initialvalue,
4066 char *r_buffer, unsigned char maxlen, unsigned char numbersonlyp )
4068 SDL_Rect rects [ 40 ];
4069 SDL_Rect *dest = rects;
4073 char hacktext [ 1024 ];
4074 unsigned char shifted = 0;
4076 bzero ( rects, sizeof(SDL_Rect) * 40 );
4078 if ( initialvalue ) {
4079 if ( initialvalue == r_buffer ) {
4080 // already good to go
4082 strncpy ( r_buffer, initialvalue, maxlen );
4085 bzero ( r_buffer, maxlen );
4091 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
4092 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
4093 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
4094 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
4095 SDL_FillRect( sdl_realscreen, dest, 0 );
4097 // show dialog background
4098 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
4101 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> w;
4102 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> h;
4103 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
4104 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
4105 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
4109 // show dialog frame
4110 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
4111 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
4112 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
4113 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
4119 rtext = TTF_RenderText_Blended ( g_tab_font, title, ui_display_context.fontcolor );
4120 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
4121 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
4122 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
4123 SDL_FreeSurface ( rtext );
4129 rtext = TTF_RenderText_Blended ( g_tab_font, footer, ui_display_context.fontcolor );
4130 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
4131 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
4132 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
4134 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
4135 SDL_FreeSurface ( rtext );
4139 // show text line - and embed cursor
4140 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
4141 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( 0/*i*/ + 1 - 0/*first_visible*/ ) );
4143 strncpy ( hacktext, r_buffer, 1000 );
4144 strncat ( hacktext, "\n", 1000 ); // add [] in most fonts
4146 rtext = TTF_RenderText_Blended ( g_tab_font, hacktext, ui_display_context.fontcolor );
4147 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
4148 SDL_FreeSurface ( rtext );
4151 // update all the rects and send it all to sdl
4152 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
4157 while ( SDL_WaitEvent ( &event ) ) {
4159 switch ( event.type ) {
4162 if ( event.key.keysym.sym == SDLK_LSHIFT || event.key.keysym.sym == SDLK_RSHIFT ) {
4169 if ( event.key.keysym.sym == SDLK_LEFT || event.key.keysym.sym == SDLK_BACKSPACE ) {
4170 if ( strlen ( r_buffer ) > 0 ) {
4171 char *eol = strchr ( r_buffer, '\0' );
4172 *( eol - 1 ) = '\0';
4175 } else if ( event.key.keysym.sym == SDLK_UP ) {
4176 r_buffer [ 0 ] = '\0'; // truncate!
4178 } else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_END ) { // return, or "B"
4179 // on Enter/Return or B, if the buffer has 1 or more chars, we return it as valid.. otherwise, invalid.
4180 if ( strlen ( r_buffer ) > 0 ) {
4185 } else if ( event.key.keysym.sym == SDLK_LSHIFT || event.key.keysym.sym == SDLK_RSHIFT ) {
4188 } else if ( event.key.keysym.sym == SDLK_ESCAPE ||
4189 event.key.keysym.sym == SDLK_PAGEUP ||
4190 event.key.keysym.sym == SDLK_PAGEDOWN ||
4191 event.key.keysym.sym == SDLK_HOME
4198 if ( isprint(event.key.keysym.sym) ) {
4200 unsigned char good = 1;
4202 if ( numbersonlyp && ( ! isdigit(event.key.keysym.sym) ) ) {
4206 if ( maxlen && strlen(r_buffer) >= maxlen ) {
4211 char b [ 2 ] = { '\0', '\0' };
4213 b [ 0 ] = toupper ( event.key.keysym.sym );
4215 b [ 0 ] = event.key.keysym.sym;
4217 strncat ( r_buffer, b, maxlen );
4230 } // while waiting for input
4237 unsigned char ovr_replace_or_add ( mm_appref_t *a, char *keybase, char *newvalue ) {
4238 //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 );
4240 char fullpath [ PATH_MAX ];
4242 sprintf ( fullpath, "%s/%s", a -> ref -> object_path, a -> ref -> object_filename );
4243 char *dot = strrchr ( fullpath, '.' );
4245 sprintf ( dot, PXML_SAMEPATH_OVERRIDE_FILEEXT );
4247 pnd_log ( pndn_error, "ERROR: Bad pnd-path in disco_t! %s\n", fullpath );
4251 struct stat statbuf;
4253 if ( stat ( fullpath, &statbuf ) == 0 ) {
4257 h = pnd_conf_fetch_by_path ( fullpath );
4260 return ( 0 ); // fail!
4264 snprintf ( key, 100, "Application-%u.%s", a -> ref -> subapp_number, keybase );
4266 pnd_conf_set_char ( h, key, newvalue );
4268 return ( pnd_conf_write ( h, fullpath ) );
4271 // file needs to be created - easy!
4273 FILE *f = fopen ( fullpath, "w" );
4276 fprintf ( f, "Application-%u.%s\t%s\n", a -> ref -> subapp_number, keybase, newvalue );
4280 return ( 0 ); // fail!
4288 void ui_manage_categories ( void ) {
4289 unsigned char require_app_scan = 0;
4291 if ( ! mmcustom_setup() ) {
4295 char *opts [ 20 ] = {
4296 "List custom categories",
4297 "List custom subcategories",
4298 "Register custom category",
4299 "Register custom subcategory",
4300 "Unregister custom category",
4301 "Unregister custom subcategory",
4307 int sel = ui_modal_single_menu ( opts, 7, "Custom Categories", "B to select; other to cancel." );
4311 case 0: // list custom
4312 ui_pick_custom_category ( 0 );
4315 case 1: // list custom sub
4316 if ( mmcustom_count ) {
4318 char *maincat = ui_pick_custom_category ( 2 );
4321 unsigned int subcount = mmcustom_count_subcats ( maincat );
4322 char titlebuf [ 201 ];
4324 snprintf ( titlebuf, 200, "Category: %s", maincat );
4326 if ( subcount == 0 ) {
4327 ui_menu_oneby ( titlebuf, "B/Enter to accept", "Category has no subcategories." );
4330 char **list = malloc ( subcount * sizeof(char*) );
4332 unsigned int counter = 0;
4334 for ( i = 0; i < mmcustom_count; i++ ) {
4335 if ( mmcustom_complete [ i ].parent_cat && strcasecmp ( mmcustom_complete [ i ].parent_cat, maincat ) == 0 ) {
4336 list [ counter++ ] = mmcustom_complete [ i ].cat;
4340 ui_modal_single_menu ( list, counter, titlebuf, "Any button to exit." );
4344 } // more than 0 subcats?
4346 } // user picked a main cat?
4349 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4353 case 2: // register custom
4355 unsigned char changed;
4356 char namebuf [ 101 ] = "";
4358 changed = ui_menu_get_text_line ( "Enter unique category name", "Use keyboard; Enter when done.",
4359 "Pandora", namebuf, 30, 0 /* alphanumeric */ );
4361 // did the user enter something?
4364 // for now, force use of '*' into something else as we use * internally :/ (FIXME)
4367 while ( ( fixme = strchr ( namebuf, '*' ) ) ) {
4372 // and if so, is it existant already or not?
4373 if ( mmcustom_query ( namebuf, NULL ) ) {
4374 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a registered category." );
4375 } else if ( freedesktop_category_query ( namebuf, NULL ) ) {
4376 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a Standard category." );
4379 char confirm [ 1001 ];
4380 snprintf ( confirm, 1000, "Confirm: %s", namebuf );
4382 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm new category", "Do not register" ) == 1 ) {
4383 // register, save, recycle the current list
4384 mmcustom_register ( namebuf, NULL );
4385 mmcustom_write ( NULL );
4386 mmcustom_shutdown();
4392 } // entered something?
4397 case 3: // register custom sub
4398 if ( 1 /*mmcustom_count -- we allow FD cats now, so this isn't applicable error */ ) {
4400 char *maincat = ui_pick_custom_category ( 1 /* include FD */ );
4403 char titlebuf [ 201 ];
4405 snprintf ( titlebuf, 200, "Subcat of: %s", maincat );
4407 unsigned char changed;
4408 char namebuf [ 101 ] = "";
4410 changed = ui_menu_get_text_line ( titlebuf, "Use keyboard; Enter when done.", "Submarine", namebuf, 30, 0 /* alphanumeric */ );
4412 // did the user enter something?
4415 // for now, force use of '*' into something else as we use * internally :/ (FIXME)
4418 while ( ( fixme = strchr ( namebuf, '*' ) ) ) {
4423 // and if so, is it existant already or not?
4424 if ( mmcustom_query ( namebuf, maincat ) ) {
4425 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a subcategory." );
4426 } else if ( freedesktop_category_query ( namebuf, maincat ) ) {
4427 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a Standard subcategory." );
4430 char confirm [ 1001 ];
4431 snprintf ( confirm, 1000, "Confirm: %s [%s]", namebuf, maincat );
4433 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm new category", "Do not register" ) == 1 ) {
4434 // register, save, recycle the current list
4435 mmcustom_register ( namebuf, maincat );
4436 mmcustom_write ( NULL );
4437 mmcustom_shutdown();
4443 } // entered something?
4445 } // selected parent cat?
4448 ui_menu_oneby ( "Warning", "B/Enter to accept", "No categories registered." );
4452 case 4: // unreg custom
4453 if ( mmcustom_count ) {
4454 char *maincat = ui_pick_custom_category ( 0 );
4457 char confirm [ 1001 ];
4458 snprintf ( confirm, 1000, "Confirm remove: %s", maincat );
4460 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm unregister", "Do not unregister" ) == 1 ) {
4461 // register, save, recycle the current list
4462 mmcustom_unregister ( maincat, NULL );
4463 mmcustom_write ( NULL );
4464 mmcustom_shutdown();
4471 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4475 case 5: // unreg custom sub
4476 if ( mmcustom_count ) {
4477 char *maincat = ui_pick_custom_category ( 2 );
4480 unsigned int subcount = mmcustom_count_subcats ( maincat );
4481 char titlebuf [ 201 ];
4483 snprintf ( titlebuf, 200, "Category: %s", maincat );
4485 if ( subcount == 0 ) {
4486 ui_menu_oneby ( titlebuf, "B/Enter to accept", "Category has no subcategories." );
4489 char **list = malloc ( subcount * sizeof(char*) );
4491 unsigned int counter = 0;
4493 for ( i = 0; i < mmcustom_count; i++ ) {
4494 if ( mmcustom_complete [ i ].parent_cat && strcasecmp ( mmcustom_complete [ i ].parent_cat, maincat ) == 0 ) {
4495 list [ counter++ ] = mmcustom_complete [ i ].cat;
4499 int sel = ui_modal_single_menu ( list, counter, titlebuf, "B to selct; other to exit." );
4502 char confirm [ 1001 ];
4503 snprintf ( confirm, 1000, "Confirm remove: %s", list [ sel ] );
4505 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm unregister", "Do not unregister" ) == 1 ) {
4506 // register, save, recycle the current list
4507 mmcustom_unregister ( list [ sel ], maincat );
4508 mmcustom_write ( NULL );
4509 mmcustom_shutdown();
4517 } // more than 0 subcats?
4519 } // user picked a main cat?
4522 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4529 if ( sel < 0 || sel > 5 ) {
4533 } // while running the menu
4535 // shut down custom cats
4536 mmcustom_shutdown();
4539 if ( require_app_scan ) {
4540 applications_free();
4541 applications_scan();
4545 render_mask |= CHANGED_EVERYTHING;
4550 // mode 0 == custom main only; 1 == custom main + FD main; 2 == custom main + FD mains-with-custom-subs
4551 char *ui_pick_custom_category ( unsigned char mode ) {
4554 unsigned int counter = 0;
4556 // alloc space for list, depending on scope
4558 list = malloc ( (mmcustom_count+freedesktop_count()) * sizeof(char*) );
4560 list = malloc ( mmcustom_count * sizeof(char*) );
4564 for ( i = 0; i < mmcustom_count; i++ ) {
4565 if ( mmcustom_complete [ i ].parent_cat == NULL ) {
4566 list [ counter++ ] = mmcustom_complete [ i ].cat;
4576 if ( ! freedesktop_complete [ i ].cat ) {
4581 if ( freedesktop_complete [ i ].parent_cat == NULL ) {
4583 // mode 1 == include them all
4584 // mode 2 == include them if they have a custom subcat
4585 if ( ( mode == 1 ) ||
4586 ( mmcustom_subcount ( freedesktop_complete [ i ].cat ) ) )
4588 list [ counter++ ] = freedesktop_complete [ i ].cat;
4598 // we actually showing anything?
4600 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4605 int sel = ui_modal_single_menu ( list, counter, "Custom Categories", "Any button to exit." );
4612 char *foo = list [ sel ];
4618 void ui_start_defered_icon_thread ( void ) {
4620 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) != 1 ) {
4624 if ( g_icon_thread_busy ) {
4625 //fprintf ( stderr, "REM: Waiting for thread to stop..\n" );
4626 ui_stop_defered_icon_thread();
4629 //fprintf ( stderr, "WARN: Starting new icon caching thread..\n" );
4630 g_icon_thread = SDL_CreateThread ( (void*)ui_threaded_defered_icon, NULL );
4632 if ( ! g_icon_thread ) {
4633 pnd_log ( pndn_error, "ERROR: Couldn't create icon thread\n" );
4639 void ui_stop_defered_icon_thread ( void ) {
4640 time_t started = time ( NULL );
4642 // ask thread to stop, then wait for it (if two run at same time, or if we change
4643 // category content under neath it, could be bad..)
4644 g_icon_thread_stop = 1;
4645 while ( g_icon_thread_busy ) {
4646 time ( NULL ); // spin
4648 g_icon_thread_stop = 0;
4650 fprintf ( stderr, "REM: Thread stoppage took %u seconds.\n", (int) ( time ( NULL ) - started ) );