2 #include <stdio.h> /* for FILE etc */
3 #include <stdlib.h> /* for malloc */
4 #include <unistd.h> /* for unlink */
5 #include <limits.h> /* for PATH_MAX */
8 #define __USE_GNU /* for strcasestr */
9 #include <string.h> /* for making ftw.h happy */
15 #include "SDL_audio.h"
16 #include "SDL_image.h"
18 #include "SDL_gfxPrimitives.h"
19 #include "SDL_rotozoom.h"
20 #include "SDL_thread.h"
24 #include "pnd_logger.h"
26 #include "pnd_container.h"
27 #include "pnd_discovery.h"
29 #include "pnd_device.h"
30 #include "../lib/pnd_pathiter.h"
31 #include "pnd_utility.h"
32 #include "pnd_pndfiles.h"
33 #include "pnd_notify.h"
34 #include "pnd_dbusnotify.h"
40 #include "mmwrapcmd.h"
42 #include "mmui_context.h"
43 #include "freedesktop_cats.h"
44 #include "mmcustom_cats.h"
46 #define CHANGED_NOTHING (0)
47 #define CHANGED_CATEGORY (1<<0) /* changed to different category */
48 #define CHANGED_SELECTION (1<<1) /* changed app selection */
49 #define CHANGED_DATAUPDATE (1<<2) /* deferred preview pic or icon came in */
50 #define CHANGED_APPRELOAD (1<<3) /* new set of applications entirely */
51 #define CHANGED_EVERYTHING (1<<4) /* redraw it all! */
52 unsigned int render_mask = CHANGED_EVERYTHING;
54 SDL_Thread *g_icon_thread = NULL;
55 unsigned char g_icon_thread_stop = 0; /* if !0 means thread should stop and maim app may block until it goes back to 0.. */
56 unsigned char g_icon_thread_busy = 0; /* if !0 means thread is running right now */
58 #define MIMETYPE_EXE "/usr/bin/file" /* check for file type prior to invocation */
62 SDL_Surface *sdl_realscreen = NULL;
63 unsigned int sdl_ticks = 0;
64 SDL_Thread *g_preview_thread = NULL;
65 SDL_Thread *g_timer_thread = NULL;
67 enum { sdl_user_ticker = 0,
68 sdl_user_finishedpreview = 1,
69 sdl_user_finishedicon = 2,
75 unsigned short int g_scale = 1; // 1 == noscale
77 SDL_Surface *g_imgcache [ IMG_MAX ];
79 TTF_Font *g_big_font = NULL;
80 TTF_Font *g_grid_font = NULL;
81 TTF_Font *g_detailtext_font = NULL;
82 TTF_Font *g_tab_font = NULL;
84 extern pnd_conf_handle g_conf;
86 /* current display state
88 int ui_rows_scrolled_down = 0; // number of rows that should be missing from top of the display
89 mm_appref_t *ui_selected = NULL;
90 unsigned char ui_category = 0; // current category
91 unsigned char ui_catshift = 0; // how many cats are offscreen to the left
92 ui_context_t ui_display_context; // display paramaters: see mmui_context.h
93 unsigned char ui_detail_hidden = 0; // if >0, detail panel is hidden
94 // FUTURE: If multiple panels can be shown/hidden, convert ui_detail_hidden to a bitmask
96 static SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ); // height -1 means ignore
97 static int ui_selected_index ( void );
98 static void ui_start_defered_icon_thread ( void );
99 static void ui_stop_defered_icon_thread ( void );
101 unsigned char ui_setup ( void ) {
106 SDL_Init ( SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE );
108 SDL_JoystickOpen ( 0 ); // turn on joy-0
110 SDL_WM_SetCaption ( "mmenu", "mmenu" );
112 // hide the mouse cursor if we can
113 if ( SDL_ShowCursor ( -1 ) == 1 ) {
114 SDL_ShowCursor ( 0 );
120 unsigned int svm = SDL_SWSURFACE /*| SDL_FULLSCREEN*/ /* 0*/;
121 if ( pnd_conf_get_as_int_d ( g_conf, "display.fullscreen", 0 ) > 0 ) {
122 svm |= SDL_FULLSCREEN;
126 SDL_SetVideoMode ( 800 * g_scale, 480 * g_scale, 16 /*bpp*/, svm );
128 if ( ! sdl_realscreen ) {
129 pnd_log ( pndn_error, "ERROR: Couldn't open SDL real screen; dieing." );
133 pnd_log ( pndn_debug, "Pixel format:" );
134 pnd_log ( pndn_debug, "bpp b: %u\n", sdl_realscreen -> format -> BitsPerPixel );
135 pnd_log ( pndn_debug, "bpp B: %u\n", sdl_realscreen -> format -> BytesPerPixel );
136 pnd_log ( pndn_debug, "R mask: %08x\n", sdl_realscreen -> format -> Rmask );
137 pnd_log ( pndn_debug, "G mask: %08x\n", sdl_realscreen -> format -> Gmask );
138 pnd_log ( pndn_debug, "B mask: %08x\n", sdl_realscreen -> format -> Bmask );
144 /* Set 16-bit stereo audio at 22Khz */
145 fmt.freq = 44100; //22050;
146 fmt.format = AUDIO_S16; //AUDIO_S16;
148 fmt.samples = 2048; /* A good value for games */
149 fmt.callback = mixaudio;
152 /* Open the audio device and start playing sound! */
153 if ( SDL_OpenAudio ( &fmt, NULL ) < 0 ) {
154 zotlog ( "Unable to open audio: %s\n", SDL_GetError() );
158 SDL_PauseAudio ( 0 );
163 SDL_EnableKeyRepeat ( 500, 125 /* 150 */ );
166 //IMG_Init ( IMG_INIT_JPG | IMG_INIT_PNG );
172 if ( TTF_Init() == -1 ) {
173 pnd_log ( pndn_error, "ERROR: Couldn't set up SDL TTF lib\n" );
174 return ( 0 ); // couldn't set up SDL TTF
177 char fullpath [ PATH_MAX ];
179 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "minimenu.font" ) );
180 g_big_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
181 if ( ! g_big_font ) {
182 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
183 pnd_conf_get_as_char ( g_conf, "minimenu.font" ), pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
184 return ( 0 ); // couldn't set up SDL TTF
188 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "grid.font" ) );
189 g_grid_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
190 if ( ! g_grid_font ) {
191 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
192 pnd_conf_get_as_char ( g_conf, "grid.font" ), pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
193 return ( 0 ); // couldn't set up SDL TTF
197 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "detailtext.font" ) );
198 g_detailtext_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
199 if ( ! g_detailtext_font ) {
200 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
201 pnd_conf_get_as_char ( g_conf, "detailtext.font" ), pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
202 return ( 0 ); // couldn't set up SDL TTF
206 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "tabs.font" ) );
207 g_tab_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
208 if ( ! g_tab_font ) {
209 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
210 pnd_conf_get_as_char ( g_conf, "tabs.font" ), pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
211 return ( 0 ); // couldn't set up SDL TTF
214 // determine display context
215 if ( pnd_conf_get_as_int_d ( g_conf, "display.show_detail_pane", 1 ) > 0 ) {
216 ui_detail_hidden = 0;
218 ui_detail_hidden = 1;
220 ui_recache_context ( &ui_display_context );
225 mm_imgcache_t g_imagecache [ IMG_TRUEMAX ] = {
226 { IMG_BACKGROUND_800480, "graphics.IMG_BACKGROUND_800480" },
227 { IMG_BACKGROUND_TABMASK, "graphics.IMG_BACKGROUND_TABMASK" },
228 { IMG_DETAIL_PANEL, "graphics.IMG_DETAIL_PANEL" },
229 { IMG_DETAIL_BG, "graphics.IMG_DETAIL_BG" },
230 { IMG_SELECTED_ALPHAMASK, "graphics.IMG_SELECTED_ALPHAMASK" },
231 { IMG_TAB_SEL, "graphics.IMG_TAB_SEL" },
232 { IMG_TAB_SEL_L, "graphics.IMG_TAB_SEL_L" },
233 { IMG_TAB_SEL_R, "graphics.IMG_TAB_SEL_R" },
234 { IMG_TAB_UNSEL, "graphics.IMG_TAB_UNSEL" },
235 { IMG_TAB_UNSEL_L, "graphics.IMG_TAB_UNSEL_L" },
236 { IMG_TAB_UNSEL_R, "graphics.IMG_TAB_UNSEL_R" },
237 { IMG_TAB_LINE, "graphics.IMG_TAB_LINE" },
238 { IMG_TAB_LINEL, "graphics.IMG_TAB_LINEL" },
239 { IMG_TAB_LINER, "graphics.IMG_TAB_LINER" },
240 { IMG_ICON_MISSING, "graphics.IMG_ICON_MISSING" },
241 { IMG_SELECTED_HILITE, "graphics.IMG_SELECTED_HILITE" },
242 { IMG_PREVIEW_MISSING, "graphics.IMG_PREVIEW_MISSING" },
243 { IMG_ARROW_UP, "graphics.IMG_ARROW_UP", },
244 { IMG_ARROW_DOWN, "graphics.IMG_ARROW_DOWN", },
245 { IMG_ARROW_SCROLLBAR, "graphics.IMG_ARROW_SCROLLBAR", },
246 { IMG_HOURGLASS, "graphics.IMG_HOURGLASS", },
247 { IMG_FOLDER, "graphics.IMG_FOLDER", },
248 { IMG_EXECBIN, "graphics.IMG_EXECBIN", },
249 { IMG_SUBCATFOLDER, "graphics.IMG_SUBCATFOLDER", "graphics.IMG_FOLDER", },
250 { IMG_DOTDOTFOLDER, "graphics.IMG_DOTDOTFOLDER", "graphics.IMG_FOLDER", },
254 unsigned char ui_imagecache ( char *basepath ) {
256 char fullpath [ PATH_MAX ];
261 for ( i = 0; i < IMG_MAX; i++ ) {
263 if ( g_imagecache [ i ].id != i ) {
264 pnd_log ( pndn_error, "ERROR: Internal table mismatch during caching [%u]\n", i );
268 for ( try = 0; try < 2; try++ ) {
273 filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].confname );
275 if ( g_imagecache [ i ].alt_confname ) {
276 filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].alt_confname );
283 pnd_log ( pndn_error, "ERROR: (Try %u) Missing filename in conf for key: %s\n", try + 1, g_imagecache [ i ].confname );
284 if ( try == 0 ) { continue; } else { return ( 0 ); }
287 if ( filename [ 0 ] == '/' ) {
288 strncpy ( fullpath, filename, PATH_MAX );
290 sprintf ( fullpath, "%s/%s", basepath, filename );
293 if ( ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
294 break; // no retry needed
296 pnd_log ( pndn_error, "ERROR: (Try %u) Couldn't load static cache image: %s\n", try + 1, fullpath );
297 if ( try == 0 ) { continue; } else { return ( 0 ); }
305 //g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = SDL_CreateRGBSurface ( SDL_SWSURFACE, 60, 60, 32, 0xFF0000, 0x00FF00, 0xFF, 0xFF000000 );
306 //boxRGBA ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, 0, 0, 60, 60, 100, 100, 100, 250 );
312 g_imagecache [ IMG_ICON_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_ICON_MISSING ].i, pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 ), -1 );
313 // scale text hilight
314 g_imagecache [ IMG_SELECTED_HILITE ].i = ui_scale_image ( g_imagecache [ IMG_SELECTED_HILITE ].i, pnd_conf_get_as_int_d ( g_conf, "grid.text_width", 50 ), -1 );
315 // scale preview no-pic
316 g_imagecache [ IMG_PREVIEW_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_PREVIEW_MISSING ].i,
317 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ),
318 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 50 ) );
320 // set alpha on detail panel
321 //SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
326 void ui_render ( void ) {
329 // divide width: 550 / 250
330 // divide left side: 5 columns == 110px width
331 // 20px buffer either side == 70px wide icon + 20 + 20?
333 // what jobs to do during render?
337 #define R_TABS (1<<1)
338 #define R_DETAIL (1<<2)
339 #define R_GRID (1<<3)
341 #define R_ALL (R_BG|R_TABS|R_DETAIL|R_GRID)
343 unsigned int render_jobs_b = 0;
345 if ( render_mask & CHANGED_EVERYTHING ) {
346 render_jobs_b |= R_ALL;
349 if ( render_mask & CHANGED_SELECTION ) {
350 render_jobs_b |= R_GRID;
351 render_jobs_b |= R_DETAIL;
354 if ( render_mask & CHANGED_CATEGORY ) {
355 render_jobs_b |= R_ALL;
358 render_mask = CHANGED_NOTHING;
362 unsigned int icon_rows;
365 SDL_Rect rects [ MAXRECTS ], src;
366 SDL_Rect *dest = rects;
367 bzero ( dest, sizeof(SDL_Rect)*MAXRECTS );
369 unsigned int row, displayrow, col;
370 mm_appref_t *appiter;
372 ui_context_t *c = &ui_display_context; // for convenience and shorthand
374 // how many total rows do we need?
375 if ( g_categorycount ) {
376 icon_rows = g_categories [ ui_category ] -> refcount / c -> col_max;
377 if ( g_categories [ ui_category ] -> refcount % c -> col_max > 0 ) {
385 // if no selected app yet, select the first one
386 if ( ! ui_selected && pnd_conf_get_as_int_d ( g_conf, "minimenu.start_selected", 0 ) ) {
387 ui_selected = g_categories [ ui_category ] -> refs;
391 // reset touchscreen regions
392 if ( render_jobs_b ) {
396 // ensure selection is visible
399 unsigned char autoscrolled = 1;
400 while ( autoscrolled ) {
403 int index = ui_selected_index();
404 int topleft = c -> col_max * ui_rows_scrolled_down;
405 int botright = ( c -> col_max * ( ui_rows_scrolled_down + c -> row_max ) - 1 );
407 if ( index < topleft ) {
408 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
409 render_jobs_b |= R_ALL;
411 } else if ( index > botright ) {
412 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
413 render_jobs_b |= R_ALL;
417 } // while autoscrolling
419 if ( ui_rows_scrolled_down < 0 ) {
420 ui_rows_scrolled_down = 0;
421 } else if ( ui_rows_scrolled_down > icon_rows ) {
422 ui_rows_scrolled_down = icon_rows;
428 if ( render_jobs_b & R_BG ) {
430 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
433 dest -> w = sdl_realscreen -> w;
434 dest -> h = sdl_realscreen -> h;
435 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
440 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
443 dest -> w = sdl_realscreen -> w;
444 dest -> h = sdl_realscreen -> h;
445 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
452 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
453 static unsigned int tab_width;
454 static unsigned int tab_height;
455 static unsigned int tab_offset_x;
456 static unsigned int tab_offset_y;
457 static unsigned int text_offset_x;
458 static unsigned int text_offset_y;
459 static unsigned int text_width;
461 static unsigned char tab_first_run = 1;
462 if ( tab_first_run ) {
464 tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
465 tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
466 tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
467 tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
468 text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
469 text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
470 text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
473 unsigned int maxtab = ( c -> screen_width / tab_width ) < g_categorycount ? ( c -> screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift;
474 unsigned int maxtabspot = ( c -> screen_width / tab_width );
476 if ( g_categorycount > 0 ) {
478 // draw tabs with categories
479 for ( col = ui_catshift;
486 // if this is the first (leftmost) tab, we use different artwork
487 // than if the other tabs (so skinner can link lines up nicely.)
488 if ( col == ui_catshift ) {
489 // leftmost tab, special case
491 if ( col == ui_category ) {
492 s = g_imagecache [ IMG_TAB_SEL_L ].i;
494 s = g_imagecache [ IMG_TAB_UNSEL_L ].i;
497 } else if ( col == maxtab - 1 ) {
498 // rightmost tab, special case
500 if ( col == ui_category ) {
501 s = g_imagecache [ IMG_TAB_SEL_R ].i;
503 s = g_imagecache [ IMG_TAB_UNSEL_R ].i;
507 // normal (not leftmost) tab
509 if ( col == ui_category ) {
510 s = g_imagecache [ IMG_TAB_SEL ].i;
512 s = g_imagecache [ IMG_TAB_UNSEL ].i;
515 } // first col, or not first col?
522 if ( col == ui_category ) {
523 src.h = tab_selheight;
531 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
532 dest -> y = tab_offset_y;
535 ui_register_tab ( col, dest -> x, dest -> y, tab_width, tab_height );
537 if ( render_jobs_b & R_TABS ) {
538 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
539 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
543 if ( col == ui_category ) {
544 // no line for selected tab
546 if ( col - ui_catshift == 0 ) {
547 s = g_imagecache [ IMG_TAB_LINEL ].i;
548 } else if ( col - ui_catshift == maxtabspot - 1 ) {
549 s = g_imagecache [ IMG_TAB_LINER ].i;
551 s = g_imagecache [ IMG_TAB_LINE ].i;
553 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
554 dest -> y = tab_offset_y + tab_height;
555 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
561 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ] -> catname, c -> fontcolor );
564 src.w = rtext -> w < text_width ? rtext -> w : text_width;
566 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
567 dest -> y = tab_offset_y + text_offset_y;
568 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
569 SDL_FreeSurface ( rtext );
576 } // if we got categories
578 if ( render_jobs_b & R_TABS ) {
580 // draw tab lines under where tabs would be if we had categories
581 for ( /* foo */; col < maxtabspot; col++ ) {
584 if ( col - ui_catshift == 0 ) {
585 s = g_imagecache [ IMG_TAB_LINEL ].i;
586 } else if ( col - ui_catshift == maxtabspot - 1 ) {
587 s = g_imagecache [ IMG_TAB_LINER ].i;
589 s = g_imagecache [ IMG_TAB_LINE ].i;
591 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
592 dest -> y = tab_offset_y + tab_height;
593 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
602 // scroll bars and arrows
603 if ( render_jobs_b & R_BG ) {
604 unsigned char show_bar = 0;
607 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
608 dest -> x = c -> arrow_up_x;
609 dest -> y = c -> arrow_up_y;
610 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
617 if ( ui_rows_scrolled_down + c -> row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
618 dest -> x = c -> arrow_down_x;
619 dest -> y = c -> arrow_down_y;
620 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
627 // show scrollbar as well
630 src.w = c -> arrow_bar_clip_w;
631 src.h = c -> arrow_bar_clip_h;
632 dest -> x = c -> arrow_bar_x;
633 dest -> y = c -> arrow_bar_y;
634 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
638 } // r_bg, scroll bars
640 // render detail pane bg
641 if ( render_jobs_b & R_DETAIL && ui_detail_hidden == 0 ) {
643 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
646 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
647 src.x = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
648 src.y = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
649 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
650 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
651 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
652 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
653 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
657 // render detail pane
658 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
659 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
660 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
661 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
665 } // detailpane frame/bg
669 // anything to render?
670 if ( render_jobs_b & R_GRID && g_categorycount ) {
672 // if just rendering grid, and nothing else, better clear it first
673 if ( ! ( render_jobs_b & R_BG ) ) {
674 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
675 src.x = c -> grid_offset_x;
676 src.y = c -> grid_offset_y + c -> sel_icon_offset_y;
677 src.w = c -> col_max * c -> cell_width;
678 src.h = c -> row_max * c -> cell_height;
680 dest -> x = c -> grid_offset_x;
681 dest -> y = c -> grid_offset_y + c -> sel_icon_offset_y;
683 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
689 if ( g_categories [ ui_category ] -> refs ) {
691 appiter = g_categories [ ui_category ] -> refs;
695 // until we run out of apps, or run out of space
696 while ( appiter != NULL ) {
698 for ( col = 0; col < c -> col_max && appiter != NULL; col++ ) {
700 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
701 if ( row >= ui_rows_scrolled_down ) {
703 // selected? show hilights
704 if ( appiter == ui_selected ) {
705 SDL_Surface *s = g_imagecache [ IMG_SELECTED_ALPHAMASK ].i;
707 //dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + ( ( icon_max_width - s -> w ) / 2 );
708 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> icon_offset_x + c -> sel_icon_offset_x;
709 //dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + ( ( icon_max_height - s -> h ) / 2 );
710 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> icon_offset_y + c -> sel_icon_offset_y;
711 SDL_BlitSurface ( s, NULL /* all */, sdl_realscreen, dest );
714 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_clip_x;
715 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> text_hilite_offset_y;
716 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
721 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
722 SDL_Surface *iconsurface;
724 iconsurface = ic -> i;
726 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
728 // no icon override; was this a pnd-file (show the unknown icon then), or was this generated from
729 // filesystem (file or directory icon)
730 if ( appiter -> ref -> object_flags & PND_DISCO_GENERATED ) {
731 if ( appiter -> ref -> object_type == pnd_object_type_directory ) {
733 // is this a subcat, a .., or a filesystem folder?
734 //iconsurface = g_imagecache [ IMG_FOLDER ].i;
735 if ( g_categories [ ui_category ] -> fspath ) {
736 iconsurface = g_imagecache [ IMG_FOLDER ].i;
737 } else if ( strcmp ( appiter -> ref -> title_en, ".." ) == 0 ) {
738 iconsurface = g_imagecache [ IMG_DOTDOTFOLDER ].i;
740 iconsurface = g_imagecache [ IMG_SUBCATFOLDER ].i;
744 iconsurface = g_imagecache [ IMG_EXECBIN ].i;
747 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
752 // got an icon I hope?
754 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
760 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> icon_offset_x + (( c -> icon_max_width - iconsurface -> w ) / 2);
761 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> icon_offset_y + (( c -> icon_max_height - iconsurface -> h ) / 2);
763 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
766 ui_register_app ( appiter, dest -> x, dest -> y, src.w, src.h );
773 if ( appiter -> ref -> title_en ) {
775 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, c -> fontcolor );
778 src.w = c -> text_width < rtext -> w ? c -> text_width : rtext -> w;
780 if ( rtext -> w > c -> text_width ) {
781 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_clip_x;
783 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_offset_x - ( rtext -> w / 2 );
785 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> text_offset_y;
786 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
787 SDL_FreeSurface ( rtext );
791 } // display now? or scrolled away..
794 appiter = appiter -> next;
796 } // for column 1...X
798 if ( row >= ui_rows_scrolled_down ) {
804 // are we done displaying rows?
805 if ( displayrow >= c -> row_max ) {
812 // no apps to render?
813 pnd_log ( pndn_rem, "No applications to render?\n" );
818 // detail panel - show app details or blank-message
819 if ( render_jobs_b & R_DETAIL && ui_detail_hidden == 0 ) {
821 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
822 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
823 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
825 unsigned int desty = cell_offset_y;
832 if ( ui_selected -> ref -> title_en ) {
834 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, c -> fontcolor );
837 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
839 dest -> x = cell_offset_x;
841 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
842 SDL_FreeSurface ( rtext );
849 if ( ui_selected -> ref -> main_category ) {
851 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
854 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
857 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
859 dest -> x = cell_offset_x;
861 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
862 SDL_FreeSurface ( rtext );
869 if ( ui_selected -> ref -> clockspeed ) {
871 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
874 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
877 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
879 dest -> x = cell_offset_x;
881 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
882 SDL_FreeSurface ( rtext );
887 // show sub-app# on right side of cpu clock?
888 //if ( ui_selected -> ref -> subapp_number )
890 sprintf ( buffer, "(app#%u)", ui_selected -> ref -> subapp_number );
893 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
894 dest -> x = cell_offset_x + cell_width - rtext -> w;
895 dest -> y = desty - src.h;
896 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
897 SDL_FreeSurface ( rtext );
902 #if 0 // merged into hint-line
903 if ( ui_selected -> ref -> info_filename ) {
905 sprintf ( buffer, "Documentation - hit Y" );
908 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
911 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
913 dest -> x = cell_offset_x;
915 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
916 SDL_FreeSurface ( rtext );
923 if ( ui_selected -> ovrh ) {
928 desty += 5; // a touch of spacing can't hurt
930 for ( i = 1; i < 4; i++ ) {
931 sprintf ( buffer, "Application-%u.note-%u", ui_selected -> ref -> subapp_number, i );
932 n = pnd_conf_get_as_char ( ui_selected -> ovrh, buffer );
936 rtext = TTF_RenderText_Blended ( g_detailtext_font, n, c -> fontcolor );
939 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
941 dest -> x = cell_offset_x;
943 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
944 SDL_FreeSurface ( rtext );
950 } // r_detail -> notes
953 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
954 SDL_Surface *previewpic;
957 previewpic = ic -> i;
959 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
963 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
964 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
965 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
966 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
972 char *empty_message = "Press SELECT for menu";
976 rtext = TTF_RenderText_Blended ( g_detailtext_font, empty_message, c -> fontcolor );
980 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
982 dest -> x = cell_offset_x;
984 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
985 SDL_FreeSurface ( rtext );
990 rtext = TTF_RenderText_Blended ( g_detailtext_font, "START or B to run app", c -> fontcolor );
991 dest -> x = cell_offset_x;
993 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
994 SDL_FreeSurface ( rtext );
998 rtext = TTF_RenderText_Blended ( g_detailtext_font, "SPACE for app menu", c -> fontcolor );
999 dest -> x = cell_offset_x;
1001 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1002 SDL_FreeSurface ( rtext );
1006 rtext = TTF_RenderText_Blended ( g_detailtext_font, "A to toggle details", c -> fontcolor );
1007 dest -> x = cell_offset_x;
1009 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1010 SDL_FreeSurface ( rtext );
1014 } // r_detail && selected?
1022 if ( render_jobs_b & R_BG ) {
1023 static int last_battlevel = 0;
1024 static unsigned char batterylevel = 0;
1025 char buffer [ 100 ];
1027 if ( time ( NULL ) - last_battlevel > 60 ) {
1028 batterylevel = pnd_device_get_battery_gauge_perc();
1029 last_battlevel = time ( NULL );
1032 sprintf ( buffer, "Battery: %u%%", batterylevel );
1035 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1036 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.battery_x", 20 );
1037 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
1038 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1039 SDL_FreeSurface ( rtext );
1044 if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
1046 unsigned int hintx, hinty;
1047 hintx = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
1048 hinty = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
1049 static unsigned int lastwidth = 3000;
1051 if ( ui_selected && ui_selected -> ref -> info_filename ) {
1052 buffer = "Documentation - hit Y";
1054 buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
1058 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1061 if ( ! ( render_jobs_b & R_BG ) ) {
1068 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, &src, sdl_realscreen, dest );
1070 lastwidth = rtext -> w;
1076 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1077 SDL_FreeSurface ( rtext );
1082 if ( render_jobs_b & R_BG &&
1083 pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 )
1087 time_t t = time ( NULL );
1088 struct tm *tm = localtime ( &t );
1089 strftime ( buffer, 50, "%a %H:%M %F", tm );
1092 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1093 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.clock_x", 700 );
1094 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.clock_y", 450 );
1095 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1096 SDL_FreeSurface ( rtext );
1100 // update all the rects and send it all to sdl
1101 // - at this point, we could probably just do 1 rect, of the
1102 // whole screen, and be faster :/
1103 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1107 void ui_process_input ( pnd_dbusnotify_handle dbh, pnd_notify_handle nh ) {
1110 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
1111 //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
1113 while ( ( ! ui_event ) &&
1114 /*block_p ?*/ SDL_WaitEvent ( &event ) /*: SDL_PollEvent ( &event )*/ )
1117 switch ( event.type ) {
1122 // the user-defined SDL events are all for threaded/delayed previews (and icons, which
1123 // generally are not used); if we're in wide mode, we can skip previews
1124 // to avoid slowing things down when they're not shown.
1126 if ( event.user.code == sdl_user_ticker ) {
1128 if ( ui_detail_hidden ) {
1129 break; // skip building previews when not showing them
1132 // timer went off, time to load something
1133 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1135 if ( ! ui_selected ) {
1139 // load the preview pics now!
1140 pnd_disco_t *iter = ui_selected -> ref;
1142 if ( iter -> preview_pic1 ) {
1144 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.threaded_preview", 0 ) ) {
1145 // load in bg thread, make user experience chuggy
1147 g_preview_thread = SDL_CreateThread ( (void*)ui_threaded_defered_preview, iter );
1149 if ( ! g_preview_thread ) {
1150 pnd_log ( pndn_error, "ERROR: Couldn't create preview thread\n" );
1154 // load it now, make user wait
1156 if ( ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
1157 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
1160 pnd_log ( pndn_debug, " Couldn't load preview pic: '%s' -> '%s'\n",
1161 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1166 } // got a preview at all?
1171 } else if ( event.user.code == sdl_user_finishedpreview ) {
1173 // if we just finished the one we happen to be looking at, better redraw now; otherwise, if
1174 // we finished another, no big woop
1175 if ( ui_selected && event.user.data1 == ui_selected -> ref ) {
1179 } else if ( event.user.code == sdl_user_finishedicon ) {
1180 // redraw, so we can show the newly loaded icon
1183 } else if ( event.user.code == sdl_user_checksd ) {
1184 // check if any inotify-type events occured, forcing us to rescan/re-disco the SDs
1186 unsigned char watch_dbus = 0;
1187 unsigned char watch_inotify = 0;
1190 watch_dbus = pnd_dbusnotify_rediscover_p ( dbh );
1194 watch_inotify = pnd_notify_rediscover_p ( nh );
1197 if ( watch_dbus || watch_inotify ) {
1198 pnd_log ( pndn_debug, "dbusnotify detected SD event\n" );
1199 applications_free();
1200 applications_scan();
1207 render_mask |= CHANGED_EVERYTHING;
1211 #if 0 // joystick motion
1212 case SDL_JOYAXISMOTION:
1214 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
1216 if ( event.jaxis.axis == 0 ) {
1218 if ( event.jaxis.value < 0 ) {
1220 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
1221 } else if ( event.jaxis.value > 0 ) {
1222 ui_push_right ( 0 );
1223 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
1225 } else if ( event.jaxis.axis == 1 ) {
1227 if ( event.jaxis.value < 0 ) {
1229 } else if ( event.jaxis.value > 0 ) {
1239 #if 0 // joystick buttons
1240 case SDL_JOYBUTTONDOWN:
1242 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
1244 if ( event.jbutton.button == 0 ) { // B
1246 } else if ( event.jbutton.button == 1 ) { // Y
1248 } else if ( event.jbutton.button == 2 ) { // X
1250 } else if ( event.jbutton.button == 3 ) { // A
1253 } else if ( event.jbutton.button == 4 ) { // Select
1254 ui_mask |= uisb_select;
1255 } else if ( event.jbutton.button == 5 ) { // Start
1256 ui_mask |= uisb_start;
1258 } else if ( event.jbutton.button == 7 ) { // L
1260 } else if ( event.jbutton.button == 8 ) { // R
1269 case SDL_JOYBUTTONUP:
1271 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
1273 if ( event.jbutton.button == 0 ) { // B
1276 } else if ( event.jbutton.button == 1 ) { // Y
1278 } else if ( event.jbutton.button == 2 ) { // X
1280 } else if ( event.jbutton.button == 3 ) { // A
1283 } else if ( event.jbutton.button == 4 ) { // Select
1284 ui_mask &= ~uisb_select;
1285 } else if ( event.jbutton.button == 5 ) { // Start
1286 ui_mask &= ~uisb_start;
1288 } else if ( event.jbutton.button == 7 ) { // L
1291 } else if ( event.jbutton.button == 8 ) { // R
1302 #if 1 // keyboard events
1306 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
1308 // SDLK_LALT -> Start
1309 // page up/down for y/x
1310 // home/end for a and b
1313 if ( event.key.keysym.sym == SDLK_RIGHT ) {
1314 ui_push_right ( 0 );
1316 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
1319 } else if ( event.key.keysym.sym == SDLK_UP ) {
1322 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1325 } else if ( event.key.keysym.sym == SDLK_END ) { // B
1328 } else if ( event.key.keysym.sym == SDLK_SPACE ) { // space
1329 if ( ui_selected ) {
1330 ui_menu_context ( ui_selected );
1332 // TBD: post an error?
1334 render_mask |= CHANGED_EVERYTHING;
1336 } else if ( event.key.keysym.sym == SDLK_TAB || event.key.keysym.sym == SDLK_HOME ) { // tab or A
1337 // if detail panel is togglable, then toggle it
1338 // if not, make sure its ruddy well shown!
1339 if ( ui_is_detail_hideable() ) {
1340 ui_toggle_detail_pane();
1342 ui_detail_hidden = 0;
1345 } else if ( event.key.keysym.sym == SDLK_RSHIFT || event.key.keysym.sym == SDLK_COMMA ) { // left trigger or comma
1348 } else if ( event.key.keysym.sym == SDLK_RCTRL || event.key.keysym.sym == SDLK_PERIOD ) { // right trigger or period
1352 } else if ( event.key.keysym.sym == SDLK_PAGEUP ) { // Y
1354 if ( ui_selected ) {
1355 ui_show_info ( pnd_run_script, ui_selected -> ref );
1358 } else if ( event.key.keysym.sym == SDLK_PAGEDOWN ) { // X
1361 // forget the selection, nolonger applies
1363 ui_set_selected ( ui_selected );
1365 if ( g_categories [ ui_category ] -> fspath ) {
1366 category_fs_restock ( g_categories [ ui_category ] );
1369 render_mask |= CHANGED_EVERYTHING;
1372 } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
1376 } else if ( event.key.keysym.sym == SDLK_LCTRL /*LALT*/ ) { // select button
1377 char *opts [ 20 ] = {
1378 "Reveal hidden category",
1380 "Configure Minimenu",
1381 "Manage custom app categories",
1382 "Rescan for applications",
1383 "Cache previews to SD now",
1384 "Run a terminal/console",
1385 "Run another GUI (xfce, etc)",
1387 "Select a Minimenu skin",
1390 int sel = ui_modal_single_menu ( opts, 11, "Minimenu", "Enter to select; other to return." );
1392 char buffer [ 100 ];
1396 } else if ( sel == 1 ) {
1398 sprintf ( buffer, "sudo poweroff" );
1400 } else if ( sel == 2 ) {
1402 unsigned char restart = conf_run_menu ( NULL );
1403 conf_write ( g_conf, conf_determine_location ( g_conf ) );
1405 emit_and_quit ( MM_RESTART );
1407 } else if ( sel == 3 ) {
1408 // manage custom categories
1409 ui_manage_categories();
1410 } else if ( sel == 4 ) {
1412 pnd_log ( pndn_debug, "Freeing up applications\n" );
1413 applications_free();
1414 pnd_log ( pndn_debug, "Rescanning applications\n" );
1415 applications_scan();
1416 } else if ( sel == 5 ) {
1417 // cache preview to SD now
1418 extern pnd_box_handle g_active_apps;
1419 pnd_box_handle h = g_active_apps;
1421 unsigned int maxwidth, maxheight;
1422 maxwidth = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 );
1423 maxheight = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 );
1425 pnd_disco_t *iter = pnd_box_get_head ( h );
1430 if ( ! cache_preview ( iter, maxwidth, maxheight ) ) {
1431 pnd_log ( pndn_debug, "Force cache: Couldn't load preview pic: '%s' -> '%s'\n",
1432 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1436 iter = pnd_box_get_next ( iter );
1439 } else if ( sel == 6 ) {
1442 argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
1446 ui_forkexec ( argv );
1449 } else if ( sel == 7 ) {
1450 char buffer [ PATH_MAX ];
1451 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/pandora/scripts/op_switchgui.sh" );
1452 emit_and_quit ( buffer );
1453 } else if ( sel == 8 ) {
1454 emit_and_quit ( MM_QUIT );
1455 } else if ( sel == 9 ) {
1457 if ( ui_pick_skin() ) {
1458 emit_and_quit ( MM_RESTART );
1460 } else if ( sel == 10 ) {
1462 char buffer [ PATH_MAX ];
1463 sprintf ( buffer, "%s/about.txt", g_skinpath );
1464 ui_aboutscreen ( buffer );
1468 render_mask |= CHANGED_EVERYTHING;
1471 // unknown SDLK_ keycode?
1473 // many SDLK_keycodes map to ASCII ("a" is ascii(a)), so try to jump to a filename of that name, in this category?
1474 // and if already there, try to jump to next, maybe?
1475 // future: look for sequence typing? ie: user types 'm' then 'a', look for 'ma*' instead of 'm' then 'a' matching
1476 if ( isalpha ( event.key.keysym.sym ) && g_categories [ ui_category ] -> refcount > 0 ) {
1477 mm_appref_t *app = g_categories [ ui_category ] -> refs;
1479 //fprintf ( stderr, "sel %s next %s\n", ui_selected -> ref -> title_en, ui_selected -> next -> ref -> title_en );
1481 // are we already matching the same char? and next item is also same char?
1482 if ( app && ui_selected && ui_selected -> next &&
1483 ui_selected -> ref -> title_en && ui_selected -> next -> ref -> title_en &&
1484 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( ui_selected -> next -> ref -> title_en [ 0 ] ) &&
1485 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym )
1488 // just skip down one
1489 app = ui_selected -> next;
1492 // walk the category, looking for a first-char match
1494 if ( app -> ref -> title_en && toupper ( app -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym ) ) {
1500 } // same start letter, or new run?
1502 // found something, or no?
1504 // looks like we found a potential match; try switching it to visible selection
1506 ui_set_selected ( ui_selected );
1511 } // SDLK_alphanumeric?
1517 if ( event.key.keysym.sym == SDLK_ESCAPE ) {
1518 emit_and_quit ( MM_QUIT );
1525 #if 1 // mouse / touchscreen
1527 case SDL_MOUSEBUTTONDOWN:
1528 if ( event.button.button == SDL_BUTTON_LEFT ) {
1529 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
1535 case SDL_MOUSEBUTTONUP:
1536 if ( event.button.button == SDL_BUTTON_LEFT ) {
1537 ui_touch_act ( event.button.x, event.button.y );
1550 } // switch event type
1557 void ui_push_left ( unsigned char forcecoil ) {
1559 if ( ! ui_selected ) {
1560 ui_push_right ( 0 );
1564 // what column we in?
1565 unsigned int col = ui_determine_screen_col ( ui_selected );
1567 // are we already at first item?
1568 if ( forcecoil == 0 &&
1569 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1572 unsigned int i = ui_display_context.col_max - 1;
1573 while ( i && ui_selected -> next ) {
1574 ui_push_right ( 0 );
1578 } else if ( g_categories [ ui_category ] -> refs == ui_selected ) {
1579 // can't go any more left, we're at the head
1582 // figure out the previous item; yay for singly linked list :/
1583 mm_appref_t *i = g_categories [ ui_category ] -> refs;
1585 if ( i -> next == ui_selected ) {
1593 ui_set_selected ( ui_selected );
1598 void ui_push_right ( unsigned char forcecoil ) {
1600 if ( ui_selected ) {
1602 // what column we in?
1603 unsigned int col = ui_determine_screen_col ( ui_selected );
1606 if ( forcecoil == 0 &&
1607 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1608 // and selected is far-right, or last icon in category (might not be far right)
1609 ( ( col == ui_display_context.col_max - 1 ) ||
1610 ( ui_selected -> next == NULL ) )
1614 //unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1615 while ( col /*i*/ ) {
1621 // just go to the next
1623 if ( ui_selected -> next ) {
1624 ui_selected = ui_selected -> next;
1630 ui_selected = g_categories [ ui_category ] -> refs;
1633 ui_set_selected ( ui_selected );
1638 void ui_push_up ( void ) {
1639 unsigned char col_max = ui_display_context.col_max;
1641 if ( ! ui_selected ) {
1646 unsigned int row = ui_determine_row ( ui_selected );
1649 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 0 ) == 0 )
1651 // wrap around instead
1653 unsigned int col = ui_determine_screen_col ( ui_selected );
1656 ui_selected = g_categories [ ui_category ] -> refs;
1657 while ( ui_selected -> next ) {
1658 ui_selected = ui_selected -> next;
1661 // try to move to same column
1662 unsigned int newcol = ui_determine_screen_col ( ui_selected );
1663 if ( newcol > col ) {
1671 // scroll down to show it
1672 int r = ui_determine_row ( ui_selected ) - 1;
1673 if ( r - ui_display_context.row_max > 0 ) {
1674 ui_rows_scrolled_down = (unsigned int) r;
1678 // stop at top/bottom
1690 void ui_push_down ( void ) {
1691 unsigned char col_max = ui_display_context.col_max;
1693 if ( ui_selected ) {
1696 unsigned int row = ui_determine_row ( ui_selected );
1699 unsigned int icon_rows = g_categories [ ui_category ] -> refcount / col_max;
1700 if ( g_categories [ ui_category ] -> refcount % col_max > 0 ) {
1705 if ( row == ( icon_rows - 1 ) &&
1706 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 0 ) == 0 )
1709 unsigned char col = ui_determine_screen_col ( ui_selected );
1711 ui_selected = g_categories [ ui_category ] -> refs;
1714 ui_selected = ui_selected -> next;
1718 ui_rows_scrolled_down = 0;
1720 render_mask |= CHANGED_EVERYTHING;
1725 ui_push_right ( 1 );
1732 ui_push_right ( 0 );
1738 // 'backup' is currently 'X', for going back up in a folder/subcat without having to hit exec on the '..' entry
1739 void ui_push_backup ( void ) {
1741 // a subcat-as-dir, or a dir browser?
1742 if ( g_categories [ ui_category] -> fspath ) {
1743 // dir browser, just climb our way back up
1748 // lop off last word; if the thing ends with /, lop that one, then the next word.
1749 while ( ( c = strrchr ( g_categories [ ui_category] -> fspath, '/' ) ) ) {
1750 *c = '\0'; // lop off the last hunk
1751 if ( *(c+1) != '\0' ) {
1757 if ( g_categories [ ui_category] -> fspath [ 0 ] == '\0' ) {
1758 free ( g_categories [ ui_category] -> fspath );
1759 g_categories [ ui_category] -> fspath = strdup ( "/" );
1763 // a pnd subcat .. are we in one, or at the 'top'?
1764 char *pcatname = g_categories [ ui_category ] -> parent_catname;
1767 return; // we're at the 'top' already
1770 // set to first cat!
1773 // republish cats .. shoudl just be the one
1774 category_publish ( CFNORMAL, NULL );
1777 ui_category = category_index ( pcatname );
1779 // ensure tab visible?
1780 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1781 if ( ui_category > ui_catshift + ( ui_display_context.screen_width / tab_width ) - 1 ) {
1782 ui_catshift = ui_category - ( ui_display_context.screen_width / tab_width ) + 1;
1792 void ui_push_exec ( void ) {
1794 if ( ! ui_selected ) {
1798 // was this icon generated from filesystem, or from pnd-file?
1799 if ( ui_selected -> ref -> object_flags & PND_DISCO_GENERATED ) {
1801 if ( ! ui_selected -> ref -> title_en ) {
1802 return; // no filename
1805 if ( ui_selected -> ref -> object_type == pnd_object_type_directory ) {
1807 // check if this guy is a dir-browser tab, or is a directory on a pnd tab
1808 if ( ! g_categories [ ui_category] -> fspath ) {
1809 // pnd subcat as dir
1811 // are we already in a subcat? if so, go back to parent; there is no grandparenting or deeper
1812 if ( g_categories [ ui_category ] -> parent_catname ) {
1817 // delve into subcat
1819 // set to first cat!
1823 // republish cats .. shoudl just be the one
1824 category_publish ( CFBYNAME, ui_selected -> ref -> object_path );
1828 // forget the selection, nolonger applies
1830 ui_set_selected ( ui_selected );
1832 render_mask |= CHANGED_EVERYTHING;
1836 // delve up/down the dir tree
1837 if ( strcmp ( ui_selected -> ref -> title_en, ".." ) == 0 ) {
1842 char *temp = malloc ( strlen ( g_categories [ ui_category] -> fspath ) + strlen ( ui_selected -> ref -> title_en ) + 1 + 1 );
1843 sprintf ( temp, "%s/%s", g_categories [ ui_category] -> fspath, ui_selected -> ref -> title_en );
1844 free ( g_categories [ ui_category] -> fspath );
1845 g_categories [ ui_category] -> fspath = temp;
1848 pnd_log ( pndn_debug, "Cat %s is now in path %s\n", g_categories [ ui_category ] -> catname, g_categories [ ui_category ]-> fspath );
1850 // forget the selection, nolonger applies
1852 ui_set_selected ( ui_selected );
1854 category_fs_restock ( g_categories [ ui_category ] );
1856 render_mask |= CHANGED_SELECTION;
1858 } // directory browser or pnd subcat?
1861 // just run it arbitrarily?
1863 // if this a pnd-file, or just some executable?
1864 if ( strcasestr ( ui_selected -> ref -> object_filename, PND_PACKAGE_FILEEXT ) ) {
1865 // looks like a pnd, now what do we do..
1866 pnd_box_handle h = pnd_disco_file ( ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
1869 pnd_disco_t *d = pnd_box_get_head ( h );
1870 pnd_apps_exec_disco ( pnd_run_script, d, PND_EXEC_OPTION_NORUN, NULL );
1871 char buffer [ PATH_MAX ];
1872 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1873 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
1874 emit_and_quit ( buffer );
1876 emit_and_run ( buffer );
1883 // is it even executable? if we don't have handlers for non-executables yet (Jan 2011 we don't),
1884 // then don't even try to run things not-flagged as executable.. but wait most people are on
1885 // FAT filesystems, what a drag, we can't tell at the fs level.
1886 // ... but we can still invoke 'file' and grep out the good bits, at least.
1888 // open a stream reading 'file /path/to/file' and check output for 'executable'
1889 // -- not checking for "ARM" so it can pick up x86 (or whatever native) executables in build environment
1890 unsigned char is_executable = 0;
1894 char popenbuf [ FILENAME_MAX ];
1895 snprintf ( popenbuf, FILENAME_MAX, "%s %s/%s", MIMETYPE_EXE, g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
1898 if ( ! ( marceau = popen ( popenbuf, "r" ) ) ) {
1899 return; // error, we need some useful error handling and dialog boxes here
1902 if ( fgets ( popenbuf, FILENAME_MAX, marceau ) ) {
1903 //printf ( "File test returns: %s\n", popenbuf );
1904 if ( strstr ( popenbuf, "executable" ) != NULL ) {
1913 if ( ! is_executable ) {
1914 fprintf ( stderr, "ERROR: File to invoke is not executable, skipping. (%s)\n", ui_selected -> ref -> title_en );
1915 return; // need some error handling here
1918 #if 0 // eat up any pending SDL events and toss 'em?
1922 while ( SDL_PeepEvents ( &e, 1, SDL_GETEVENT, SDL_ALLEVENTS ) > 0 ) {
1932 // get CWD so we can restore it on return
1933 char cwd [ PATH_MAX ];
1934 getcwd ( cwd, PATH_MAX );
1936 // full path to executable so we don't rely on implicit "./"
1937 char execbuf [ FILENAME_MAX ];
1938 snprintf ( execbuf, FILENAME_MAX, "%s/%s", g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
1941 chdir ( g_categories [ ui_category ] -> fspath );
1942 exec_raw_binary ( execbuf /*ui_selected -> ref -> title_en*/ );
1945 // DEPRECATED / NOT TESTED
1946 // get mmwrapper to run it
1947 char buffer [ PATH_MAX ];
1948 sprintf ( buffer, "%s %s/%s\n", MM_RUN, g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
1949 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
1950 emit_and_quit ( buffer );
1952 emit_and_run ( buffer );
1961 // set app-run speed
1962 int use_run_speed = pnd_conf_get_as_int_d ( g_conf, "minimenu.use_run_speed", 0 );
1963 if ( use_run_speed > 0 ) {
1964 int mm_speed = pnd_conf_get_as_int_d ( g_conf, "minimenu.run_speed", -1 );
1965 if ( mm_speed > -1 ) {
1966 char buffer [ 512 ];
1967 snprintf ( buffer, 500, "sudo /usr/pandora/scripts/op_cpuspeed.sh %d", mm_speed );
1970 } // do speed change?
1972 // request app to run and quit mmenu
1973 pnd_apps_exec_disco ( pnd_run_script, ui_selected -> ref, PND_EXEC_OPTION_NORUN, NULL );
1974 char buffer [ PATH_MAX ];
1975 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1976 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
1977 emit_and_quit ( buffer );
1979 emit_and_run ( buffer );
1986 void ui_push_ltrigger ( void ) {
1987 unsigned char oldcat = ui_category;
1988 unsigned int screen_width = ui_display_context.screen_width;
1989 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1991 if ( g_categorycount == 0 ) {
1995 if ( g_icon_thread_busy ) {
1996 ui_stop_defered_icon_thread();
1999 if ( ui_category > 0 ) {
2001 category_fs_restock ( g_categories [ ui_category ] );
2003 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
2004 ui_category = g_categorycount - 1;
2006 if ( ui_category >= ( screen_width / tab_width ) ) {
2007 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
2009 category_fs_restock ( g_categories [ ui_category ] );
2013 if ( oldcat != ui_category ) {
2015 ui_set_selected ( ui_selected );
2018 // make tab visible?
2019 if ( ui_catshift > 0 && ui_category == ui_catshift - 1 ) {
2024 ui_rows_scrolled_down = 0;
2026 render_mask |= CHANGED_CATEGORY;
2027 ui_start_defered_icon_thread();
2032 void ui_push_rtrigger ( void ) {
2033 unsigned char oldcat = ui_category;
2035 if ( g_categorycount == 0 ) {
2039 if ( g_icon_thread_busy ) {
2040 ui_stop_defered_icon_thread();
2043 unsigned int screen_width = ui_display_context.screen_width;
2044 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2046 if ( ui_category < ( g_categorycount - 1 ) ) {
2048 category_fs_restock ( g_categories [ ui_category ] );
2050 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
2053 category_fs_restock ( g_categories [ ui_category ] );
2057 if ( oldcat != ui_category ) {
2059 ui_set_selected ( ui_selected );
2062 // make tab visible?
2063 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2068 ui_rows_scrolled_down = 0;
2070 render_mask |= CHANGED_CATEGORY;
2071 ui_start_defered_icon_thread();
2076 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
2077 double scale = 1000000.0;
2078 double scalex = 1000000.0;
2079 double scaley = 1000000.0;
2080 SDL_Surface *scaled;
2082 scalex = (double)maxwidth / (double)s -> w;
2084 if ( maxheight == -1 ) {
2087 scaley = (double)maxheight / (double)s -> h;
2089 if ( scaley < scalex ) {
2097 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
2098 SDL_FreeSurface ( s );
2104 void ui_loadscreen ( void ) {
2109 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2113 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", ui_display_context.fontcolor );
2116 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
2117 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2118 SDL_FreeSurface ( rtext );
2123 void ui_discoverscreen ( unsigned char clearscreen ) {
2128 if ( clearscreen ) {
2129 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2131 // render background
2132 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2135 dest.w = sdl_realscreen -> w;
2136 dest.h = sdl_realscreen -> h;
2137 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
2138 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2145 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", ui_display_context.fontcolor );
2146 if ( clearscreen ) {
2153 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
2154 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2155 SDL_FreeSurface ( rtext );
2158 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
2159 dest.x = rtext -> w + 30;
2161 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
2162 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2168 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
2170 SDL_Rect rects [ 4 ];
2171 SDL_Rect *dest = rects;
2173 bzero ( dest, sizeof(SDL_Rect)* 4 );
2175 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
2176 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
2177 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
2178 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
2180 static unsigned int stepx = 0;
2183 if ( clearscreen ) {
2184 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2186 // render background
2187 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2190 dest -> w = sdl_realscreen -> w;
2191 dest -> h = sdl_realscreen -> h;
2192 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
2198 // render background
2199 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2202 src.w = sdl_realscreen -> w;
2206 dest -> w = sdl_realscreen -> w;
2207 dest -> h = sdl_realscreen -> h;
2208 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
2216 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
2217 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
2220 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2221 SDL_FreeSurface ( rtext );
2225 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
2226 dest -> x = rtext -> w + 30 + stepx;
2228 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
2234 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
2237 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2238 SDL_FreeSurface ( rtext );
2245 if ( stepx > 350 ) {
2249 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
2254 int ui_selected_index ( void ) {
2256 if ( ! ui_selected ) {
2257 return ( -1 ); // no index
2260 mm_appref_t *r = g_categories [ ui_category ] -> refs;
2263 if ( r == ui_selected ) {
2273 static mm_appref_t *timer_ref = NULL;
2274 void ui_set_selected ( mm_appref_t *r ) {
2276 render_mask |= CHANGED_SELECTION;
2278 if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
2279 return; // no desire to defer anything
2284 SDL_SetTimer ( 0, NULL );
2289 SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
2295 unsigned int ui_callback_f ( unsigned int t ) {
2297 if ( ui_selected != timer_ref ) {
2298 return ( 0 ); // user has moved it, who cares
2302 bzero ( &e, sizeof(SDL_Event) );
2303 e.type = SDL_USEREVENT;
2304 e.user.code = sdl_user_ticker;
2305 SDL_PushEvent ( &e );
2310 int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
2311 SDL_Rect rects [ 40 ];
2312 SDL_Rect *dest = rects;
2315 unsigned char max_visible = pnd_conf_get_as_int_d ( g_conf, "detailtext.max_visible" , 11 );
2316 unsigned char first_visible = 0;
2318 bzero ( rects, sizeof(SDL_Rect) * 40 );
2320 unsigned int sel = 0;
2322 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 };
2330 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2331 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2332 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
2333 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
2334 SDL_FillRect( sdl_realscreen, dest, 0 );
2336 // show dialog background
2337 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
2340 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> w;
2341 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> h;
2342 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2343 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2344 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2345 // repeat for darken?
2346 //SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2347 //SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2348 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2352 // show dialog frame
2353 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
2354 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2355 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2356 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
2357 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2363 rtext = TTF_RenderText_Blended ( g_tab_font, title, ui_display_context.fontcolor );
2364 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2365 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
2366 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2367 SDL_FreeSurface ( rtext );
2373 rtext = TTF_RenderText_Blended ( g_tab_font, footer, ui_display_context.fontcolor );
2374 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2375 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
2376 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
2378 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2379 SDL_FreeSurface ( rtext );
2384 for ( i = first_visible; i < first_visible + max_visible && i < argc; i++ ) {
2388 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
2390 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], ui_display_context.fontcolor );
2392 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2393 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 - first_visible ) );
2394 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2395 SDL_FreeSurface ( rtext );
2400 // update all the rects and send it all to sdl
2401 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
2405 while ( SDL_WaitEvent ( &event ) ) {
2407 switch ( event.type ) {
2412 if ( event.key.keysym.sym == SDLK_UP ) {
2416 if ( sel < first_visible ) {
2421 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
2423 if ( sel < argc - 1 ) {
2426 // ensure visibility
2427 if ( sel >= first_visible + max_visible ) {
2433 } else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_END ) { // return, or "B"
2437 } else if ( event.key.keysym.sym == SDLK_q ) {
2442 return ( -1 ); // nada
2457 unsigned char ui_determine_row ( mm_appref_t *a ) {
2458 unsigned int row = 0;
2460 mm_appref_t *i = g_categories [ ui_category ] -> refs;
2465 row /= ui_display_context.col_max;
2470 unsigned char ui_determine_screen_row ( mm_appref_t *a ) {
2471 return ( ui_determine_row ( a ) % ui_display_context.row_max );
2474 unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
2475 unsigned int col = 0;
2477 mm_appref_t *i = g_categories [ ui_category ] -> refs;
2482 col %= ui_display_context.col_max;
2487 unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ) {
2488 char *viewer, *searchpath;
2489 pnd_conf_handle desktoph;
2492 searchpath = pnd_conf_query_searchpath();
2494 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
2500 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
2503 return ( 0 ); // no way to view the file
2507 if ( ! p -> unique_id ) {
2511 if ( ! p -> info_filename ) {
2515 if ( ! p -> info_name ) {
2526 if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
2527 snprintf ( pargs, 1001, "%s %s",
2528 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
2533 char pndfile [ 1024 ];
2534 if ( p -> object_type == pnd_object_type_directory ) {
2535 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
2536 strncpy ( pndfile, p -> object_path, 1000 );
2537 } else if ( p -> object_type == pnd_object_type_pnd ) {
2538 // pnd_run.sh wants the full path and filename for the .pnd file
2539 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
2542 if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
2543 p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
2548 pnd_log ( pndn_debug, "Info Exec=%s\n", pnd_apps_exec_runline() );
2552 if ( ( x = fork() ) < 0 ) {
2553 pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
2558 execl ( "/bin/sh", "/bin/sh", "-c", pnd_apps_exec_runline(), (char*)NULL );
2559 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", pnd_apps_exec_runline() );
2571 #define MAXTOUCH 100
2572 ui_touch_t ui_touchrects [ MAXTOUCH ];
2573 unsigned char ui_touchrect_count = 0;
2575 void ui_register_reset ( void ) {
2576 bzero ( ui_touchrects, sizeof(ui_touch_t)*MAXTOUCH );
2577 ui_touchrect_count = 0;
2581 void ui_register_tab ( unsigned char catnum, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2583 if ( ui_touchrect_count == MAXTOUCH ) {
2587 ui_touchrects [ ui_touchrect_count ].r.x = x;
2588 ui_touchrects [ ui_touchrect_count ].r.y = y;
2589 ui_touchrects [ ui_touchrect_count ].r.w = w;
2590 ui_touchrects [ ui_touchrect_count ].r.h = h;
2591 ui_touchrects [ ui_touchrect_count ].catnum = catnum;
2592 ui_touchrect_count++;
2597 void ui_register_app ( mm_appref_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2599 if ( ui_touchrect_count == MAXTOUCH ) {
2603 ui_touchrects [ ui_touchrect_count ].r.x = x;
2604 ui_touchrects [ ui_touchrect_count ].r.y = y;
2605 ui_touchrects [ ui_touchrect_count ].r.w = w;
2606 ui_touchrects [ ui_touchrect_count ].r.h = h;
2607 ui_touchrects [ ui_touchrect_count ].ref = app;
2608 ui_touchrect_count++;
2613 void ui_touch_act ( unsigned int x, unsigned int y ) {
2618 for ( i = 0; i < ui_touchrect_count; i++ ) {
2619 t = &(ui_touchrects [ i ]);
2621 if ( x >= t -> r.x &&
2622 x <= t -> r.x + t -> r.w &&
2624 y <= t -> r.y + t -> r.h
2629 ui_selected = t -> ref;
2632 if ( ui_category != t -> catnum ) {
2635 ui_category = t -> catnum;
2636 render_mask |= CHANGED_CATEGORY;
2638 category_fs_restock ( g_categories [ ui_category ] );
2639 ui_start_defered_icon_thread();
2650 unsigned char ui_forkexec ( char *argv[] ) {
2651 char *fooby = argv[0];
2654 if ( ( x = fork() ) < 0 ) {
2655 pnd_log ( pndn_error, "ERROR: Couldn't fork() for '%s'\n", fooby );
2659 if ( x == 0 ) { // child
2660 execv ( fooby, argv );
2661 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", fooby );
2669 unsigned char ui_threaded_timer_create ( void ) {
2671 g_timer_thread = SDL_CreateThread ( (void*)ui_threaded_timer, NULL );
2673 if ( ! g_timer_thread ) {
2674 pnd_log ( pndn_error, "ERROR: Couldn't create timer thread\n" );
2681 int ui_threaded_timer ( pnd_disco_t *p ) {
2683 // this timer's job is to ..
2684 // - do nothing for quite awhile
2685 // - on wake, post event to SDL event queue, so that main thread will check if SD insert/eject occurred
2688 unsigned int delay_s = 2; // seconds
2693 //sleep ( delay_s );
2694 SDL_Delay ( delay_s * 1000 );
2696 // .. trigger SD check
2698 bzero ( &e, sizeof(SDL_Event) );
2699 e.type = SDL_USEREVENT;
2700 e.user.code = sdl_user_checksd;
2701 SDL_PushEvent ( &e );
2708 unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
2710 if ( ! cache_preview ( p, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
2711 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
2714 pnd_log ( pndn_debug, "THREAD: Couldn't load preview pic: '%s' -> '%s'\n",
2715 IFNULL(p->title_en,"No Name"), p -> preview_pic1 );
2718 // trigger that we completed
2720 bzero ( &e, sizeof(SDL_Event) );
2721 e.type = SDL_USEREVENT;
2722 e.user.code = sdl_user_finishedpreview;
2724 SDL_PushEvent ( &e );
2729 void ui_post_scan ( void ) {
2733 ui_rows_scrolled_down = 0;
2734 // set back to first tab, to be safe
2738 // do we have a preferred category to jump to?
2739 char *dc = pnd_conf_get_as_char ( g_conf, "categories.default_cat" );
2742 // attempt to find default cat; if we do find it, select it; otherwise
2743 // default behaviour will pick first cat (ie: usually All)
2745 for ( i = 0; i < g_categorycount; i++ ) {
2746 if ( strcasecmp ( g_categories [ i ] -> catname, dc ) == 0 ) {
2748 // ensure visibility
2749 unsigned int screen_width = ui_display_context.screen_width;
2750 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2751 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2752 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
2758 if ( i == g_categorycount ) {
2759 pnd_log ( pndn_warning, " User defined default category '%s' but not found, so using default behaviour\n", dc );
2764 // if we're sent right to a dirbrowser tab, restock it now (normally we restock on entry)
2765 if ( g_categories [ ui_category ] -> fspath ) {
2766 printf ( "Restock on start: '%s'\n", g_categories [ ui_category ] -> fspath );
2767 category_fs_restock ( g_categories [ ui_category ] );
2771 render_mask |= CHANGED_EVERYTHING;
2773 // if deferred icon load, kick off the thread now
2774 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 1 ) {
2775 ui_start_defered_icon_thread();
2776 } // deferred icon load
2781 unsigned char ui_threaded_defered_icon ( void *p ) {
2782 extern pnd_box_handle g_active_apps;
2784 unsigned char maxwidth, maxheight;
2785 maxwidth = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 );
2786 maxheight = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_height", 50 );
2790 g_icon_thread_busy = 1;
2792 // work at it in order within current category
2794 mm_appref_t *refiter = g_categories [ ui_category ] -> refs;
2795 while ( refiter && ! g_icon_thread_stop ) {
2796 iter = refiter -> ref;
2798 // has an icon that is not already cached?
2799 if ( ( iter -> pnd_icon_pos ) ||
2800 ( iter -> icon && iter -> object_flags & PND_DISCO_CUSTOM1 )
2805 if ( ! cache_icon ( iter, maxwidth, maxheight ) ) {
2806 //pnd_log ( pndn_warning, " Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2810 // trigger that we completed
2812 bzero ( &e, sizeof(SDL_Event) );
2813 e.type = SDL_USEREVENT;
2814 e.user.code = sdl_user_finishedicon;
2815 SDL_PushEvent ( &e );
2817 //pnd_log ( pndn_warning, " Finished deferred load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2818 //usleep ( pnd_conf_get_as_int_d ( g_conf, "minimenu.defer_icon_us", 50000 ) );
2823 iter -> pnd_icon_pos = 0;
2824 if ( iter -> icon ) {
2825 free ( iter -> icon );
2826 iter -> icon = NULL;
2829 // let user do something..
2834 refiter = refiter -> next;
2838 g_icon_thread_busy = 0;
2843 void ui_show_hourglass ( unsigned char updaterect ) {
2846 SDL_Surface *s = g_imagecache [ IMG_HOURGLASS ].i;
2848 dest.x = ( 800 - s -> w ) / 2;
2849 dest.y = ( 480 - s -> h ) / 2;
2851 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, &dest );
2854 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2860 unsigned char ui_pick_skin ( void ) {
2862 char *skins [ MAXSKINS ];
2865 char *searchpath = pnd_conf_get_as_char ( g_conf, "minimenu.skin_searchpath" );
2866 char tempname [ 100 ];
2870 skins [ iter++ ] = "No skin change";
2874 DIR *d = opendir ( buffer );
2879 while ( ( dd = readdir ( d ) ) ) {
2881 if ( dd -> d_name [ 0 ] == '.' ) {
2883 } else if ( ( dd -> d_type == DT_DIR || dd -> d_type == DT_UNKNOWN ) &&
2886 snprintf ( tempname, 100, "Skin: %s", dd -> d_name );
2887 skins [ iter++ ] = strdup ( tempname );
2898 int sel = ui_modal_single_menu ( skins, iter, "Skins", "Enter to select; other to return." );
2900 // did they pick one?
2904 char *s = strdup ( pnd_conf_get_as_char ( g_conf, "minimenu.skin_selected" ) );
2905 s = pnd_expand_tilde ( s );
2907 f = fopen ( s, "w" );
2912 fprintf ( f, "%s\n", skins [ sel ] + 6 );
2922 void ui_aboutscreen ( char *textpath ) {
2929 #define ROWS SCRH / ( PIXELH + MARGINH )
2930 #define COLS SCRW / ( PIXELW + MARGINW )
2932 unsigned char pixelboard [ ROWS * COLS ]; // pixel heat
2933 bzero ( pixelboard, ROWS * COLS );
2938 SDL_Color rtextc = { 200, 200, 200, 100 };
2941 char *textloop [ 500 ];
2942 unsigned int textmax = 0;
2943 bzero ( textloop, 500 * sizeof(char*) );
2946 char cbuffer [ 50000 ];
2947 bzero ( cbuffer, 50000 );
2948 unsigned int crevealed = 0;
2950 FILE *f = fopen ( textpath, "r" );
2953 pnd_log ( pndn_error, "ERROR: Couldn't open about text: %s\n", textpath );
2957 char textbuf [ 100 ];
2958 while ( fgets ( textbuf, 100, f ) ) {
2960 // add to full buffer
2961 strncat ( cbuffer, textbuf, 50000 );
2964 if ( strchr ( textbuf, '\n' ) ) {
2965 * strchr ( textbuf, '\n' ) = '\0';
2968 // add to pixel loop
2969 if ( 1||textbuf [ 0 ] ) {
2970 textloop [ textmax ] = strdup ( textbuf );
2978 unsigned int textiter = 0;
2979 while ( textiter < textmax ) {
2980 char *text = textloop [ textiter ];
2984 // render to surface
2985 rtext = TTF_RenderText_Blended ( g_grid_font, text, rtextc );
2987 // render font to pixelboard
2988 unsigned int px, py;
2990 unsigned int *pixels = rtext -> pixels;
2991 unsigned char cr, cg, cb, ca;
2992 for ( py = 0; py < rtext -> h; py ++ ) {
2993 for ( px = 0; px < ( rtext -> w > COLS ? COLS : rtext -> w ); px++ ) {
2995 SDL_GetRGBA ( pixels [ ( py * rtext -> pitch / 4 ) + px ],
2996 rtext -> format, &cr, &cg, &cb, &ca );
3000 ph = pixelboard + ( /*y offset */ 30 * COLS ) + ( py * COLS ) + px /* / 2 */;
3007 if ( *ph + ca < 250 ) {
3018 unsigned int runcount = 10;
3019 while ( runcount-- ) {
3022 SDL_FillRect( sdl_realscreen, NULL /* whole */, 0 );
3024 // render pixelboard
3027 for ( y = 0; y < ROWS; y++ ) {
3028 for ( x = 0; x < COLS; x++ ) {
3030 if ( 1||pixelboard [ ( y * COLS ) + x ] ) {
3033 r.x = x * ( PIXELW + MARGINW );
3034 r.y = y * ( PIXELH + MARGINH );
3038 c = SDL_MapRGB ( sdl_realscreen -> format, 100 /* r */, 0 /* g */, pixelboard [ ( y * COLS ) + x ] );
3040 SDL_FillRect( sdl_realscreen, &r /* whole */, c );
3048 unsigned char *pc = pixelboard;
3049 for ( y = 0; y < ROWS; y++ ) {
3050 for ( x = 0; x < COLS; x++ ) {
3060 // slide pixels upwards
3061 memmove ( pixelboard, pixelboard + COLS, ( COLS * ROWS ) - COLS );
3063 // render actual readable text
3066 // display up to cursor
3068 unsigned int cdraw = 0;
3072 if ( crevealed > 200 ) {
3073 cdraw = crevealed - 200;
3079 for ( ; cdraw < crevealed; cdraw++ ) {
3080 ctb [ 0 ] = cbuffer [ cdraw ];
3082 // move over or down
3083 if ( cbuffer [ cdraw ] == '\n' ) {
3088 if ( dest.y > 450 ) {
3094 cs = TTF_RenderText_Blended ( g_tab_font, ctb, rtextc );
3096 SDL_BlitSurface ( cs, NULL /* all */, sdl_realscreen, &dest );
3097 SDL_FreeSurface ( cs );
3107 SDL_FillRect ( sdl_realscreen, &dest /* whole */, 220 );
3109 // increment cursor to next character
3110 if ( cbuffer [ crevealed ] != '\0' ) {
3114 } // draw cursor text
3118 SDL_UpdateRect ( sdl_realscreen, 0, 0, 0, 0 ); // whole screen
3122 // any button? if so, about
3128 if ( SDL_PeepEvents ( &e, 1, SDL_GETEVENT, SDL_EVENTMASK(/*SDL_KEYUP|*/SDL_KEYDOWN) ) > 0 ) {
3137 SDL_FreeSurface ( rtext );
3141 } // while more text
3145 for ( i = 0; i < textmax; i++ ) {
3146 if ( textloop [ i ] ) {
3147 free ( textloop [ i ] );
3155 void ui_revealscreen ( void ) {
3156 char *labels [ 500 ];
3157 unsigned int labelmax = 0;
3159 char fulllabel [ 200 ];
3161 if ( ! category_count ( CFHIDDEN ) ) {
3162 return; // nothing to do
3165 // switch to hidden categories
3166 category_publish ( CFHIDDEN, NULL );
3168 // build up labels to show in menu
3169 for ( i = 0; i < g_categorycount; i++ ) {
3171 if ( g_categories [ i ] -> parent_catname ) {
3172 sprintf ( fulllabel, "%s [%s]", g_categories [ i ] -> catname, g_categories [ i ] -> parent_catname );
3174 sprintf ( fulllabel, "%s", g_categories [ i ] -> catname );
3177 labels [ labelmax++ ] = strdup ( fulllabel );
3181 int sel = ui_modal_single_menu ( labels, labelmax, "Temporary Category Reveal",
3182 "Enter to select; other to return." );
3184 // if selected, try to set this guy to visible
3187 // fix up category name, if its been hacked
3188 #if 0 // prepending and .. wtf crap is this
3189 if ( strchr ( g_categories [ sel ] -> catname, '.' ) ) {
3190 char *t = g_categories [ sel ] -> catname;
3191 g_categories [ sel ] -> catname = strdup ( strchr ( g_categories [ sel ] -> catname, '.' ) + 1 );
3196 // reflag this guy to be visible
3197 g_categories [ sel ] -> catflags = CFNORMAL;
3199 // switch to the new category.. cache name.
3200 char *switch_to_name = g_categories [ sel ] -> catname;
3202 // republish categories
3203 category_publish ( CFNORMAL, NULL );
3205 // switch to the new category.. with the cached name!
3206 ui_category = category_index ( switch_to_name );
3208 // ensure visibility
3209 unsigned int screen_width = ui_display_context.screen_width;
3210 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
3211 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
3212 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
3217 // republish categories
3218 category_publish ( CFNORMAL, NULL );
3221 render_mask |= CHANGED_CATEGORY;
3222 ui_start_defered_icon_thread();
3227 void ui_recache_context ( ui_context_t *c ) {
3229 c -> screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
3231 c -> font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
3232 c -> font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
3233 c -> font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
3234 c -> font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
3236 c -> grid_offset_x = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_x" );
3237 c -> grid_offset_y = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_y" );
3239 c -> icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
3240 c -> icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
3241 c -> icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
3242 c -> icon_max_height = pnd_conf_get_as_int ( g_conf, "grid.icon_max_height" );
3243 c -> sel_icon_offset_x = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_x", 0 );
3244 c -> sel_icon_offset_y = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_y", 0 );
3246 c -> text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
3247 c -> text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
3248 c -> text_offset_x = pnd_conf_get_as_int ( g_conf, "grid.text_offset_x" );
3249 c -> text_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_offset_y" );
3250 c -> text_hilite_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
3252 c -> row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 4 );
3253 c -> col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
3255 c -> cell_width = pnd_conf_get_as_int ( g_conf, "grid.cell_width" );
3256 c -> cell_height = pnd_conf_get_as_int ( g_conf, "grid.cell_height" );
3258 c -> arrow_bar_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
3259 c -> arrow_bar_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
3260 c -> arrow_bar_clip_w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
3261 c -> arrow_bar_clip_h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
3262 c -> arrow_up_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
3263 c -> arrow_up_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
3264 c -> arrow_down_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
3265 c -> arrow_down_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
3268 SDL_Color tmp = { c -> font_rgba_r, c -> font_rgba_g, c -> font_rgba_b, c -> font_rgba_a };
3269 c -> fontcolor = tmp;
3271 // now that we've got 'normal' (detail pane shown) param's, lets check if detail pane
3272 // is hidden; if so, override some values with those alternate skin values where possible.
3273 if ( ui_detail_hidden ) {
3274 // if detail panel is hidden, and theme cannot support it, unhide the bloody thing. (This may help
3275 // when someone is amid theme hacking or changing.)
3276 if ( ! ui_is_detail_hideable() ) {
3277 ui_detail_hidden = 0;
3281 if ( ui_detail_hidden ) {
3283 c -> row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max_w", c -> row_max );
3284 c -> col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max_w", c -> col_max );
3286 c -> cell_width = pnd_conf_get_as_int_d ( g_conf, "grid.cell_width_w", c -> cell_width );
3287 c -> cell_height = pnd_conf_get_as_int_d ( g_conf, "grid.cell_height_w", c -> cell_height );
3289 c -> arrow_bar_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x_w", 450 );
3290 c -> arrow_bar_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y_w", 100 );
3291 c -> arrow_up_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x_w", 450 );
3292 c -> arrow_up_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y_w", 80 );
3293 c -> arrow_down_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x_w", 450 );
3294 c -> arrow_down_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y_w", 80 );
3296 } // if detail hidden.. still.
3298 } // if detail hidden
3303 unsigned char ui_is_detail_hideable ( void ) {
3305 // if skin has a bit of info for wide-mode, we assume wide-mode is available
3306 if ( pnd_conf_get_as_char ( g_conf, "grid.row_max_w" ) != NULL ) {
3314 void ui_toggle_detail_pane ( void ) {
3316 // no bitmask trickery here; I like it to be stand-out obvious at 3am.
3318 if ( ui_detail_hidden ) {
3319 ui_detail_hidden = 0;
3321 ui_detail_hidden = 1;
3324 // repull skin config
3325 ui_recache_context ( &ui_display_context );
3328 render_mask |= CHANGED_EVERYTHING;
3333 void ui_menu_context ( mm_appref_t *a ) {
3335 unsigned char rescan_apps = 0;
3336 unsigned char context_alive = 1;
3341 context_file_delete,
3344 context_app_recategorize,
3345 context_app_recategorize_sub,
3347 context_app_cpuspeed,
3355 char *verbiage[] = {
3356 "Done (return to grid)", // context_done
3357 "Get info about file/dir", // context_file_info
3358 "Delete file/dir", // context_file_delete
3359 "Get info", // context_app_info
3360 "Hide application", // hide
3361 "Recategorize", // recategorize
3362 "Recategorize subcategory", // recategorize
3363 "Change displayed title", // rename
3364 "Set CPU speed for launch", // cpuspeed
3365 "Run application", // run
3366 "Edit notes line 1", // notes1
3367 "Edit notes line 2", // notes2
3368 "Edit notes line 3", // notes3
3371 unsigned short int menu [ context_menu_max ];
3372 char *menustring [ context_menu_max ];
3373 unsigned char menumax = 0;
3376 menu [ menumax ] = context_done; menustring [ menumax++ ] = verbiage [ context_done ];
3378 // hook up appropriate menu options based on tab-type and object-type
3379 if ( g_categories [ ui_category ] -> fspath ) {
3381 menu [ menumax ] = context_file_info; menustring [ menumax++ ] = verbiage [ context_file_info ];
3382 menu [ menumax ] = context_file_delete; menustring [ menumax++ ] = verbiage [ context_file_delete ];
3385 if ( a -> ref -> object_type == pnd_object_type_directory ) {
3386 return; // don't do anything if the guy is a subcat-as-folder
3389 //menu [ menumax ] = context_app_info; menustring [ menumax++ ] = verbiage [ context_app_info ];
3390 menu [ menumax ] = context_app_run; menustring [ menumax++ ] = verbiage [ context_app_run ];
3391 menu [ menumax ] = context_app_hide; menustring [ menumax++ ] = verbiage [ context_app_hide ];
3392 menu [ menumax ] = context_app_recategorize; menustring [ menumax++ ] = verbiage [ context_app_recategorize ];
3393 menu [ menumax ] = context_app_recategorize_sub; menustring [ menumax++ ] = verbiage [ context_app_recategorize_sub ];
3394 menu [ menumax ] = context_app_rename; menustring [ menumax++ ] = verbiage [ context_app_rename ];
3395 menu [ menumax ] = context_app_cpuspeed; menustring [ menumax++ ] = verbiage [ context_app_cpuspeed ];
3396 menu [ menumax ] = context_app_notes1; menustring [ menumax++ ] = verbiage [ context_app_notes1 ];
3397 menu [ menumax ] = context_app_notes2; menustring [ menumax++ ] = verbiage [ context_app_notes2 ];
3398 menu [ menumax ] = context_app_notes3; menustring [ menumax++ ] = verbiage [ context_app_notes3 ];
3402 while ( context_alive ) {
3404 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 */ );
3411 switch ( menu [ sel ] ) {
3417 case context_file_info:
3420 case context_file_delete:
3421 //ui_menu_twoby ( "Delete - Are you sure?", "B/enter; other to cancel", "Delete", "Do not delete" );
3424 case context_app_info:
3427 case context_app_hide:
3430 char confkey [ 1000 ];
3431 snprintf ( confkey, 999, "%s.%s", "appshow", a -> ref -> unique_id );
3434 pnd_conf_set_char ( g_conf, confkey, "0" );
3436 // write conf, so it will take next time
3437 conf_write ( g_conf, conf_determine_location ( g_conf ) );
3439 // can we just 'hide' this guy without reloading all apps? (this is for you, EvilDragon)
3442 // DOESN'T WORK YET; other parts of app are still hanging onto some values and blow up
3444 char *uid = strdup ( a -> ref -> unique_id );
3446 for ( i = 0; i < g_categorycount; i++ ) {
3447 mm_appref_t *p = g_categories [ i ] -> refs;
3452 if ( strcmp ( p -> ref -> unique_id, uid ) == 0 ) {
3454 if ( g_categories [ i ] -> refcount ) {
3455 g_categories [ i ] -> refcount--;
3460 } // while for each appref
3461 } // for each cat/tab
3466 // request rescan and wrap up
3470 context_alive = 0; // nolonger visible, so lets just get out
3476 case context_app_recategorize:
3479 unsigned char optmax = 0;
3482 // show custom categories
3483 if ( mmcustom_setup() ) {
3485 for ( i = 0; i < mmcustom_count; i++ ) {
3486 if ( mmcustom_complete [ i ].parent_cat == NULL ) {
3487 opts [ optmax++ ] = mmcustom_complete [ i ].cat;
3493 // show FD categories
3494 i = 2; // skip first two - Other and NoParentCategory
3497 if ( ! freedesktop_complete [ i ].cat ) {
3501 if ( ! freedesktop_complete [ i ].parent_cat ) {
3502 opts [ optmax++ ] = freedesktop_complete [ i ].cat;
3509 char prompt [ 101 ];
3510 snprintf ( prompt, 100, "Pick category [%s]", a -> ref -> main_category ? a -> ref -> main_category : "NoParentCategory" );
3512 int sel = ui_modal_single_menu ( opts, optmax, prompt /*"Select parent category"*/, "Enter to select; other to skip." );
3515 char confirm [ 1001 ];
3516 snprintf ( confirm, 1000, "Confirm: %s", opts [ sel ] );
3518 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm categorization", "Do not set category" ) == 1 ) {
3519 ovr_replace_or_add ( a, "maincategory", opts [ sel ] );
3521 // when changing main cat, reset subcat, otherwise you go from Game/Emu to Network/Emu and get sent to Other right away
3522 ovr_replace_or_add ( a, "maincategorysub1", freedesktop_complete [ 2 ].cat );
3527 if ( mmcustom_is_ready() ) {
3528 mmcustom_shutdown();
3534 case context_app_recategorize_sub:
3537 unsigned char optmax = 0;
3538 unsigned char i = 0;
3540 char *whichparentarewe;
3541 if ( g_categories [ ui_category ] -> parent_catname ) {
3542 whichparentarewe = g_categories [ ui_category ] -> parent_catname;
3544 whichparentarewe = g_categories [ ui_category ] -> catname;
3547 // add NoSubcategory magic one
3548 opts [ optmax++ ] = freedesktop_complete [ 2 ].cat;
3550 // add custom categories
3551 if ( mmcustom_setup() ) {
3553 for ( i = 0; i < mmcustom_count; i++ ) {
3554 if ( mmcustom_complete [ i ].parent_cat && strcmp ( mmcustom_complete [ i ].parent_cat, whichparentarewe ) == 0 ) {
3555 opts [ optmax++ ] = mmcustom_complete [ i ].cat;
3561 // add FD categories
3564 if ( ! freedesktop_complete [ i ].cat ) {
3568 if ( ( freedesktop_complete [ i ].parent_cat ) &&
3569 ( strcasecmp ( freedesktop_complete [ i ].parent_cat, whichparentarewe ) == 0 )
3572 opts [ optmax++ ] = freedesktop_complete [ i ].cat;
3578 char prompt [ 101 ];
3579 //snprintf ( prompt, 100, "Currently: %s", a -> ref -> main_category1 ? a -> ref -> main_category1 : "NoSubcategory" );
3580 snprintf ( prompt, 100, "%s [%s]", a -> ref -> main_category1 ? a -> ref -> main_category1 : "NoSubcategory", whichparentarewe );
3582 int sel = ui_modal_single_menu ( opts, optmax, prompt /*"Select subcategory"*/, "Enter to select; other to skip." );
3585 char confirm [ 1001 ];
3586 snprintf ( confirm, 1000, "Confirm: %s", opts [ sel ] );
3588 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm sub-categorization", "Do not set sub-category" ) == 1 ) {
3589 ovr_replace_or_add ( a, "maincategorysub1", opts [ sel ] );
3595 if ( mmcustom_is_ready() ) {
3596 mmcustom_shutdown();
3602 case context_app_rename:
3604 char namebuf [ 101 ];
3605 unsigned char changed;
3607 changed = ui_menu_get_text_line ( "Rename application", "Use keyboard; Enter when done.",
3608 a -> ref -> title_en ? a -> ref -> title_en : "blank", namebuf, 30, 0 /* alphanumeric */ );
3611 char confirm [ 1001 ];
3612 snprintf ( confirm, 1000, "Confirm: %s", namebuf );
3614 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm rename", "Do not rename" ) == 1 ) {
3615 ovr_replace_or_add ( a, "title", namebuf );
3625 case context_app_cpuspeed:
3627 char namebuf [ 101 ];
3628 unsigned char changed;
3630 changed = ui_menu_get_text_line ( "Specify runspeed", "Use keyboard; Enter when done.",
3631 a -> ref -> clockspeed ? a -> ref -> clockspeed : "500", namebuf, 6, 1 /* numeric */ );
3634 char confirm [ 1001 ];
3635 snprintf ( confirm, 1000, "Confirm: %s", namebuf );
3637 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm clockspeed", "Do not set" ) == 1 ) {
3638 ovr_replace_or_add ( a, "clockspeed", namebuf );
3648 case context_app_run:
3652 case context_app_notes1:
3653 case context_app_notes2:
3654 case context_app_notes3:
3656 char namebuf [ 101 ] = "";
3659 unsigned char notenum;
3662 if ( menu [ sel ] == context_app_notes1 ) {
3664 } else if ( menu [ sel ] == context_app_notes2 ) {
3666 } else if ( menu [ sel ] == context_app_notes3 ) {
3670 // figure out key for looking up existing, and for storing replacement
3671 snprintf ( key, 500, "Application-%u.note-%u", a -> ref -> subapp_number, notenum );
3673 // do we have existing value?
3675 char *existing = pnd_conf_get_as_char ( a -> ovrh, key );
3677 strncpy ( namebuf, existing, 100 );
3681 unsigned char changed;
3683 changed = ui_menu_get_text_line ( "Enter replacement note", "Use keyboard; Enter when done.",
3684 namebuf, namebuf, 30, 0 /* not-numeric-forced */ );
3687 ovr_replace_or_add ( a, strchr ( key, '.' ) + 1, namebuf );
3699 } // if useful return
3704 if ( rescan_apps ) {
3705 applications_free();
3706 applications_scan();
3712 unsigned char ui_menu_oneby ( char *title, char *footer, char *one ) {
3715 int sel = ui_modal_single_menu ( opts, 1, title, footer );
3722 unsigned char ui_menu_twoby ( char *title, char *footer, char *one, char *two ) {
3726 int sel = ui_modal_single_menu ( opts, 2, title, footer );
3733 unsigned char ui_menu_get_text_line ( char *title, char *footer, char *initialvalue,
3734 char *r_buffer, unsigned char maxlen, unsigned char numbersonlyp )
3736 SDL_Rect rects [ 40 ];
3737 SDL_Rect *dest = rects;
3741 char hacktext [ 1024 ];
3742 unsigned char shifted = 0;
3744 bzero ( rects, sizeof(SDL_Rect) * 40 );
3746 if ( initialvalue ) {
3747 if ( initialvalue == r_buffer ) {
3748 // already good to go
3750 strncpy ( r_buffer, initialvalue, maxlen );
3753 bzero ( r_buffer, maxlen );
3759 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
3760 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
3761 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
3762 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
3763 SDL_FillRect( sdl_realscreen, dest, 0 );
3765 // show dialog background
3766 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
3769 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> w;
3770 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> h;
3771 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
3772 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
3773 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
3777 // show dialog frame
3778 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
3779 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
3780 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
3781 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
3787 rtext = TTF_RenderText_Blended ( g_tab_font, title, ui_display_context.fontcolor );
3788 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
3789 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
3790 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
3791 SDL_FreeSurface ( rtext );
3797 rtext = TTF_RenderText_Blended ( g_tab_font, footer, ui_display_context.fontcolor );
3798 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
3799 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
3800 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
3802 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
3803 SDL_FreeSurface ( rtext );
3807 // show text line - and embed cursor
3808 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
3809 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( 0/*i*/ + 1 - 0/*first_visible*/ ) );
3811 strncpy ( hacktext, r_buffer, 1000 );
3812 strncat ( hacktext, "\n", 1000 ); // add [] in most fonts
3814 rtext = TTF_RenderText_Blended ( g_tab_font, hacktext, ui_display_context.fontcolor );
3815 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
3816 SDL_FreeSurface ( rtext );
3819 // update all the rects and send it all to sdl
3820 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
3825 while ( SDL_WaitEvent ( &event ) ) {
3827 switch ( event.type ) {
3830 if ( event.key.keysym.sym == SDLK_LSHIFT || event.key.keysym.sym == SDLK_RSHIFT ) {
3837 if ( event.key.keysym.sym == SDLK_LEFT || event.key.keysym.sym == SDLK_BACKSPACE ) {
3838 if ( strlen ( r_buffer ) > 0 ) {
3839 char *eol = strchr ( r_buffer, '\0' );
3840 *( eol - 1 ) = '\0';
3843 } else if ( event.key.keysym.sym == SDLK_UP ) {
3844 r_buffer [ 0 ] = '\0'; // truncate!
3846 } else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_END ) { // return, or "B"
3847 // on Enter/Return or B, if the buffer has 1 or more chars, we return it as valid.. otherwise, invalid.
3848 if ( strlen ( r_buffer ) > 0 ) {
3853 } else if ( event.key.keysym.sym == SDLK_LSHIFT || event.key.keysym.sym == SDLK_RSHIFT ) {
3856 } else if ( event.key.keysym.sym == SDLK_ESCAPE ||
3857 event.key.keysym.sym == SDLK_PAGEUP ||
3858 event.key.keysym.sym == SDLK_PAGEDOWN ||
3859 event.key.keysym.sym == SDLK_HOME
3866 if ( isprint(event.key.keysym.sym) ) {
3868 unsigned char good = 1;
3870 if ( numbersonlyp && ( ! isdigit(event.key.keysym.sym) ) ) {
3874 if ( maxlen && strlen(r_buffer) >= maxlen ) {
3879 char b [ 2 ] = { '\0', '\0' };
3881 b [ 0 ] = toupper ( event.key.keysym.sym );
3883 b [ 0 ] = event.key.keysym.sym;
3885 strncat ( r_buffer, b, maxlen );
3898 } // while waiting for input
3905 unsigned char ovr_replace_or_add ( mm_appref_t *a, char *keybase, char *newvalue ) {
3906 //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 );
3908 char fullpath [ PATH_MAX ];
3910 sprintf ( fullpath, "%s/%s", a -> ref -> object_path, a -> ref -> object_filename );
3911 char *dot = strrchr ( fullpath, '.' );
3913 sprintf ( dot, PXML_SAMEPATH_OVERRIDE_FILEEXT );
3915 pnd_log ( pndn_error, "ERROR: Bad pnd-path in disco_t! %s\n", fullpath );
3919 struct stat statbuf;
3921 if ( stat ( fullpath, &statbuf ) == 0 ) {
3925 h = pnd_conf_fetch_by_path ( fullpath );
3928 return ( 0 ); // fail!
3932 snprintf ( key, 100, "Application-%u.%s", a -> ref -> subapp_number, keybase );
3934 pnd_conf_set_char ( h, key, newvalue );
3936 return ( pnd_conf_write ( h, fullpath ) );
3939 // file needs to be created - easy!
3941 FILE *f = fopen ( fullpath, "w" );
3944 fprintf ( f, "Application-%u.%s\t%s\n", a -> ref -> subapp_number, keybase, newvalue );
3948 return ( 0 ); // fail!
3956 void ui_manage_categories ( void ) {
3957 unsigned char require_app_scan = 0;
3959 if ( ! mmcustom_setup() ) {
3963 char *opts [ 20 ] = {
3964 "List custom categories",
3965 "List custom subcategories",
3966 "Register custom category",
3967 "Register custom subcategory",
3968 "Unregister custom category",
3969 "Unregister custom subcategory",
3975 int sel = ui_modal_single_menu ( opts, 7, "Custom Categories", "B to select; other to cancel." );
3979 case 0: // list custom
3980 ui_pick_custom_category ( 0 );
3983 case 1: // list custom sub
3984 if ( mmcustom_count ) {
3986 char *maincat = ui_pick_custom_category ( 2 );
3989 unsigned int subcount = mmcustom_count_subcats ( maincat );
3990 char titlebuf [ 201 ];
3992 snprintf ( titlebuf, 200, "Category: %s", maincat );
3994 if ( subcount == 0 ) {
3995 ui_menu_oneby ( titlebuf, "B/Enter to accept", "Category has no subcategories." );
3998 char **list = malloc ( subcount * sizeof(char*) );
4000 unsigned int counter = 0;
4002 for ( i = 0; i < mmcustom_count; i++ ) {
4003 if ( mmcustom_complete [ i ].parent_cat && strcasecmp ( mmcustom_complete [ i ].parent_cat, maincat ) == 0 ) {
4004 list [ counter++ ] = mmcustom_complete [ i ].cat;
4008 ui_modal_single_menu ( list, counter, titlebuf, "Any button to exit." );
4012 } // more than 0 subcats?
4014 } // user picked a main cat?
4017 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4021 case 2: // register custom
4023 unsigned char changed;
4024 char namebuf [ 101 ] = "";
4026 changed = ui_menu_get_text_line ( "Enter unique category name", "Use keyboard; Enter when done.",
4027 "Pandora", namebuf, 30, 0 /* alphanumeric */ );
4029 // did the user enter something?
4032 // and if so, is it existant already or not?
4033 if ( mmcustom_query ( namebuf, NULL ) ) {
4034 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a registered category." );
4035 } else if ( freedesktop_category_query ( namebuf, NULL ) ) {
4036 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a Standard category." );
4039 char confirm [ 1001 ];
4040 snprintf ( confirm, 1000, "Confirm: %s", namebuf );
4042 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm new category", "Do not register" ) == 1 ) {
4043 // register, save, recycle the current list
4044 mmcustom_register ( namebuf, NULL );
4045 mmcustom_write ( NULL );
4046 mmcustom_shutdown();
4052 } // entered something?
4057 case 3: // register custom sub
4058 if ( 1 /*mmcustom_count -- we allow FD cats now, so this isn't applicable error */ ) {
4060 char *maincat = ui_pick_custom_category ( 1 /* include FD */ );
4063 char titlebuf [ 201 ];
4065 snprintf ( titlebuf, 200, "Subcat of: %s", maincat );
4067 unsigned char changed;
4068 char namebuf [ 101 ] = "";
4070 changed = ui_menu_get_text_line ( titlebuf, "Use keyboard; Enter when done.", "Submarine", namebuf, 30, 0 /* alphanumeric */ );
4072 // did the user enter something?
4075 // and if so, is it existant already or not?
4076 if ( mmcustom_query ( namebuf, maincat ) ) {
4077 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a subcategory." );
4078 } else if ( freedesktop_category_query ( namebuf, maincat ) ) {
4079 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a Standard subcategory." );
4082 char confirm [ 1001 ];
4083 snprintf ( confirm, 1000, "Confirm: %s [%s]", namebuf, maincat );
4085 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm new category", "Do not register" ) == 1 ) {
4086 // register, save, recycle the current list
4087 mmcustom_register ( namebuf, maincat );
4088 mmcustom_write ( NULL );
4089 mmcustom_shutdown();
4095 } // entered something?
4097 } // selected parent cat?
4100 ui_menu_oneby ( "Warning", "B/Enter to accept", "No categories registered." );
4104 case 4: // unreg custom
4105 if ( mmcustom_count ) {
4106 char *maincat = ui_pick_custom_category ( 0 );
4109 char confirm [ 1001 ];
4110 snprintf ( confirm, 1000, "Confirm remove: %s", maincat );
4112 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm unregister", "Do not unregister" ) == 1 ) {
4113 // register, save, recycle the current list
4114 mmcustom_unregister ( maincat, NULL );
4115 mmcustom_write ( NULL );
4116 mmcustom_shutdown();
4123 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4127 case 5: // unreg custom sub
4128 if ( mmcustom_count ) {
4129 char *maincat = ui_pick_custom_category ( 2 );
4132 unsigned int subcount = mmcustom_count_subcats ( maincat );
4133 char titlebuf [ 201 ];
4135 snprintf ( titlebuf, 200, "Category: %s", maincat );
4137 if ( subcount == 0 ) {
4138 ui_menu_oneby ( titlebuf, "B/Enter to accept", "Category has no subcategories." );
4141 char **list = malloc ( subcount * sizeof(char*) );
4143 unsigned int counter = 0;
4145 for ( i = 0; i < mmcustom_count; i++ ) {
4146 if ( mmcustom_complete [ i ].parent_cat && strcasecmp ( mmcustom_complete [ i ].parent_cat, maincat ) == 0 ) {
4147 list [ counter++ ] = mmcustom_complete [ i ].cat;
4151 int sel = ui_modal_single_menu ( list, counter, titlebuf, "B to selct; other to exit." );
4154 char confirm [ 1001 ];
4155 snprintf ( confirm, 1000, "Confirm remove: %s", list [ sel ] );
4157 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm unregister", "Do not unregister" ) == 1 ) {
4158 // register, save, recycle the current list
4159 mmcustom_unregister ( list [ sel ], maincat );
4160 mmcustom_write ( NULL );
4161 mmcustom_shutdown();
4169 } // more than 0 subcats?
4171 } // user picked a main cat?
4174 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4181 if ( sel < 0 || sel > 5 ) {
4185 } // while running the menu
4187 // shut down custom cats
4188 mmcustom_shutdown();
4191 if ( require_app_scan ) {
4192 applications_free();
4193 applications_scan();
4197 render_mask |= CHANGED_EVERYTHING;
4202 // mode 0 == custom main only; 1 == custom main + FD main; 2 == custom main + FD mains-with-custom-subs
4203 char *ui_pick_custom_category ( unsigned char mode ) {
4206 unsigned int counter = 0;
4208 // alloc space for list, depending on scope
4210 list = malloc ( (mmcustom_count+freedesktop_count()) * sizeof(char*) );
4212 list = malloc ( mmcustom_count * sizeof(char*) );
4216 for ( i = 0; i < mmcustom_count; i++ ) {
4217 if ( mmcustom_complete [ i ].parent_cat == NULL ) {
4218 list [ counter++ ] = mmcustom_complete [ i ].cat;
4228 if ( ! freedesktop_complete [ i ].cat ) {
4233 if ( freedesktop_complete [ i ].parent_cat == NULL ) {
4235 // mode 1 == include them all
4236 // mode 2 == include them if they have a custom subcat
4237 if ( ( mode == 1 ) ||
4238 ( mmcustom_subcount ( freedesktop_complete [ i ].cat ) ) )
4240 list [ counter++ ] = freedesktop_complete [ i ].cat;
4250 // we actually showing anything?
4252 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4257 int sel = ui_modal_single_menu ( list, counter, "Custom Categories", "Any button to exit." );
4264 char *foo = list [ sel ];
4270 void ui_start_defered_icon_thread ( void ) {
4272 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 0 ) {
4276 if ( g_icon_thread_busy ) {
4277 //fprintf ( stderr, "REM: Waiting for thread to stop..\n" );
4278 ui_stop_defered_icon_thread();
4281 //fprintf ( stderr, "WARN: Starting new icon caching thread..\n" );
4282 g_icon_thread = SDL_CreateThread ( (void*)ui_threaded_defered_icon, NULL );
4284 if ( ! g_icon_thread ) {
4285 pnd_log ( pndn_error, "ERROR: Couldn't create icon thread\n" );
4291 void ui_stop_defered_icon_thread ( void ) {
4292 time_t started = time ( NULL );
4294 // ask thread to stop, then wait for it (if two run at same time, or if we change
4295 // category content under neath it, could be bad..)
4296 g_icon_thread_stop = 1;
4297 while ( g_icon_thread_busy ) {
4298 time ( NULL ); // spin
4300 g_icon_thread_stop = 0;
4302 fprintf ( stderr, "REM: Thread stoppage took %u seconds.\n", (int) ( time ( NULL ) - started ) );