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"
45 #define CHANGED_NOTHING (0)
46 #define CHANGED_CATEGORY (1<<0) /* changed to different category */
47 #define CHANGED_SELECTION (1<<1) /* changed app selection */
48 #define CHANGED_DATAUPDATE (1<<2) /* deferred preview pic or icon came in */
49 #define CHANGED_APPRELOAD (1<<3) /* new set of applications entirely */
50 #define CHANGED_EVERYTHING (1<<4) /* redraw it all! */
51 unsigned int render_mask = CHANGED_EVERYTHING;
53 #define MIMETYPE_EXE "/usr/bin/file" /* check for file type prior to invocation */
57 SDL_Surface *sdl_realscreen = NULL;
58 unsigned int sdl_ticks = 0;
59 SDL_Thread *g_preview_thread = NULL;
60 SDL_Thread *g_timer_thread = NULL;
62 enum { sdl_user_ticker = 0,
63 sdl_user_finishedpreview = 1,
64 sdl_user_finishedicon = 2,
70 unsigned short int g_scale = 1; // 1 == noscale
72 SDL_Surface *g_imgcache [ IMG_MAX ];
74 TTF_Font *g_big_font = NULL;
75 TTF_Font *g_grid_font = NULL;
76 TTF_Font *g_detailtext_font = NULL;
77 TTF_Font *g_tab_font = NULL;
79 extern pnd_conf_handle g_conf;
81 /* current display state
83 int ui_rows_scrolled_down = 0; // number of rows that should be missing from top of the display
84 mm_appref_t *ui_selected = NULL;
85 unsigned char ui_category = 0; // current category
86 unsigned char ui_catshift = 0; // how many cats are offscreen to the left
87 ui_context_t ui_display_context; // display paramaters: see mmui_context.h
88 unsigned char ui_detail_hidden = 0; // if >0, detail panel is hidden
89 // FUTURE: If multiple panels can be shown/hidden, convert ui_detail_hidden to a bitmask
91 static SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ); // height -1 means ignore
92 static int ui_selected_index ( void );
94 unsigned char ui_setup ( void ) {
99 SDL_Init ( SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE );
101 SDL_JoystickOpen ( 0 ); // turn on joy-0
103 SDL_WM_SetCaption ( "mmenu", "mmenu" );
105 // hide the mouse cursor if we can
106 if ( SDL_ShowCursor ( -1 ) == 1 ) {
107 SDL_ShowCursor ( 0 );
113 unsigned int svm = SDL_SWSURFACE /*| SDL_FULLSCREEN*/ /* 0*/;
114 if ( pnd_conf_get_as_int_d ( g_conf, "display.fullscreen", 0 ) > 0 ) {
115 svm |= SDL_FULLSCREEN;
119 SDL_SetVideoMode ( 800 * g_scale, 480 * g_scale, 16 /*bpp*/, svm );
121 if ( ! sdl_realscreen ) {
122 pnd_log ( pndn_error, "ERROR: Couldn't open SDL real screen; dieing." );
126 pnd_log ( pndn_debug, "Pixel format:" );
127 pnd_log ( pndn_debug, "bpp b: %u\n", sdl_realscreen -> format -> BitsPerPixel );
128 pnd_log ( pndn_debug, "bpp B: %u\n", sdl_realscreen -> format -> BytesPerPixel );
129 pnd_log ( pndn_debug, "R mask: %08x\n", sdl_realscreen -> format -> Rmask );
130 pnd_log ( pndn_debug, "G mask: %08x\n", sdl_realscreen -> format -> Gmask );
131 pnd_log ( pndn_debug, "B mask: %08x\n", sdl_realscreen -> format -> Bmask );
137 /* Set 16-bit stereo audio at 22Khz */
138 fmt.freq = 44100; //22050;
139 fmt.format = AUDIO_S16; //AUDIO_S16;
141 fmt.samples = 2048; /* A good value for games */
142 fmt.callback = mixaudio;
145 /* Open the audio device and start playing sound! */
146 if ( SDL_OpenAudio ( &fmt, NULL ) < 0 ) {
147 zotlog ( "Unable to open audio: %s\n", SDL_GetError() );
151 SDL_PauseAudio ( 0 );
156 SDL_EnableKeyRepeat ( 500, 125 /* 150 */ );
159 //IMG_Init ( IMG_INIT_JPG | IMG_INIT_PNG );
165 if ( TTF_Init() == -1 ) {
166 pnd_log ( pndn_error, "ERROR: Couldn't set up SDL TTF lib\n" );
167 return ( 0 ); // couldn't set up SDL TTF
170 char fullpath [ PATH_MAX ];
172 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "minimenu.font" ) );
173 g_big_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
174 if ( ! g_big_font ) {
175 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
176 pnd_conf_get_as_char ( g_conf, "minimenu.font" ), pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
177 return ( 0 ); // couldn't set up SDL TTF
181 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "grid.font" ) );
182 g_grid_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
183 if ( ! g_grid_font ) {
184 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
185 pnd_conf_get_as_char ( g_conf, "grid.font" ), pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
186 return ( 0 ); // couldn't set up SDL TTF
190 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "detailtext.font" ) );
191 g_detailtext_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
192 if ( ! g_detailtext_font ) {
193 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
194 pnd_conf_get_as_char ( g_conf, "detailtext.font" ), pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
195 return ( 0 ); // couldn't set up SDL TTF
199 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "tabs.font" ) );
200 g_tab_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
201 if ( ! g_tab_font ) {
202 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
203 pnd_conf_get_as_char ( g_conf, "tabs.font" ), pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
204 return ( 0 ); // couldn't set up SDL TTF
207 // determine display context
208 if ( pnd_conf_get_as_int_d ( g_conf, "display.show_detail_pane", 1 ) > 0 ) {
209 ui_detail_hidden = 0;
211 ui_detail_hidden = 1;
213 ui_recache_context ( &ui_display_context );
218 mm_imgcache_t g_imagecache [ IMG_TRUEMAX ] = {
219 { IMG_BACKGROUND_800480, "graphics.IMG_BACKGROUND_800480" },
220 { IMG_BACKGROUND_TABMASK, "graphics.IMG_BACKGROUND_TABMASK" },
221 { IMG_DETAIL_PANEL, "graphics.IMG_DETAIL_PANEL" },
222 { IMG_DETAIL_BG, "graphics.IMG_DETAIL_BG" },
223 { IMG_SELECTED_ALPHAMASK, "graphics.IMG_SELECTED_ALPHAMASK" },
224 { IMG_TAB_SEL, "graphics.IMG_TAB_SEL" },
225 { IMG_TAB_SEL_L, "graphics.IMG_TAB_SEL_L" },
226 { IMG_TAB_SEL_R, "graphics.IMG_TAB_SEL_R" },
227 { IMG_TAB_UNSEL, "graphics.IMG_TAB_UNSEL" },
228 { IMG_TAB_UNSEL_L, "graphics.IMG_TAB_UNSEL_L" },
229 { IMG_TAB_UNSEL_R, "graphics.IMG_TAB_UNSEL_R" },
230 { IMG_TAB_LINE, "graphics.IMG_TAB_LINE" },
231 { IMG_TAB_LINEL, "graphics.IMG_TAB_LINEL" },
232 { IMG_TAB_LINER, "graphics.IMG_TAB_LINER" },
233 { IMG_ICON_MISSING, "graphics.IMG_ICON_MISSING" },
234 { IMG_SELECTED_HILITE, "graphics.IMG_SELECTED_HILITE" },
235 { IMG_PREVIEW_MISSING, "graphics.IMG_PREVIEW_MISSING" },
236 { IMG_ARROW_UP, "graphics.IMG_ARROW_UP", },
237 { IMG_ARROW_DOWN, "graphics.IMG_ARROW_DOWN", },
238 { IMG_ARROW_SCROLLBAR, "graphics.IMG_ARROW_SCROLLBAR", },
239 { IMG_HOURGLASS, "graphics.IMG_HOURGLASS", },
240 { IMG_FOLDER, "graphics.IMG_FOLDER", },
241 { IMG_EXECBIN, "graphics.IMG_EXECBIN", },
245 unsigned char ui_imagecache ( char *basepath ) {
247 char fullpath [ PATH_MAX ];
251 for ( i = 0; i < IMG_MAX; i++ ) {
253 if ( g_imagecache [ i ].id != i ) {
254 pnd_log ( pndn_error, "ERROR: Internal table mismatch during caching [%u]\n", i );
258 char *filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].confname );
261 pnd_log ( pndn_error, "ERROR: Missing filename in conf for key: %s\n", g_imagecache [ i ].confname );
265 if ( filename [ 0 ] == '/' ) {
266 strncpy ( fullpath, filename, PATH_MAX );
268 sprintf ( fullpath, "%s/%s", basepath, filename );
271 if ( ! ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
272 pnd_log ( pndn_error, "ERROR: Couldn't load static cache image: %s\n", fullpath );
279 //g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = SDL_CreateRGBSurface ( SDL_SWSURFACE, 60, 60, 32, 0xFF0000, 0x00FF00, 0xFF, 0xFF000000 );
280 //boxRGBA ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, 0, 0, 60, 60, 100, 100, 100, 250 );
286 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 );
287 // scale text hilight
288 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 );
289 // scale preview no-pic
290 g_imagecache [ IMG_PREVIEW_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_PREVIEW_MISSING ].i,
291 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ),
292 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 50 ) );
294 // set alpha on detail panel
295 //SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
300 void ui_render ( void ) {
303 // divide width: 550 / 250
304 // divide left side: 5 columns == 110px width
305 // 20px buffer either side == 70px wide icon + 20 + 20?
307 // what jobs to do during render?
311 #define R_TABS (1<<1)
312 #define R_DETAIL (1<<2)
313 #define R_GRID (1<<3)
315 #define R_ALL (R_BG|R_TABS|R_DETAIL|R_GRID)
317 unsigned int render_jobs_b = 0;
319 if ( render_mask & CHANGED_EVERYTHING ) {
320 render_jobs_b |= R_ALL;
323 if ( render_mask & CHANGED_SELECTION ) {
324 render_jobs_b |= R_GRID;
325 render_jobs_b |= R_DETAIL;
328 if ( render_mask & CHANGED_CATEGORY ) {
329 render_jobs_b |= R_ALL;
332 render_mask = CHANGED_NOTHING;
336 unsigned int icon_rows;
339 SDL_Rect rects [ MAXRECTS ], src;
340 SDL_Rect *dest = rects;
341 bzero ( dest, sizeof(SDL_Rect)*MAXRECTS );
343 unsigned int row, displayrow, col;
344 mm_appref_t *appiter;
346 ui_context_t *c = &ui_display_context; // for convenience and shorthand
348 // how many total rows do we need?
349 if ( g_categorycount ) {
350 icon_rows = g_categories [ ui_category ] -> refcount / c -> col_max;
351 if ( g_categories [ ui_category ] -> refcount % c -> col_max > 0 ) {
359 // if no selected app yet, select the first one
360 if ( ! ui_selected && pnd_conf_get_as_int_d ( g_conf, "minimenu.start_selected", 0 ) ) {
361 ui_selected = g_categories [ ui_category ] -> refs;
365 // reset touchscreen regions
366 if ( render_jobs_b ) {
370 // ensure selection is visible
373 unsigned char autoscrolled = 1;
374 while ( autoscrolled ) {
377 int index = ui_selected_index();
378 int topleft = c -> col_max * ui_rows_scrolled_down;
379 int botright = ( c -> col_max * ( ui_rows_scrolled_down + c -> row_max ) - 1 );
381 if ( index < topleft ) {
382 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
383 render_jobs_b |= R_ALL;
385 } else if ( index > botright ) {
386 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
387 render_jobs_b |= R_ALL;
391 } // while autoscrolling
393 if ( ui_rows_scrolled_down < 0 ) {
394 ui_rows_scrolled_down = 0;
395 } else if ( ui_rows_scrolled_down > icon_rows ) {
396 ui_rows_scrolled_down = icon_rows;
402 if ( render_jobs_b & R_BG ) {
404 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
407 dest -> w = sdl_realscreen -> w;
408 dest -> h = sdl_realscreen -> h;
409 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
414 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
417 dest -> w = sdl_realscreen -> w;
418 dest -> h = sdl_realscreen -> h;
419 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
426 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
427 static unsigned int tab_width;
428 static unsigned int tab_height;
429 static unsigned int tab_offset_x;
430 static unsigned int tab_offset_y;
431 static unsigned int text_offset_x;
432 static unsigned int text_offset_y;
433 static unsigned int text_width;
435 static unsigned char tab_first_run = 1;
436 if ( tab_first_run ) {
438 tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
439 tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
440 tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
441 tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
442 text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
443 text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
444 text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
447 unsigned int maxtab = ( c -> screen_width / tab_width ) < g_categorycount ? ( c -> screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift;
448 unsigned int maxtabspot = ( c -> screen_width / tab_width );
450 if ( g_categorycount > 0 ) {
452 // draw tabs with categories
453 for ( col = ui_catshift;
460 // if this is the first (leftmost) tab, we use different artwork
461 // than if the other tabs (so skinner can link lines up nicely.)
462 if ( col == ui_catshift ) {
463 // leftmost tab, special case
465 if ( col == ui_category ) {
466 s = g_imagecache [ IMG_TAB_SEL_L ].i;
468 s = g_imagecache [ IMG_TAB_UNSEL_L ].i;
471 } else if ( col == maxtab - 1 ) {
472 // rightmost tab, special case
474 if ( col == ui_category ) {
475 s = g_imagecache [ IMG_TAB_SEL_R ].i;
477 s = g_imagecache [ IMG_TAB_UNSEL_R ].i;
481 // normal (not leftmost) tab
483 if ( col == ui_category ) {
484 s = g_imagecache [ IMG_TAB_SEL ].i;
486 s = g_imagecache [ IMG_TAB_UNSEL ].i;
489 } // first col, or not first col?
496 if ( col == ui_category ) {
497 src.h = tab_selheight;
505 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
506 dest -> y = tab_offset_y;
509 ui_register_tab ( col, dest -> x, dest -> y, tab_width, tab_height );
511 if ( render_jobs_b & R_TABS ) {
512 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
513 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
517 if ( col == ui_category ) {
518 // no line for selected tab
520 if ( col - ui_catshift == 0 ) {
521 s = g_imagecache [ IMG_TAB_LINEL ].i;
522 } else if ( col - ui_catshift == maxtabspot - 1 ) {
523 s = g_imagecache [ IMG_TAB_LINER ].i;
525 s = g_imagecache [ IMG_TAB_LINE ].i;
527 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
528 dest -> y = tab_offset_y + tab_height;
529 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
535 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ] -> catname, c -> fontcolor );
538 src.w = rtext -> w < text_width ? rtext -> w : text_width;
540 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
541 dest -> y = tab_offset_y + text_offset_y;
542 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
543 SDL_FreeSurface ( rtext );
550 } // if we got categories
552 if ( render_jobs_b & R_TABS ) {
554 // draw tab lines under where tabs would be if we had categories
555 for ( /* foo */; col < maxtabspot; col++ ) {
558 if ( col - ui_catshift == 0 ) {
559 s = g_imagecache [ IMG_TAB_LINEL ].i;
560 } else if ( col - ui_catshift == maxtabspot - 1 ) {
561 s = g_imagecache [ IMG_TAB_LINER ].i;
563 s = g_imagecache [ IMG_TAB_LINE ].i;
565 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
566 dest -> y = tab_offset_y + tab_height;
567 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
576 // scroll bars and arrows
577 if ( render_jobs_b & R_BG ) {
578 unsigned char show_bar = 0;
581 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
582 dest -> x = c -> arrow_up_x;
583 dest -> y = c -> arrow_up_y;
584 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
591 if ( ui_rows_scrolled_down + c -> row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
592 dest -> x = c -> arrow_down_x;
593 dest -> y = c -> arrow_down_y;
594 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
601 // show scrollbar as well
604 src.w = c -> arrow_bar_clip_w;
605 src.h = c -> arrow_bar_clip_h;
606 dest -> x = c -> arrow_bar_x;
607 dest -> y = c -> arrow_bar_y;
608 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
612 } // r_bg, scroll bars
614 // render detail pane bg
615 if ( render_jobs_b & R_DETAIL && ui_detail_hidden == 0 ) {
617 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
620 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
621 src.x = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
622 src.y = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
623 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
624 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
625 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
626 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
627 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
631 // render detail pane
632 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
633 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
634 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
635 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
639 } // detailpane frame/bg
643 // anything to render?
644 if ( render_jobs_b & R_GRID && g_categorycount ) {
646 // if just rendering grid, and nothing else, better clear it first
647 if ( ! ( render_jobs_b & R_BG ) ) {
648 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
649 src.x = c -> grid_offset_x;
650 src.y = c -> grid_offset_y + c -> sel_icon_offset_y;
651 src.w = c -> col_max * c -> cell_width;
652 src.h = c -> row_max * c -> cell_height;
654 dest -> x = c -> grid_offset_x;
655 dest -> y = c -> grid_offset_y + c -> sel_icon_offset_y;
657 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
663 if ( g_categories [ ui_category ] -> refs ) {
665 appiter = g_categories [ ui_category ] -> refs;
669 // until we run out of apps, or run out of space
670 while ( appiter != NULL ) {
672 for ( col = 0; col < c -> col_max && appiter != NULL; col++ ) {
674 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
675 if ( row >= ui_rows_scrolled_down ) {
677 // selected? show hilights
678 if ( appiter == ui_selected ) {
679 SDL_Surface *s = g_imagecache [ IMG_SELECTED_ALPHAMASK ].i;
681 //dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + ( ( icon_max_width - s -> w ) / 2 );
682 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> icon_offset_x + c -> sel_icon_offset_x;
683 //dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + ( ( icon_max_height - s -> h ) / 2 );
684 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> icon_offset_y + c -> sel_icon_offset_y;
685 SDL_BlitSurface ( s, NULL /* all */, sdl_realscreen, dest );
688 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_clip_x;
689 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> text_hilite_offset_y;
690 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
695 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
696 SDL_Surface *iconsurface;
698 iconsurface = ic -> i;
700 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
702 // no icon override; was this a pnd-file (show the unknown icon then), or was this generated from
703 // filesystem (file or directory icon)
704 if ( appiter -> ref -> object_flags & PND_DISCO_GENERATED ) {
705 if ( appiter -> ref -> object_type == pnd_object_type_directory ) {
706 iconsurface = g_imagecache [ IMG_FOLDER ].i;
708 iconsurface = g_imagecache [ IMG_EXECBIN ].i;
711 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
716 // got an icon I hope?
718 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
724 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> icon_offset_x + (( c -> icon_max_width - iconsurface -> w ) / 2);
725 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> icon_offset_y + (( c -> icon_max_height - iconsurface -> h ) / 2);
727 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
730 ui_register_app ( appiter, dest -> x, dest -> y, src.w, src.h );
737 if ( appiter -> ref -> title_en ) {
739 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, c -> fontcolor );
742 src.w = c -> text_width < rtext -> w ? c -> text_width : rtext -> w;
744 if ( rtext -> w > c -> text_width ) {
745 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_clip_x;
747 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_offset_x - ( rtext -> w / 2 );
749 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> text_offset_y;
750 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
751 SDL_FreeSurface ( rtext );
755 } // display now? or scrolled away..
758 appiter = appiter -> next;
760 } // for column 1...X
762 if ( row >= ui_rows_scrolled_down ) {
768 // are we done displaying rows?
769 if ( displayrow >= c -> row_max ) {
776 // no apps to render?
777 pnd_log ( pndn_rem, "No applications to render?\n" );
782 // detail panel - show app details or blank-message
783 if ( render_jobs_b & R_DETAIL && ui_detail_hidden == 0 ) {
785 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
786 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
787 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
789 unsigned int desty = cell_offset_y;
796 if ( ui_selected -> ref -> title_en ) {
798 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, c -> fontcolor );
801 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
803 dest -> x = cell_offset_x;
805 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
806 SDL_FreeSurface ( rtext );
813 if ( ui_selected -> ref -> main_category ) {
815 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
818 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
821 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
823 dest -> x = cell_offset_x;
825 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
826 SDL_FreeSurface ( rtext );
833 if ( ui_selected -> ref -> clockspeed ) {
835 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
838 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
841 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
843 dest -> x = cell_offset_x;
845 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
846 SDL_FreeSurface ( rtext );
851 // show sub-app# on right side of cpu clock?
852 //if ( ui_selected -> ref -> subapp_number )
854 sprintf ( buffer, "(app#%u)", ui_selected -> ref -> subapp_number );
857 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
858 dest -> x = cell_offset_x + cell_width - rtext -> w;
859 dest -> y = desty - src.h;
860 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
861 SDL_FreeSurface ( rtext );
866 #if 0 // merged into hint-line
867 if ( ui_selected -> ref -> info_filename ) {
869 sprintf ( buffer, "Documentation - hit Y" );
872 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
875 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
877 dest -> x = cell_offset_x;
879 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
880 SDL_FreeSurface ( rtext );
887 if ( ui_selected -> ovrh ) {
892 desty += 5; // a touch of spacing can't hurt
894 for ( i = 1; i < 4; i++ ) {
895 sprintf ( buffer, "Application-%u.note-%u", ui_selected -> ref -> subapp_number, i );
896 n = pnd_conf_get_as_char ( ui_selected -> ovrh, buffer );
900 rtext = TTF_RenderText_Blended ( g_detailtext_font, n, c -> fontcolor );
903 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
905 dest -> x = cell_offset_x;
907 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
908 SDL_FreeSurface ( rtext );
914 } // r_detail -> notes
917 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
918 SDL_Surface *previewpic;
921 previewpic = ic -> i;
923 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
927 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
928 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
929 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
930 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
936 char *empty_message = "Press SELECT for menu";
940 rtext = TTF_RenderText_Blended ( g_detailtext_font, empty_message, c -> fontcolor );
944 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
946 dest -> x = cell_offset_x;
948 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
949 SDL_FreeSurface ( rtext );
954 rtext = TTF_RenderText_Blended ( g_detailtext_font, "START or B to run app", c -> fontcolor );
955 dest -> x = cell_offset_x;
957 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
958 SDL_FreeSurface ( rtext );
962 rtext = TTF_RenderText_Blended ( g_detailtext_font, "SPACE for app menu", c -> fontcolor );
963 dest -> x = cell_offset_x;
965 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
966 SDL_FreeSurface ( rtext );
970 rtext = TTF_RenderText_Blended ( g_detailtext_font, "A to toggle details", c -> fontcolor );
971 dest -> x = cell_offset_x;
973 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
974 SDL_FreeSurface ( rtext );
978 } // r_detail && selected?
986 if ( render_jobs_b & R_BG ) {
987 static int last_battlevel = 0;
988 static unsigned char batterylevel = 0;
991 if ( time ( NULL ) - last_battlevel > 60 ) {
992 batterylevel = pnd_device_get_battery_gauge_perc();
993 last_battlevel = time ( NULL );
996 sprintf ( buffer, "Battery: %u%%", batterylevel );
999 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1000 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.battery_x", 20 );
1001 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
1002 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1003 SDL_FreeSurface ( rtext );
1008 if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
1010 unsigned int hintx, hinty;
1011 hintx = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
1012 hinty = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
1013 static unsigned int lastwidth = 3000;
1015 if ( ui_selected && ui_selected -> ref -> info_filename ) {
1016 buffer = "Documentation - hit Y";
1018 buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
1022 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1025 if ( ! ( render_jobs_b & R_BG ) ) {
1032 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, &src, sdl_realscreen, dest );
1034 lastwidth = rtext -> w;
1040 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1041 SDL_FreeSurface ( rtext );
1046 if ( render_jobs_b & R_BG &&
1047 pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 )
1051 time_t t = time ( NULL );
1052 struct tm *tm = localtime ( &t );
1053 strftime ( buffer, 50, "%a %H:%M %F", tm );
1056 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1057 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.clock_x", 700 );
1058 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.clock_y", 450 );
1059 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1060 SDL_FreeSurface ( rtext );
1064 // update all the rects and send it all to sdl
1065 // - at this point, we could probably just do 1 rect, of the
1066 // whole screen, and be faster :/
1067 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1071 void ui_process_input ( pnd_dbusnotify_handle dbh, pnd_notify_handle nh ) {
1074 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
1075 //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
1077 while ( ( ! ui_event ) &&
1078 /*block_p ?*/ SDL_WaitEvent ( &event ) /*: SDL_PollEvent ( &event )*/ )
1081 switch ( event.type ) {
1086 // the user-defined SDL events are all for threaded/delayed previews (and icons, which
1087 // generally are not used); if we're in wide mode, we can skip previews
1088 // to avoid slowing things down when they're not shown.
1090 if ( event.user.code == sdl_user_ticker ) {
1092 if ( ui_detail_hidden ) {
1093 break; // skip building previews when not showing them
1096 // timer went off, time to load something
1097 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1099 if ( ! ui_selected ) {
1103 // load the preview pics now!
1104 pnd_disco_t *iter = ui_selected -> ref;
1106 if ( iter -> preview_pic1 ) {
1108 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.threaded_preview", 0 ) ) {
1109 // load in bg thread, make user experience chuggy
1111 g_preview_thread = SDL_CreateThread ( (void*)ui_threaded_defered_preview, iter );
1113 if ( ! g_preview_thread ) {
1114 pnd_log ( pndn_error, "ERROR: Couldn't create preview thread\n" );
1118 // load it now, make user wait
1120 if ( ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
1121 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
1124 pnd_log ( pndn_debug, " Couldn't load preview pic: '%s' -> '%s'\n",
1125 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1130 } // got a preview at all?
1135 } else if ( event.user.code == sdl_user_finishedpreview ) {
1137 // if we just finished the one we happen to be looking at, better redraw now; otherwise, if
1138 // we finished another, no big woop
1139 if ( ui_selected && event.user.data1 == ui_selected -> ref ) {
1143 } else if ( event.user.code == sdl_user_finishedicon ) {
1144 // redraw, so we can show the newly loaded icon
1147 } else if ( event.user.code == sdl_user_checksd ) {
1148 // check if any inotify-type events occured, forcing us to rescan/re-disco the SDs
1150 unsigned char watch_dbus = 0;
1151 unsigned char watch_inotify = 0;
1154 watch_dbus = pnd_dbusnotify_rediscover_p ( dbh );
1158 watch_inotify = pnd_notify_rediscover_p ( nh );
1161 if ( watch_dbus || watch_inotify ) {
1162 pnd_log ( pndn_debug, "dbusnotify detected SD event\n" );
1163 applications_free();
1164 applications_scan();
1171 render_mask |= CHANGED_EVERYTHING;
1175 #if 0 // joystick motion
1176 case SDL_JOYAXISMOTION:
1178 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
1180 if ( event.jaxis.axis == 0 ) {
1182 if ( event.jaxis.value < 0 ) {
1184 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
1185 } else if ( event.jaxis.value > 0 ) {
1186 ui_push_right ( 0 );
1187 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
1189 } else if ( event.jaxis.axis == 1 ) {
1191 if ( event.jaxis.value < 0 ) {
1193 } else if ( event.jaxis.value > 0 ) {
1203 #if 0 // joystick buttons
1204 case SDL_JOYBUTTONDOWN:
1206 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
1208 if ( event.jbutton.button == 0 ) { // B
1210 } else if ( event.jbutton.button == 1 ) { // Y
1212 } else if ( event.jbutton.button == 2 ) { // X
1214 } else if ( event.jbutton.button == 3 ) { // A
1217 } else if ( event.jbutton.button == 4 ) { // Select
1218 ui_mask |= uisb_select;
1219 } else if ( event.jbutton.button == 5 ) { // Start
1220 ui_mask |= uisb_start;
1222 } else if ( event.jbutton.button == 7 ) { // L
1224 } else if ( event.jbutton.button == 8 ) { // R
1233 case SDL_JOYBUTTONUP:
1235 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
1237 if ( event.jbutton.button == 0 ) { // B
1240 } else if ( event.jbutton.button == 1 ) { // Y
1242 } else if ( event.jbutton.button == 2 ) { // X
1244 } else if ( event.jbutton.button == 3 ) { // A
1247 } else if ( event.jbutton.button == 4 ) { // Select
1248 ui_mask &= ~uisb_select;
1249 } else if ( event.jbutton.button == 5 ) { // Start
1250 ui_mask &= ~uisb_start;
1252 } else if ( event.jbutton.button == 7 ) { // L
1255 } else if ( event.jbutton.button == 8 ) { // R
1266 #if 1 // keyboard events
1270 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
1272 // SDLK_LALT -> Start
1273 // page up/down for y/x
1274 // home/end for a and b
1277 if ( event.key.keysym.sym == SDLK_RIGHT ) {
1278 ui_push_right ( 0 );
1280 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
1283 } else if ( event.key.keysym.sym == SDLK_UP ) {
1286 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1289 } else if ( event.key.keysym.sym == SDLK_END ) { // B
1292 } else if ( event.key.keysym.sym == SDLK_SPACE ) { // space
1293 if ( ui_selected ) {
1294 ui_menu_context ( ui_selected );
1296 // TBD: post an error?
1298 render_mask |= CHANGED_EVERYTHING;
1300 } else if ( event.key.keysym.sym == SDLK_TAB || event.key.keysym.sym == SDLK_HOME ) { // tab or A
1301 // if detail panel is togglable, then toggle it
1302 // if not, make sure its ruddy well shown!
1303 if ( ui_is_detail_hideable() ) {
1304 ui_toggle_detail_pane();
1306 ui_detail_hidden = 0;
1309 } else if ( event.key.keysym.sym == SDLK_RSHIFT || event.key.keysym.sym == SDLK_COMMA ) { // left trigger or comma
1312 } else if ( event.key.keysym.sym == SDLK_RCTRL || event.key.keysym.sym == SDLK_PERIOD ) { // right trigger or period
1316 } else if ( event.key.keysym.sym == SDLK_PAGEUP ) { // Y
1318 if ( ui_selected ) {
1319 ui_show_info ( pnd_run_script, ui_selected -> ref );
1322 } else if ( event.key.keysym.sym == SDLK_PAGEDOWN ) { // X
1325 // forget the selection, nolonger applies
1327 ui_set_selected ( ui_selected );
1329 if ( g_categories [ ui_category ] -> fspath ) {
1330 category_fs_restock ( g_categories [ ui_category ] );
1333 render_mask |= CHANGED_EVERYTHING;
1336 } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
1340 } else if ( event.key.keysym.sym == SDLK_LCTRL /*LALT*/ ) { // select button
1341 char *opts [ 20 ] = {
1342 "Reveal hidden category",
1344 "Configure Minimenu",
1345 "Rescan for applications",
1346 "Cache previews to SD now",
1347 "Run a terminal/console",
1348 "Run another GUI (xfce, etc)",
1350 "Select a Minimenu skin",
1353 int sel = ui_modal_single_menu ( opts, 10, "Minimenu", "Enter to select; other to return." );
1355 char buffer [ 100 ];
1359 } else if ( sel == 1 ) {
1361 sprintf ( buffer, "sudo poweroff" );
1363 } else if ( sel == 2 ) {
1365 unsigned char restart = conf_run_menu ( NULL );
1366 conf_write ( g_conf, conf_determine_location ( g_conf ) );
1368 emit_and_quit ( MM_RESTART );
1370 } else if ( sel == 3 ) {
1372 pnd_log ( pndn_debug, "Freeing up applications\n" );
1373 applications_free();
1374 pnd_log ( pndn_debug, "Rescanning applications\n" );
1375 applications_scan();
1376 } else if ( sel == 4 ) {
1377 // cache preview to SD now
1378 extern pnd_box_handle g_active_apps;
1379 pnd_box_handle h = g_active_apps;
1381 unsigned int maxwidth, maxheight;
1382 maxwidth = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 );
1383 maxheight = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 );
1385 pnd_disco_t *iter = pnd_box_get_head ( h );
1390 if ( ! cache_preview ( iter, maxwidth, maxheight ) ) {
1391 pnd_log ( pndn_debug, "Force cache: Couldn't load preview pic: '%s' -> '%s'\n",
1392 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1396 iter = pnd_box_get_next ( iter );
1399 } else if ( sel == 5 ) {
1402 argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
1406 ui_forkexec ( argv );
1409 } else if ( sel == 6 ) {
1410 char buffer [ PATH_MAX ];
1411 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/pandora/scripts/op_switchgui.sh" );
1412 emit_and_quit ( buffer );
1413 } else if ( sel == 7 ) {
1414 emit_and_quit ( MM_QUIT );
1415 } else if ( sel == 8 ) {
1417 if ( ui_pick_skin() ) {
1418 emit_and_quit ( MM_RESTART );
1420 } else if ( sel == 9 ) {
1422 char buffer [ PATH_MAX ];
1423 sprintf ( buffer, "%s/about.txt", g_skinpath );
1424 ui_aboutscreen ( buffer );
1428 render_mask |= CHANGED_EVERYTHING;
1431 // unknown SDLK_ keycode?
1433 // many SDLK_keycodes map to ASCII ("a" is ascii(a)), so try to jump to a filename of that name, in this category?
1434 // and if already there, try to jump to next, maybe?
1435 // future: look for sequence typing? ie: user types 'm' then 'a', look for 'ma*' instead of 'm' then 'a' matching
1436 if ( isalpha ( event.key.keysym.sym ) && g_categories [ ui_category ] -> refcount > 0 ) {
1437 mm_appref_t *app = g_categories [ ui_category ] -> refs;
1439 //fprintf ( stderr, "sel %s next %s\n", ui_selected -> ref -> title_en, ui_selected -> next -> ref -> title_en );
1441 // are we already matching the same char? and next item is also same char?
1442 if ( app && ui_selected && ui_selected -> next &&
1443 ui_selected -> ref -> title_en && ui_selected -> next -> ref -> title_en &&
1444 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( ui_selected -> next -> ref -> title_en [ 0 ] ) &&
1445 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym )
1448 // just skip down one
1449 app = ui_selected -> next;
1452 // walk the category, looking for a first-char match
1454 if ( app -> ref -> title_en && toupper ( app -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym ) ) {
1460 } // same start letter, or new run?
1462 // found something, or no?
1464 // looks like we found a potential match; try switching it to visible selection
1466 ui_set_selected ( ui_selected );
1471 } // SDLK_alphanumeric?
1477 if ( event.key.keysym.sym == SDLK_ESCAPE ) {
1478 emit_and_quit ( MM_QUIT );
1485 #if 1 // mouse / touchscreen
1487 case SDL_MOUSEBUTTONDOWN:
1488 if ( event.button.button == SDL_BUTTON_LEFT ) {
1489 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
1495 case SDL_MOUSEBUTTONUP:
1496 if ( event.button.button == SDL_BUTTON_LEFT ) {
1497 ui_touch_act ( event.button.x, event.button.y );
1510 } // switch event type
1517 void ui_push_left ( unsigned char forcecoil ) {
1519 if ( ! ui_selected ) {
1520 ui_push_right ( 0 );
1524 // what column we in?
1525 unsigned int col = ui_determine_screen_col ( ui_selected );
1527 // are we already at first item?
1528 if ( forcecoil == 0 &&
1529 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1532 unsigned int i = ui_display_context.col_max - 1;
1533 while ( i && ui_selected -> next ) {
1534 ui_push_right ( 0 );
1538 } else if ( g_categories [ ui_category ] -> refs == ui_selected ) {
1539 // can't go any more left, we're at the head
1542 // figure out the previous item; yay for singly linked list :/
1543 mm_appref_t *i = g_categories [ ui_category ] -> refs;
1545 if ( i -> next == ui_selected ) {
1553 ui_set_selected ( ui_selected );
1558 void ui_push_right ( unsigned char forcecoil ) {
1560 if ( ui_selected ) {
1562 // what column we in?
1563 unsigned int col = ui_determine_screen_col ( ui_selected );
1566 if ( forcecoil == 0 &&
1567 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1568 // and selected is far-right, or last icon in category (might not be far right)
1569 ( ( col == ui_display_context.col_max - 1 ) ||
1570 ( ui_selected -> next == NULL ) )
1574 //unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1575 while ( col /*i*/ ) {
1581 // just go to the next
1583 if ( ui_selected -> next ) {
1584 ui_selected = ui_selected -> next;
1590 ui_selected = g_categories [ ui_category ] -> refs;
1593 ui_set_selected ( ui_selected );
1598 void ui_push_up ( void ) {
1599 unsigned char col_max = ui_display_context.col_max;
1601 if ( ! ui_selected ) {
1606 unsigned int row = ui_determine_row ( ui_selected );
1609 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 0 ) == 0 )
1611 // wrap around instead
1613 unsigned int col = ui_determine_screen_col ( ui_selected );
1616 ui_selected = g_categories [ ui_category ] -> refs;
1617 while ( ui_selected -> next ) {
1618 ui_selected = ui_selected -> next;
1621 // try to move to same column
1622 unsigned int newcol = ui_determine_screen_col ( ui_selected );
1623 if ( newcol > col ) {
1631 // scroll down to show it
1632 int r = ui_determine_row ( ui_selected ) - 1;
1633 if ( r - ui_display_context.row_max > 0 ) {
1634 ui_rows_scrolled_down = (unsigned int) r;
1638 // stop at top/bottom
1650 void ui_push_down ( void ) {
1651 unsigned char col_max = ui_display_context.col_max;
1653 if ( ui_selected ) {
1656 unsigned int row = ui_determine_row ( ui_selected );
1659 unsigned int icon_rows = g_categories [ ui_category ] -> refcount / col_max;
1660 if ( g_categories [ ui_category ] -> refcount % col_max > 0 ) {
1665 if ( row == ( icon_rows - 1 ) &&
1666 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 0 ) == 0 )
1669 unsigned char col = ui_determine_screen_col ( ui_selected );
1671 ui_selected = g_categories [ ui_category ] -> refs;
1674 ui_selected = ui_selected -> next;
1678 ui_rows_scrolled_down = 0;
1680 render_mask |= CHANGED_EVERYTHING;
1685 ui_push_right ( 1 );
1692 ui_push_right ( 0 );
1698 // 'backup' is currently 'X', for going back up in a folder/subcat without having to hit exec on the '..' entry
1699 void ui_push_backup ( void ) {
1701 // a subcat-as-dir, or a dir browser?
1702 if ( g_categories [ ui_category] -> fspath ) {
1703 // dir browser, just climb our way back up
1708 // lop off last word; if the thing ends with /, lop that one, then the next word.
1709 while ( ( c = strrchr ( g_categories [ ui_category] -> fspath, '/' ) ) ) {
1710 *c = '\0'; // lop off the last hunk
1711 if ( *(c+1) != '\0' ) {
1717 if ( g_categories [ ui_category] -> fspath [ 0 ] == '\0' ) {
1718 free ( g_categories [ ui_category] -> fspath );
1719 g_categories [ ui_category] -> fspath = strdup ( "/" );
1723 // a pnd subcat .. are we in one, or at the 'top'?
1724 char *pcatname = g_categories [ ui_category ] -> parent_catname;
1727 return; // we're at the 'top' already
1730 // set to first cat!
1733 // republish cats .. shoudl just be the one
1734 category_publish ( CFNORMAL, NULL );
1737 ui_category = category_index ( pcatname );
1739 // ensure tab visible?
1740 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1741 if ( ui_category > ui_catshift + ( ui_display_context.screen_width / tab_width ) - 1 ) {
1742 ui_catshift = ui_category - ( ui_display_context.screen_width / tab_width ) + 1;
1752 void ui_push_exec ( void ) {
1754 if ( ! ui_selected ) {
1758 // was this icon generated from filesystem, or from pnd-file?
1759 if ( ui_selected -> ref -> object_flags & PND_DISCO_GENERATED ) {
1761 if ( ! ui_selected -> ref -> title_en ) {
1762 return; // no filename
1765 if ( ui_selected -> ref -> object_type == pnd_object_type_directory ) {
1767 // check if this guy is a dir-browser tab, or is a directory on a pnd tab
1768 if ( ! g_categories [ ui_category] -> fspath ) {
1769 // pnd subcat as dir
1771 // are we already in a subcat? if so, go back to parent; there is no grandparenting or deeper
1772 if ( g_categories [ ui_category ] -> parent_catname ) {
1777 // delve into subcat
1779 // set to first cat!
1783 // republish cats .. shoudl just be the one
1784 category_publish ( CFBYNAME, ui_selected -> ref -> object_path );
1788 // forget the selection, nolonger applies
1790 ui_set_selected ( ui_selected );
1792 render_mask |= CHANGED_EVERYTHING;
1796 // delve up/down the dir tree
1797 if ( strcmp ( ui_selected -> ref -> title_en, ".." ) == 0 ) {
1802 char *temp = malloc ( strlen ( g_categories [ ui_category] -> fspath ) + strlen ( ui_selected -> ref -> title_en ) + 1 + 1 );
1803 sprintf ( temp, "%s/%s", g_categories [ ui_category] -> fspath, ui_selected -> ref -> title_en );
1804 free ( g_categories [ ui_category] -> fspath );
1805 g_categories [ ui_category] -> fspath = temp;
1808 pnd_log ( pndn_debug, "Cat %s is now in path %s\n", g_categories [ ui_category ] -> catname, g_categories [ ui_category ]-> fspath );
1810 // forget the selection, nolonger applies
1812 ui_set_selected ( ui_selected );
1814 category_fs_restock ( g_categories [ ui_category ] );
1816 render_mask |= CHANGED_SELECTION;
1818 } // directory browser or pnd subcat?
1821 // just run it arbitrarily?
1823 // if this a pnd-file, or just some executable?
1824 if ( strcasestr ( ui_selected -> ref -> object_filename, PND_PACKAGE_FILEEXT ) ) {
1825 // looks like a pnd, now what do we do..
1826 pnd_box_handle h = pnd_disco_file ( ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
1829 pnd_disco_t *d = pnd_box_get_head ( h );
1830 pnd_apps_exec_disco ( pnd_run_script, d, PND_EXEC_OPTION_NORUN, NULL );
1831 char buffer [ PATH_MAX ];
1832 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1833 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
1834 emit_and_quit ( buffer );
1836 emit_and_run ( buffer );
1843 // is it even executable? if we don't have handlers for non-executables yet (Jan 2011 we don't),
1844 // then don't even try to run things not-flagged as executable.. but wait most people are on
1845 // FAT filesystems, what a drag, we can't tell at the fs level.
1846 // ... but we can still invoke 'file' and grep out the good bits, at least.
1848 // open a stream reading 'file /path/to/file' and check output for 'executable'
1849 // -- not checking for "ARM" so it can pick up x86 (or whatever native) executables in build environment
1850 unsigned char is_executable = 0;
1854 char popenbuf [ FILENAME_MAX ];
1855 snprintf ( popenbuf, FILENAME_MAX, "%s %s/%s", MIMETYPE_EXE, g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
1858 if ( ! ( marceau = popen ( popenbuf, "r" ) ) ) {
1859 return; // error, we need some useful error handling and dialog boxes here
1862 if ( fgets ( popenbuf, FILENAME_MAX, marceau ) ) {
1863 //printf ( "File test returns: %s\n", popenbuf );
1864 if ( strstr ( popenbuf, "executable" ) != NULL ) {
1873 if ( ! is_executable ) {
1874 fprintf ( stderr, "ERROR: File to invoke is not executable, skipping. (%s)\n", ui_selected -> ref -> title_en );
1875 return; // need some error handling here
1878 #if 0 // eat up any pending SDL events and toss 'em?
1882 while ( SDL_PeepEvents ( &e, 1, SDL_GETEVENT, SDL_ALLEVENTS ) > 0 ) {
1892 // get CWD so we can restore it on return
1893 char cwd [ PATH_MAX ];
1894 getcwd ( cwd, PATH_MAX );
1896 // full path to executable so we don't rely on implicit "./"
1897 char execbuf [ FILENAME_MAX ];
1898 snprintf ( execbuf, FILENAME_MAX, "%s/%s", g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
1901 chdir ( g_categories [ ui_category ] -> fspath );
1902 exec_raw_binary ( execbuf /*ui_selected -> ref -> title_en*/ );
1905 // DEPRECATED / NOT TESTED
1906 // get mmwrapper to run it
1907 char buffer [ PATH_MAX ];
1908 sprintf ( buffer, "%s %s/%s\n", MM_RUN, g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
1909 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
1910 emit_and_quit ( buffer );
1912 emit_and_run ( buffer );
1921 // set app-run speed
1922 int use_run_speed = pnd_conf_get_as_int_d ( g_conf, "minimenu.use_run_speed", 0 );
1923 if ( use_run_speed > 0 ) {
1924 int mm_speed = pnd_conf_get_as_int_d ( g_conf, "minimenu.run_speed", -1 );
1925 if ( mm_speed > -1 ) {
1926 char buffer [ 512 ];
1927 snprintf ( buffer, 500, "sudo /usr/pandora/scripts/op_cpuspeed.sh %d", mm_speed );
1930 } // do speed change?
1932 // request app to run and quit mmenu
1933 pnd_apps_exec_disco ( pnd_run_script, ui_selected -> ref, PND_EXEC_OPTION_NORUN, NULL );
1934 char buffer [ PATH_MAX ];
1935 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1936 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
1937 emit_and_quit ( buffer );
1939 emit_and_run ( buffer );
1946 void ui_push_ltrigger ( void ) {
1947 unsigned char oldcat = ui_category;
1948 unsigned int screen_width = ui_display_context.screen_width;
1949 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1951 if ( g_categorycount == 0 ) {
1955 if ( ui_category > 0 ) {
1957 category_fs_restock ( g_categories [ ui_category ] );
1959 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1960 ui_category = g_categorycount - 1;
1962 if ( ui_category >= ( screen_width / tab_width ) ) {
1963 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
1965 category_fs_restock ( g_categories [ ui_category ] );
1969 if ( oldcat != ui_category ) {
1971 ui_set_selected ( ui_selected );
1974 // make tab visible?
1975 if ( ui_catshift > 0 && ui_category == ui_catshift - 1 ) {
1980 ui_rows_scrolled_down = 0;
1982 render_mask |= CHANGED_CATEGORY;
1987 void ui_push_rtrigger ( void ) {
1988 unsigned char oldcat = ui_category;
1990 if ( g_categorycount == 0 ) {
1994 unsigned int screen_width = ui_display_context.screen_width;
1995 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1997 if ( ui_category < ( g_categorycount - 1 ) ) {
1999 category_fs_restock ( g_categories [ ui_category ] );
2001 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
2004 category_fs_restock ( g_categories [ ui_category ] );
2008 if ( oldcat != ui_category ) {
2010 ui_set_selected ( ui_selected );
2013 // make tab visible?
2014 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2019 ui_rows_scrolled_down = 0;
2021 render_mask |= CHANGED_CATEGORY;
2026 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
2027 double scale = 1000000.0;
2028 double scalex = 1000000.0;
2029 double scaley = 1000000.0;
2030 SDL_Surface *scaled;
2032 scalex = (double)maxwidth / (double)s -> w;
2034 if ( maxheight == -1 ) {
2037 scaley = (double)maxheight / (double)s -> h;
2039 if ( scaley < scalex ) {
2047 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
2048 SDL_FreeSurface ( s );
2054 void ui_loadscreen ( void ) {
2059 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2063 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", ui_display_context.fontcolor );
2066 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
2067 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2068 SDL_FreeSurface ( rtext );
2073 void ui_discoverscreen ( unsigned char clearscreen ) {
2078 if ( clearscreen ) {
2079 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2081 // render background
2082 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2085 dest.w = sdl_realscreen -> w;
2086 dest.h = sdl_realscreen -> h;
2087 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
2088 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2095 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", ui_display_context.fontcolor );
2096 if ( clearscreen ) {
2103 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
2104 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2105 SDL_FreeSurface ( rtext );
2108 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
2109 dest.x = rtext -> w + 30;
2111 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
2112 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2118 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
2120 SDL_Rect rects [ 4 ];
2121 SDL_Rect *dest = rects;
2123 bzero ( dest, sizeof(SDL_Rect)* 4 );
2125 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
2126 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
2127 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
2128 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
2130 static unsigned int stepx = 0;
2133 if ( clearscreen ) {
2134 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2136 // render background
2137 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2140 dest -> w = sdl_realscreen -> w;
2141 dest -> h = sdl_realscreen -> h;
2142 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
2148 // render background
2149 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2152 src.w = sdl_realscreen -> w;
2156 dest -> w = sdl_realscreen -> w;
2157 dest -> h = sdl_realscreen -> h;
2158 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
2166 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
2167 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
2170 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2171 SDL_FreeSurface ( rtext );
2175 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
2176 dest -> x = rtext -> w + 30 + stepx;
2178 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
2184 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
2187 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2188 SDL_FreeSurface ( rtext );
2195 if ( stepx > 350 ) {
2199 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
2204 int ui_selected_index ( void ) {
2206 if ( ! ui_selected ) {
2207 return ( -1 ); // no index
2210 mm_appref_t *r = g_categories [ ui_category ] -> refs;
2213 if ( r == ui_selected ) {
2223 static mm_appref_t *timer_ref = NULL;
2224 void ui_set_selected ( mm_appref_t *r ) {
2226 render_mask |= CHANGED_SELECTION;
2228 if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
2229 return; // no desire to defer anything
2234 SDL_SetTimer ( 0, NULL );
2239 SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
2245 unsigned int ui_callback_f ( unsigned int t ) {
2247 if ( ui_selected != timer_ref ) {
2248 return ( 0 ); // user has moved it, who cares
2252 bzero ( &e, sizeof(SDL_Event) );
2253 e.type = SDL_USEREVENT;
2254 e.user.code = sdl_user_ticker;
2255 SDL_PushEvent ( &e );
2260 int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
2261 SDL_Rect rects [ 40 ];
2262 SDL_Rect *dest = rects;
2265 unsigned char max_visible = pnd_conf_get_as_int_d ( g_conf, "detailtext.max_visible" , 11 );
2266 unsigned char first_visible = 0;
2268 bzero ( rects, sizeof(SDL_Rect) * 40 );
2270 unsigned int sel = 0;
2272 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 };
2280 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2281 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2282 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
2283 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
2284 SDL_FillRect( sdl_realscreen, dest, 0 );
2286 // show dialog background
2287 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
2290 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> w;
2291 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> h;
2292 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2293 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2294 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2295 // repeat for darken?
2296 //SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2297 //SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2298 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2302 // show dialog frame
2303 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
2304 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2305 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2306 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
2307 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2313 rtext = TTF_RenderText_Blended ( g_tab_font, title, ui_display_context.fontcolor );
2314 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2315 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
2316 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2317 SDL_FreeSurface ( rtext );
2323 rtext = TTF_RenderText_Blended ( g_tab_font, footer, ui_display_context.fontcolor );
2324 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2325 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
2326 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
2328 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2329 SDL_FreeSurface ( rtext );
2334 for ( i = first_visible; i < first_visible + max_visible && i < argc; i++ ) {
2338 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
2340 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], ui_display_context.fontcolor );
2342 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2343 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 - first_visible ) );
2344 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2345 SDL_FreeSurface ( rtext );
2350 // update all the rects and send it all to sdl
2351 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
2355 while ( SDL_WaitEvent ( &event ) ) {
2357 switch ( event.type ) {
2362 if ( event.key.keysym.sym == SDLK_UP ) {
2366 if ( sel < first_visible ) {
2371 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
2373 if ( sel < argc - 1 ) {
2376 // ensure visibility
2377 if ( sel >= first_visible + max_visible ) {
2383 } else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_END ) { // return, or "B"
2387 } else if ( event.key.keysym.sym == SDLK_q ) {
2392 return ( -1 ); // nada
2407 unsigned char ui_determine_row ( mm_appref_t *a ) {
2408 unsigned int row = 0;
2410 mm_appref_t *i = g_categories [ ui_category ] -> refs;
2415 row /= ui_display_context.col_max;
2420 unsigned char ui_determine_screen_row ( mm_appref_t *a ) {
2421 return ( ui_determine_row ( a ) % ui_display_context.row_max );
2424 unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
2425 unsigned int col = 0;
2427 mm_appref_t *i = g_categories [ ui_category ] -> refs;
2432 col %= ui_display_context.col_max;
2437 unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ) {
2438 char *viewer, *searchpath;
2439 pnd_conf_handle desktoph;
2442 searchpath = pnd_conf_query_searchpath();
2444 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
2450 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
2453 return ( 0 ); // no way to view the file
2457 if ( ! p -> unique_id ) {
2461 if ( ! p -> info_filename ) {
2465 if ( ! p -> info_name ) {
2476 if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
2477 snprintf ( pargs, 1001, "%s %s",
2478 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
2483 char pndfile [ 1024 ];
2484 if ( p -> object_type == pnd_object_type_directory ) {
2485 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
2486 strncpy ( pndfile, p -> object_path, 1000 );
2487 } else if ( p -> object_type == pnd_object_type_pnd ) {
2488 // pnd_run.sh wants the full path and filename for the .pnd file
2489 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
2492 if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
2493 p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
2498 pnd_log ( pndn_debug, "Info Exec=%s\n", pnd_apps_exec_runline() );
2502 if ( ( x = fork() ) < 0 ) {
2503 pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
2508 execl ( "/bin/sh", "/bin/sh", "-c", pnd_apps_exec_runline(), (char*)NULL );
2509 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", pnd_apps_exec_runline() );
2521 #define MAXTOUCH 100
2522 ui_touch_t ui_touchrects [ MAXTOUCH ];
2523 unsigned char ui_touchrect_count = 0;
2525 void ui_register_reset ( void ) {
2526 bzero ( ui_touchrects, sizeof(ui_touch_t)*MAXTOUCH );
2527 ui_touchrect_count = 0;
2531 void ui_register_tab ( unsigned char catnum, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2533 if ( ui_touchrect_count == MAXTOUCH ) {
2537 ui_touchrects [ ui_touchrect_count ].r.x = x;
2538 ui_touchrects [ ui_touchrect_count ].r.y = y;
2539 ui_touchrects [ ui_touchrect_count ].r.w = w;
2540 ui_touchrects [ ui_touchrect_count ].r.h = h;
2541 ui_touchrects [ ui_touchrect_count ].catnum = catnum;
2542 ui_touchrect_count++;
2547 void ui_register_app ( mm_appref_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2549 if ( ui_touchrect_count == MAXTOUCH ) {
2553 ui_touchrects [ ui_touchrect_count ].r.x = x;
2554 ui_touchrects [ ui_touchrect_count ].r.y = y;
2555 ui_touchrects [ ui_touchrect_count ].r.w = w;
2556 ui_touchrects [ ui_touchrect_count ].r.h = h;
2557 ui_touchrects [ ui_touchrect_count ].ref = app;
2558 ui_touchrect_count++;
2563 void ui_touch_act ( unsigned int x, unsigned int y ) {
2568 for ( i = 0; i < ui_touchrect_count; i++ ) {
2569 t = &(ui_touchrects [ i ]);
2571 if ( x >= t -> r.x &&
2572 x <= t -> r.x + t -> r.w &&
2574 y <= t -> r.y + t -> r.h
2579 ui_selected = t -> ref;
2582 if ( ui_category != t -> catnum ) {
2585 ui_category = t -> catnum;
2586 render_mask |= CHANGED_CATEGORY;
2588 category_fs_restock ( g_categories [ ui_category ] );
2599 unsigned char ui_forkexec ( char *argv[] ) {
2600 char *fooby = argv[0];
2603 if ( ( x = fork() ) < 0 ) {
2604 pnd_log ( pndn_error, "ERROR: Couldn't fork() for '%s'\n", fooby );
2608 if ( x == 0 ) { // child
2609 execv ( fooby, argv );
2610 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", fooby );
2618 unsigned char ui_threaded_timer_create ( void ) {
2620 g_timer_thread = SDL_CreateThread ( (void*)ui_threaded_timer, NULL );
2622 if ( ! g_timer_thread ) {
2623 pnd_log ( pndn_error, "ERROR: Couldn't create timer thread\n" );
2630 int ui_threaded_timer ( pnd_disco_t *p ) {
2632 // this timer's job is to ..
2633 // - do nothing for quite awhile
2634 // - on wake, post event to SDL event queue, so that main thread will check if SD insert/eject occurred
2637 unsigned int delay_s = 2; // seconds
2644 // .. trigger SD check
2646 bzero ( &e, sizeof(SDL_Event) );
2647 e.type = SDL_USEREVENT;
2648 e.user.code = sdl_user_checksd;
2649 SDL_PushEvent ( &e );
2656 unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
2658 if ( ! cache_preview ( p, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
2659 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
2662 pnd_log ( pndn_debug, "THREAD: Couldn't load preview pic: '%s' -> '%s'\n",
2663 IFNULL(p->title_en,"No Name"), p -> preview_pic1 );
2666 // trigger that we completed
2668 bzero ( &e, sizeof(SDL_Event) );
2669 e.type = SDL_USEREVENT;
2670 e.user.code = sdl_user_finishedpreview;
2672 SDL_PushEvent ( &e );
2677 SDL_Thread *g_icon_thread = NULL;
2678 void ui_post_scan ( void ) {
2680 // if deferred icon load, kick off the thread now
2681 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 1 ) {
2683 g_icon_thread = SDL_CreateThread ( (void*)ui_threaded_defered_icon, NULL );
2685 if ( ! g_icon_thread ) {
2686 pnd_log ( pndn_error, "ERROR: Couldn't create icon thread\n" );
2689 } // deferred icon load
2693 ui_rows_scrolled_down = 0;
2694 // set back to first tab, to be safe
2698 // do we have a preferred category to jump to?
2699 char *dc = pnd_conf_get_as_char ( g_conf, "categories.default_cat" );
2702 // attempt to find default cat; if we do find it, select it; otherwise
2703 // default behaviour will pick first cat (ie: usually All)
2705 for ( i = 0; i < g_categorycount; i++ ) {
2706 if ( strcasecmp ( g_categories [ i ] -> catname, dc ) == 0 ) {
2708 // ensure visibility
2709 unsigned int screen_width = ui_display_context.screen_width;
2710 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2711 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2712 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
2718 if ( i == g_categorycount ) {
2719 pnd_log ( pndn_warning, " User defined default category '%s' but not found, so using default behaviour\n", dc );
2724 // if we're sent right to a dirbrowser tab, restock it now (normally we restock on entry)
2725 if ( g_categories [ ui_category ] -> fspath ) {
2726 printf ( "Restock on start: '%s'\n", g_categories [ ui_category ] -> fspath );
2727 category_fs_restock ( g_categories [ ui_category ] );
2731 render_mask |= CHANGED_EVERYTHING;
2736 unsigned char ui_threaded_defered_icon ( void *p ) {
2737 extern pnd_box_handle g_active_apps;
2738 pnd_box_handle h = g_active_apps;
2740 unsigned char maxwidth, maxheight;
2741 maxwidth = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 );
2742 maxheight = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_height", 50 );
2744 pnd_disco_t *iter = pnd_box_get_head ( h );
2749 if ( iter -> pnd_icon_pos &&
2750 ! cache_icon ( iter, maxwidth, maxheight ) )
2752 pnd_log ( pndn_warning, " Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2755 // trigger that we completed
2757 bzero ( &e, sizeof(SDL_Event) );
2758 e.type = SDL_USEREVENT;
2759 e.user.code = sdl_user_finishedicon;
2760 SDL_PushEvent ( &e );
2762 //pnd_log ( pndn_warning, " Finished deferred load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2763 usleep ( pnd_conf_get_as_int_d ( g_conf, "minimenu.defer_icon_us", 50000 ) );
2768 iter = pnd_box_get_next ( iter );
2774 void ui_show_hourglass ( unsigned char updaterect ) {
2777 SDL_Surface *s = g_imagecache [ IMG_HOURGLASS ].i;
2779 dest.x = ( 800 - s -> w ) / 2;
2780 dest.y = ( 480 - s -> h ) / 2;
2782 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, &dest );
2785 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2791 unsigned char ui_pick_skin ( void ) {
2793 char *skins [ MAXSKINS ];
2796 char *searchpath = pnd_conf_get_as_char ( g_conf, "minimenu.skin_searchpath" );
2797 char tempname [ 100 ];
2801 skins [ iter++ ] = "No skin change";
2805 DIR *d = opendir ( buffer );
2810 while ( ( dd = readdir ( d ) ) ) {
2812 if ( dd -> d_name [ 0 ] == '.' ) {
2814 } else if ( ( dd -> d_type == DT_DIR || dd -> d_type == DT_UNKNOWN ) &&
2817 snprintf ( tempname, 100, "Skin: %s", dd -> d_name );
2818 skins [ iter++ ] = strdup ( tempname );
2829 int sel = ui_modal_single_menu ( skins, iter, "Skins", "Enter to select; other to return." );
2831 // did they pick one?
2835 char *s = strdup ( pnd_conf_get_as_char ( g_conf, "minimenu.skin_selected" ) );
2836 s = pnd_expand_tilde ( s );
2838 f = fopen ( s, "w" );
2843 fprintf ( f, "%s\n", skins [ sel ] + 6 );
2853 void ui_aboutscreen ( char *textpath ) {
2860 #define ROWS SCRH / ( PIXELH + MARGINH )
2861 #define COLS SCRW / ( PIXELW + MARGINW )
2863 unsigned char pixelboard [ ROWS * COLS ]; // pixel heat
2864 bzero ( pixelboard, ROWS * COLS );
2869 SDL_Color rtextc = { 200, 200, 200, 100 };
2872 char *textloop [ 500 ];
2873 unsigned int textmax = 0;
2874 bzero ( textloop, 500 * sizeof(char*) );
2877 char cbuffer [ 50000 ];
2878 bzero ( cbuffer, 50000 );
2879 unsigned int crevealed = 0;
2881 FILE *f = fopen ( textpath, "r" );
2884 pnd_log ( pndn_error, "ERROR: Couldn't open about text: %s\n", textpath );
2888 char textbuf [ 100 ];
2889 while ( fgets ( textbuf, 100, f ) ) {
2891 // add to full buffer
2892 strncat ( cbuffer, textbuf, 50000 );
2895 if ( strchr ( textbuf, '\n' ) ) {
2896 * strchr ( textbuf, '\n' ) = '\0';
2899 // add to pixel loop
2900 if ( 1||textbuf [ 0 ] ) {
2901 textloop [ textmax ] = strdup ( textbuf );
2909 unsigned int textiter = 0;
2910 while ( textiter < textmax ) {
2911 char *text = textloop [ textiter ];
2915 // render to surface
2916 rtext = TTF_RenderText_Blended ( g_grid_font, text, rtextc );
2918 // render font to pixelboard
2919 unsigned int px, py;
2921 unsigned int *pixels = rtext -> pixels;
2922 unsigned char cr, cg, cb, ca;
2923 for ( py = 0; py < rtext -> h; py ++ ) {
2924 for ( px = 0; px < ( rtext -> w > COLS ? COLS : rtext -> w ); px++ ) {
2926 SDL_GetRGBA ( pixels [ ( py * rtext -> pitch / 4 ) + px ],
2927 rtext -> format, &cr, &cg, &cb, &ca );
2931 ph = pixelboard + ( /*y offset */ 30 * COLS ) + ( py * COLS ) + px /* / 2 */;
2938 if ( *ph + ca < 250 ) {
2949 unsigned int runcount = 10;
2950 while ( runcount-- ) {
2953 SDL_FillRect( sdl_realscreen, NULL /* whole */, 0 );
2955 // render pixelboard
2958 for ( y = 0; y < ROWS; y++ ) {
2959 for ( x = 0; x < COLS; x++ ) {
2961 if ( 1||pixelboard [ ( y * COLS ) + x ] ) {
2964 r.x = x * ( PIXELW + MARGINW );
2965 r.y = y * ( PIXELH + MARGINH );
2969 c = SDL_MapRGB ( sdl_realscreen -> format, 100 /* r */, 0 /* g */, pixelboard [ ( y * COLS ) + x ] );
2971 SDL_FillRect( sdl_realscreen, &r /* whole */, c );
2979 unsigned char *pc = pixelboard;
2980 for ( y = 0; y < ROWS; y++ ) {
2981 for ( x = 0; x < COLS; x++ ) {
2991 // slide pixels upwards
2992 memmove ( pixelboard, pixelboard + COLS, ( COLS * ROWS ) - COLS );
2994 // render actual readable text
2997 // display up to cursor
2999 unsigned int cdraw = 0;
3003 if ( crevealed > 200 ) {
3004 cdraw = crevealed - 200;
3010 for ( ; cdraw < crevealed; cdraw++ ) {
3011 ctb [ 0 ] = cbuffer [ cdraw ];
3013 // move over or down
3014 if ( cbuffer [ cdraw ] == '\n' ) {
3019 if ( dest.y > 450 ) {
3025 cs = TTF_RenderText_Blended ( g_tab_font, ctb, rtextc );
3027 SDL_BlitSurface ( cs, NULL /* all */, sdl_realscreen, &dest );
3028 SDL_FreeSurface ( cs );
3038 SDL_FillRect ( sdl_realscreen, &dest /* whole */, 220 );
3040 // increment cursor to next character
3041 if ( cbuffer [ crevealed ] != '\0' ) {
3045 } // draw cursor text
3049 SDL_UpdateRect ( sdl_realscreen, 0, 0, 0, 0 ); // whole screen
3053 // any button? if so, about
3059 if ( SDL_PeepEvents ( &e, 1, SDL_GETEVENT, SDL_EVENTMASK(/*SDL_KEYUP|*/SDL_KEYDOWN) ) > 0 ) {
3068 SDL_FreeSurface ( rtext );
3072 } // while more text
3076 for ( i = 0; i < textmax; i++ ) {
3077 if ( textloop [ i ] ) {
3078 free ( textloop [ i ] );
3086 void ui_revealscreen ( void ) {
3087 char *labels [ 500 ];
3088 unsigned int labelmax = 0;
3090 char fulllabel [ 200 ];
3092 if ( ! category_count ( CFHIDDEN ) ) {
3093 return; // nothing to do
3096 // switch to hidden categories
3097 category_publish ( CFHIDDEN, NULL );
3099 // build up labels to show in menu
3100 for ( i = 0; i < g_categorycount; i++ ) {
3102 if ( g_categories [ i ] -> parent_catname ) {
3103 sprintf ( fulllabel, "%s [%s]", g_categories [ i ] -> catname, g_categories [ i ] -> parent_catname );
3105 sprintf ( fulllabel, "%s", g_categories [ i ] -> catname );
3108 labels [ labelmax++ ] = strdup ( fulllabel );
3112 int sel = ui_modal_single_menu ( labels, labelmax, "Temporary Category Reveal",
3113 "Enter to select; other to return." );
3115 // if selected, try to set this guy to visible
3118 // fix up category name, if its been hacked
3119 if ( strchr ( g_categories [ sel ] -> catname, '.' ) ) {
3120 char *t = g_categories [ sel ] -> catname;
3121 g_categories [ sel ] -> catname = strdup ( strchr ( g_categories [ sel ] -> catname, '.' ) + 1 );
3125 // reflag this guy to be visible
3126 g_categories [ sel ] -> catflags = CFNORMAL;
3128 // switch to the new category.. cache name.
3129 char *switch_to_name = g_categories [ sel ] -> catname;
3131 // republish categories
3132 category_publish ( CFNORMAL, NULL );
3134 // switch to the new category.. with the cached name!
3135 ui_category = category_index ( switch_to_name );
3137 // ensure visibility
3138 unsigned int screen_width = ui_display_context.screen_width;
3139 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
3140 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
3141 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
3145 render_mask |= CHANGED_CATEGORY;
3148 for ( i = 0; i < g_categorycount; i++ ) {
3149 free ( labels [ i ] );
3155 void ui_recache_context ( ui_context_t *c ) {
3157 c -> screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
3159 c -> font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
3160 c -> font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
3161 c -> font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
3162 c -> font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
3164 c -> grid_offset_x = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_x" );
3165 c -> grid_offset_y = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_y" );
3167 c -> icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
3168 c -> icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
3169 c -> icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
3170 c -> icon_max_height = pnd_conf_get_as_int ( g_conf, "grid.icon_max_height" );
3171 c -> sel_icon_offset_x = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_x", 0 );
3172 c -> sel_icon_offset_y = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_y", 0 );
3174 c -> text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
3175 c -> text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
3176 c -> text_offset_x = pnd_conf_get_as_int ( g_conf, "grid.text_offset_x" );
3177 c -> text_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_offset_y" );
3178 c -> text_hilite_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
3180 c -> row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 4 );
3181 c -> col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
3183 c -> cell_width = pnd_conf_get_as_int ( g_conf, "grid.cell_width" );
3184 c -> cell_height = pnd_conf_get_as_int ( g_conf, "grid.cell_height" );
3186 c -> arrow_bar_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
3187 c -> arrow_bar_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
3188 c -> arrow_bar_clip_w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
3189 c -> arrow_bar_clip_h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
3190 c -> arrow_up_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
3191 c -> arrow_up_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
3192 c -> arrow_down_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
3193 c -> arrow_down_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
3196 SDL_Color tmp = { c -> font_rgba_r, c -> font_rgba_g, c -> font_rgba_b, c -> font_rgba_a };
3197 c -> fontcolor = tmp;
3199 // now that we've got 'normal' (detail pane shown) param's, lets check if detail pane
3200 // is hidden; if so, override some values with those alternate skin values where possible.
3201 if ( ui_detail_hidden ) {
3202 // if detail panel is hidden, and theme cannot support it, unhide the bloody thing. (This may help
3203 // when someone is amid theme hacking or changing.)
3204 if ( ! ui_is_detail_hideable() ) {
3205 ui_detail_hidden = 0;
3209 if ( ui_detail_hidden ) {
3211 c -> row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max_w", c -> row_max );
3212 c -> col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max_w", c -> col_max );
3214 c -> cell_width = pnd_conf_get_as_int_d ( g_conf, "grid.cell_width_w", c -> cell_width );
3215 c -> cell_height = pnd_conf_get_as_int_d ( g_conf, "grid.cell_height_w", c -> cell_height );
3217 c -> arrow_bar_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x_w", 450 );
3218 c -> arrow_bar_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y_w", 100 );
3219 c -> arrow_up_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x_w", 450 );
3220 c -> arrow_up_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y_w", 80 );
3221 c -> arrow_down_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x_w", 450 );
3222 c -> arrow_down_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y_w", 80 );
3224 } // if detail hidden.. still.
3226 } // if detail hidden
3231 unsigned char ui_is_detail_hideable ( void ) {
3233 // if skin has a bit of info for wide-mode, we assume wide-mode is available
3234 if ( pnd_conf_get_as_char ( g_conf, "grid.row_max_w" ) != NULL ) {
3242 void ui_toggle_detail_pane ( void ) {
3244 // no bitmask trickery here; I like it to be stand-out obvious at 3am.
3246 if ( ui_detail_hidden ) {
3247 ui_detail_hidden = 0;
3249 ui_detail_hidden = 1;
3252 // repull skin config
3253 ui_recache_context ( &ui_display_context );
3256 render_mask |= CHANGED_EVERYTHING;
3261 void ui_menu_context ( mm_appref_t *a ) {
3263 unsigned char rescan_apps = 0;
3264 unsigned char context_alive = 1;
3269 context_file_delete,
3272 context_app_recategorize,
3273 context_app_recategorize_sub,
3275 context_app_cpuspeed,
3283 char *verbiage[] = {
3284 "Done (return to grid)", // context_done
3285 "Get info about file/dir", // context_file_info
3286 "Delete file/dir", // context_file_delete
3287 "Get info", // context_app_info
3288 "Hide application", // hide
3289 "Recategorize", // recategorize
3290 "Recategorize subcategory", // recategorize
3291 "Change displayed title", // rename
3292 "Set CPU speed for launch", // cpuspeed
3293 "Run application", // run
3294 "Edit notes line 1", // notes1
3295 "Edit notes line 2", // notes2
3296 "Edit notes line 3", // notes3
3299 unsigned short int menu [ context_menu_max ];
3300 char *menustring [ context_menu_max ];
3301 unsigned char menumax = 0;
3304 menu [ menumax ] = context_done; menustring [ menumax++ ] = verbiage [ context_done ];
3306 // hook up appropriate menu options based on tab-type and object-type
3307 if ( g_categories [ ui_category ] -> fspath ) {
3309 menu [ menumax ] = context_file_info; menustring [ menumax++ ] = verbiage [ context_file_info ];
3310 menu [ menumax ] = context_file_delete; menustring [ menumax++ ] = verbiage [ context_file_delete ];
3313 if ( a -> ref -> object_type == pnd_object_type_directory ) {
3314 return; // don't do anything if the guy is a subcat-as-folder
3317 //menu [ menumax ] = context_app_info; menustring [ menumax++ ] = verbiage [ context_app_info ];
3318 menu [ menumax ] = context_app_run; menustring [ menumax++ ] = verbiage [ context_app_run ];
3319 menu [ menumax ] = context_app_hide; menustring [ menumax++ ] = verbiage [ context_app_hide ];
3320 menu [ menumax ] = context_app_recategorize; menustring [ menumax++ ] = verbiage [ context_app_recategorize ];
3321 menu [ menumax ] = context_app_recategorize_sub; menustring [ menumax++ ] = verbiage [ context_app_recategorize_sub ];
3322 menu [ menumax ] = context_app_rename; menustring [ menumax++ ] = verbiage [ context_app_rename ];
3323 menu [ menumax ] = context_app_cpuspeed; menustring [ menumax++ ] = verbiage [ context_app_cpuspeed ];
3324 menu [ menumax ] = context_app_notes1; menustring [ menumax++ ] = verbiage [ context_app_notes1 ];
3325 menu [ menumax ] = context_app_notes2; menustring [ menumax++ ] = verbiage [ context_app_notes2 ];
3326 menu [ menumax ] = context_app_notes3; menustring [ menumax++ ] = verbiage [ context_app_notes3 ];
3330 while ( context_alive ) {
3332 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 */ );
3339 switch ( menu [ sel ] ) {
3345 case context_file_info:
3348 case context_file_delete:
3349 //ui_menu_twoby ( "Delete - Are you sure?", "B/enter; other to cancel", "Delete", "Do not delete" );
3352 case context_app_info:
3355 case context_app_hide:
3358 char confkey [ 1000 ];
3359 snprintf ( confkey, 999, "%s.%s", "appshow", a -> ref -> unique_id );
3362 pnd_conf_set_char ( g_conf, confkey, "0" );
3364 // write conf, so it will take next time
3365 conf_write ( g_conf, conf_determine_location ( g_conf ) );
3367 // request rescan and wrap up
3369 context_alive = 0; // nolonger visible, so lets just get out
3375 case context_app_recategorize:
3378 unsigned char optmax = 0;
3381 i = 2; // skip first two - Other and NoParentCategory
3384 if ( ! freedesktop_complete [ i ].cat ) {
3388 if ( ! freedesktop_complete [ i ].parent_cat ) {
3389 opts [ optmax++ ] = freedesktop_complete [ i ].cat;
3395 char prompt [ 101 ];
3396 snprintf ( prompt, 100, "Pick category [%s]", a -> ref -> main_category ? a -> ref -> main_category : "NoParentCategory" );
3398 int sel = ui_modal_single_menu ( opts, optmax, prompt /*"Select parent category"*/, "Enter to select; other to skip." );
3401 char confirm [ 1001 ];
3402 snprintf ( confirm, 1000, "Confirm: %s", opts [ sel ] );
3404 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm categorization", "Do not set category" ) == 1 ) {
3405 ovr_replace_or_add ( a, "maincategory", opts [ sel ] );
3414 case context_app_recategorize_sub:
3417 unsigned char optmax = 0;
3423 if ( ! freedesktop_complete [ i ].cat ) {
3427 if ( freedesktop_complete [ i ].parent_cat ) {
3428 opts [ optmax++ ] = freedesktop_complete [ i ].cat;
3434 char prompt [ 101 ];
3435 snprintf ( prompt, 100, "Pick subcategory [%s]", a -> ref -> main_category1 ? a -> ref -> main_category1 : "NoSubcategory" );
3437 int sel = ui_modal_single_menu ( opts, optmax, prompt /*"Select subcategory"*/, "Enter to select; other to skip." );
3440 char confirm [ 1001 ];
3441 snprintf ( confirm, 1000, "Confirm: %s", opts [ sel ] );
3443 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm sub-categorization", "Do not set sub-category" ) == 1 ) {
3444 ovr_replace_or_add ( a, "maincategorysub1", opts [ sel ] );
3453 case context_app_rename:
3455 char namebuf [ 101 ];
3456 unsigned char changed;
3458 changed = ui_menu_get_text_line ( "Rename application", "Use keyboard; Enter when done.",
3459 a -> ref -> title_en ? a -> ref -> title_en : "blank", namebuf, 30, 0 /* alphanumeric */ );
3462 char confirm [ 1001 ];
3463 snprintf ( confirm, 1000, "Confirm: %s", namebuf );
3465 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm rename", "Do not rename" ) == 1 ) {
3466 ovr_replace_or_add ( a, "title", namebuf );
3476 case context_app_cpuspeed:
3478 char namebuf [ 101 ];
3479 unsigned char changed;
3481 changed = ui_menu_get_text_line ( "Specify runspeed", "Use keyboard; Enter when done.",
3482 a -> ref -> clockspeed ? a -> ref -> clockspeed : "500", namebuf, 6, 1 /* numeric */ );
3485 char confirm [ 1001 ];
3486 snprintf ( confirm, 1000, "Confirm: %s", namebuf );
3488 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm clockspeed", "Do not set" ) == 1 ) {
3489 ovr_replace_or_add ( a, "clockspeed", namebuf );
3499 case context_app_run:
3503 case context_app_notes1:
3504 case context_app_notes2:
3505 case context_app_notes3:
3507 char namebuf [ 101 ] = "";
3510 unsigned char notenum;
3513 if ( menu [ sel ] == context_app_notes1 ) {
3515 } else if ( menu [ sel ] == context_app_notes2 ) {
3517 } else if ( menu [ sel ] == context_app_notes3 ) {
3521 // figure out key for looking up existing, and for storing replacement
3522 snprintf ( key, 500, "Application-%u.note-%u", a -> ref -> subapp_number, notenum );
3524 // do we have existing value?
3526 char *existing = pnd_conf_get_as_char ( a -> ovrh, key );
3528 strncpy ( namebuf, existing, 100 );
3532 unsigned char changed;
3534 changed = ui_menu_get_text_line ( "Enter replacement note", "Use keyboard; Enter when done.",
3535 namebuf, namebuf, 30, 0 /* not-numeric-forced */ );
3538 ovr_replace_or_add ( a, strchr ( key, '.' ) + 1, namebuf );
3550 } // if useful return
3555 if ( rescan_apps ) {
3556 applications_free();
3557 applications_scan();
3563 unsigned char ui_menu_twoby ( char *title, char *footer, char *one, char *two ) {
3567 int sel = ui_modal_single_menu ( opts, 2, title, footer );
3574 unsigned char ui_menu_get_text_line ( char *title, char *footer, char *initialvalue,
3575 char *r_buffer, unsigned char maxlen, unsigned char numbersonlyp )
3577 SDL_Rect rects [ 40 ];
3578 SDL_Rect *dest = rects;
3582 char hacktext [ 1024 ];
3583 unsigned char shifted = 0;
3585 bzero ( rects, sizeof(SDL_Rect) * 40 );
3587 if ( initialvalue ) {
3588 if ( initialvalue == r_buffer ) {
3589 // already good to go
3591 strncpy ( r_buffer, initialvalue, maxlen );
3594 bzero ( r_buffer, maxlen );
3600 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
3601 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
3602 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
3603 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
3604 SDL_FillRect( sdl_realscreen, dest, 0 );
3606 // show dialog background
3607 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
3610 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> w;
3611 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> h;
3612 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
3613 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
3614 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
3618 // show dialog frame
3619 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
3620 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
3621 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
3622 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
3628 rtext = TTF_RenderText_Blended ( g_tab_font, title, ui_display_context.fontcolor );
3629 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
3630 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
3631 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
3632 SDL_FreeSurface ( rtext );
3638 rtext = TTF_RenderText_Blended ( g_tab_font, footer, ui_display_context.fontcolor );
3639 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
3640 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
3641 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
3643 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
3644 SDL_FreeSurface ( rtext );
3648 // show text line - and embed cursor
3649 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
3650 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( 0/*i*/ + 1 - 0/*first_visible*/ ) );
3652 strncpy ( hacktext, r_buffer, 1000 );
3653 strncat ( hacktext, "\n", 1000 ); // add [] in most fonts
3655 rtext = TTF_RenderText_Blended ( g_tab_font, hacktext, ui_display_context.fontcolor );
3656 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
3657 SDL_FreeSurface ( rtext );
3660 // update all the rects and send it all to sdl
3661 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
3666 while ( SDL_WaitEvent ( &event ) ) {
3668 switch ( event.type ) {
3671 if ( event.key.keysym.sym == SDLK_LSHIFT || event.key.keysym.sym == SDLK_RSHIFT ) {
3678 if ( event.key.keysym.sym == SDLK_LEFT || event.key.keysym.sym == SDLK_BACKSPACE ) {
3679 if ( strlen ( r_buffer ) > 0 ) {
3680 char *eol = strchr ( r_buffer, '\0' );
3681 *( eol - 1 ) = '\0';
3683 } else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_END ) { // return, or "B"
3686 } else if ( event.key.keysym.sym == SDLK_LSHIFT || event.key.keysym.sym == SDLK_RSHIFT ) {
3689 } else if ( event.key.keysym.sym == SDLK_ESCAPE ||
3690 event.key.keysym.sym == SDLK_PAGEUP ||
3691 event.key.keysym.sym == SDLK_PAGEDOWN ||
3692 event.key.keysym.sym == SDLK_HOME
3699 if ( isprint(event.key.keysym.sym) ) {
3701 unsigned char good = 1;
3703 if ( numbersonlyp && ( ! isdigit(event.key.keysym.sym) ) ) {
3707 if ( maxlen && strlen(r_buffer) >= maxlen ) {
3712 char b [ 2 ] = { '\0', '\0' };
3714 b [ 0 ] = toupper ( event.key.keysym.sym );
3716 b [ 0 ] = event.key.keysym.sym;
3718 strncat ( r_buffer, b, maxlen );
3731 } // while waiting for input
3738 unsigned char ovr_replace_or_add ( mm_appref_t *a, char *keybase, char *newvalue ) {
3739 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 );
3741 char fullpath [ PATH_MAX ];
3743 sprintf ( fullpath, "%s/%s", a -> ref -> object_path, a -> ref -> object_filename );
3744 char *dot = strrchr ( fullpath, '.' );
3746 sprintf ( dot, PXML_SAMEPATH_OVERRIDE_FILEEXT );
3748 fprintf ( stderr, "ERROR: Bad pnd-path in disco_t! %s\n", fullpath );
3752 struct stat statbuf;
3754 if ( stat ( fullpath, &statbuf ) == 0 ) {
3758 h = pnd_conf_fetch_by_path ( fullpath );
3761 return ( 0 ); // fail!
3765 snprintf ( key, 100, "Application-%u.%s", a -> ref -> subapp_number, keybase );
3767 pnd_conf_set_char ( h, key, newvalue );
3769 return ( pnd_conf_write ( h, fullpath ) );
3772 // file needs to be created - easy!
3774 FILE *f = fopen ( fullpath, "w" );
3777 fprintf ( f, "Application-%u.%s\t%s\n", a -> ref -> subapp_number, keybase, newvalue );
3781 return ( 0 ); // fail!