From 7bbc97983b85abeabfa1748fc5467138fb11ad33 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Wed, 3 Apr 2013 22:06:19 -0700 Subject: [PATCH] NSM: Show client icons in nsm GUI. --- lib/ntk | 2 +- session-manager/src/session-manager.C | 79 +++++++++++++++++++++++---- 2 files changed, 70 insertions(+), 11 deletions(-) diff --git a/lib/ntk b/lib/ntk index f4ea6b8..77fb243 160000 --- a/lib/ntk +++ b/lib/ntk @@ -1 +1 @@ -Subproject commit f4ea6b8e475ef7cc252a5d0183f3c5e3b06188e3 +Subproject commit 77fb243ae95a4c1818cc10545655ff34160da2b5 diff --git a/session-manager/src/session-manager.C b/session-manager/src/session-manager.C index 9ccd39a..7b5e14e 100644 --- a/session-manager/src/session-manager.C +++ b/session-manager/src/session-manager.C @@ -38,6 +38,8 @@ #include #include #include +#include +#include #include "FL/Fl_Packscroller.H" #include "FL/Fl_Scalepack.H" @@ -80,13 +82,45 @@ static std::list daemon_list; /* list #define foreach_daemon( _it ) for ( std::list::iterator _it = daemon_list.begin(); _it != daemon_list.end(); ++ _it ) +static +Fl_Image * +get_program_icon ( const char *name ) +{ + const char *tries[] = + { + "/usr/local/share/icons/hicolor/32x32/apps/%s.png", + "/usr/local/share/pixmaps/%s.png", + "/usr/local/share/pixmaps/%s.xpm", + "/usr/share/icons/hicolor/32x32/apps/%s.png", + "/usr/share/pixmaps/%s.png", + "/usr/share/pixmaps/%s.xpm", + }; + + for ( unsigned int i = 0; i < 6; i++ ) + { + char *icon_p; + + asprintf( &icon_p, tries[i], name ); + + Fl_Image *img = Fl_Shared_Image::get( icon_p ); + + free( icon_p ); + + if ( img ) + return img; + } + + return NULL; +} + class NSM_Client : public Fl_Group { char *_client_id; char *_client_label; char *_client_name; - -// Fl_Box *client_name; + + Fl_Box *client_name; + Fl_Box *icon_box; Fl_Progress *_progress; Fl_Light_Button *_dirty; Fl_Light_Button *_gui; @@ -104,10 +138,19 @@ class NSM_Client : public Fl_Group else l = strdup( _client_name ); - if ( label() ) - free((char*)label()); + if ( ! icon_box->image() ) + { + Fl_Image *img = get_program_icon( _client_name ); + + if ( img ) + { + icon_box->image( img ); + } + } - label( l ); + client_name->copy_label( l ); + + // _client_label = l; redraw(); } @@ -311,12 +354,26 @@ public: int xx = X + W - ( 75 + Fl::box_dw( box() ) ); int ss = 2; - /* dummy group */ - { Fl_Group *o = new Fl_Group( X, Y, 50, 50 ); - o->end(); - resizable( o ); - } + /* /\* dummy group *\/ */ + /* { Fl_Group *o = new Fl_Group( X, Y, 50, 50 ); */ + /* o->end(); */ + /* resizable( o ); */ + /* } */ + + { Fl_Pack *o = new Fl_Pack( X + 15, Y, 200 - 5, H ); + o->type( FL_HORIZONTAL ); + o->spacing( 10 ); + { icon_box = new Fl_Box( 0, 0, 32, 32 ); + } + { Fl_Box *o = client_name = new Fl_Box( 0, 0, 300, 48 ); + /* o->color( FL_BLUE ); */ + o->align( FL_ALIGN_INSIDE | FL_ALIGN_LEFT ); + o->labeltype( FL_NORMAL_LABEL ); + } + o->end(); + } + { Fl_Progress *o = _progress = new Fl_Progress( xx, Y + H * 0.25, 75, H * 0.50, NULL ); o->box( FL_FLAT_BOX ); o->color( FL_BLACK ); @@ -1171,6 +1228,8 @@ main (int argc, char **argv ) (char**)icon_16x16, &p, &mask, NULL); #endif + fl_register_images(); + Fl::lock(); Fl_Double_Window *main_window;