Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

234 lines
5.5KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2012 Jonathan Moore Liles */
  3. /* */
  4. /* This program is free software; you can redistribute it and/or modify it */
  5. /* under the terms of the GNU General Public License as published by the */
  6. /* Free Software Foundation; either version 2 of the License, or (at your */
  7. /* option) any later version. */
  8. /* */
  9. /* This program is distributed in the hope that it will be useful, but WITHOUT */
  10. /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
  11. /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
  12. /* more details. */
  13. /* */
  14. /* You should have received a copy of the GNU General Public License along */
  15. /* with This program; see the file COPYING. If not,write to the Free Software */
  16. /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. /*******************************************************************************/
  18. #include "FL/Fl_Theme.H"
  19. #include <FL/Fl.H>
  20. #include <FL/Fl_Window.H>
  21. #include <FL/Fl_Preferences.H>
  22. Fl_Theme *Fl_Theme::first;
  23. Fl_Theme *Fl_Theme::_current;
  24. Fl_Color_Scheme *Fl_Color_Scheme::first;
  25. int Fl_Theme::total;
  26. int Fl_Color_Scheme::total;
  27. void
  28. Fl_Theme::add ( Fl_Theme *t )
  29. {
  30. t->next = first;
  31. first = t;
  32. total++;
  33. }
  34. Fl_Theme **
  35. Fl_Theme::get ( void )
  36. {
  37. Fl_Theme **r = (Fl_Theme**) malloc( sizeof( Fl_Theme* ) * ( total + 1 ) );
  38. int i = 0;
  39. for ( Fl_Theme *t = first; t; t = t->next, i++ )
  40. r[i] = t;
  41. r[i] = 0;
  42. return r;
  43. }
  44. static
  45. Fl_Preferences *prefs ( void )
  46. {
  47. char *path;
  48. asprintf( &path, "%s/.config/ntk/", getenv("HOME" ) );
  49. Fl_Preferences *p = new Fl_Preferences( path, "ntk", "theme" );
  50. free( path );
  51. return p;
  52. }
  53. static void conf_set ( const char *key, const char *value )
  54. {
  55. Fl_Preferences *p = prefs();
  56. p->set( key, value );
  57. delete p;
  58. }
  59. static void conf_set ( const char *key, Fl_Color value )
  60. {
  61. Fl_Preferences *p = prefs();
  62. p->set( key, (int)value );
  63. delete p;
  64. }
  65. static const char *conf_get ( const char *key, const char *def )
  66. {
  67. static char buf[256];
  68. Fl_Preferences *p = prefs();
  69. p->get( key, buf, def, sizeof( buf ) );
  70. delete p;
  71. return buf;
  72. }
  73. static
  74. Fl_Color
  75. conf_get_color ( const char *key, Fl_Color def )
  76. {
  77. Fl_Preferences *p = prefs();
  78. int c;
  79. p->get( key, c, def );
  80. delete p;
  81. return (Fl_Color)c;
  82. }
  83. static bool dont_save = false;
  84. /* sets the configured default */
  85. int
  86. Fl_Theme::set ( void )
  87. {
  88. const char *name = conf_get( "theme", "clean" );
  89. int rv = set( name );
  90. dont_save = true;
  91. Fl_Color_Scheme::set( "System" );
  92. dont_save = false;
  93. uchar r, g, b;
  94. Fl::get_color( conf_get_color( "background", FL_BACKGROUND_COLOR ), r, g, b );
  95. Fl::background( r, g, b );
  96. Fl::get_color( conf_get_color( "background2", FL_BACKGROUND2_COLOR ), r, g, b );
  97. Fl::background2( r, g, b );
  98. Fl::get_color( conf_get_color( "foreground", FL_FOREGROUND_COLOR ), r, g, b );
  99. Fl::foreground( r, g, b );
  100. return rv;
  101. }
  102. int
  103. Fl_Theme::set ( const char *name )
  104. {
  105. for ( Fl_Theme *t = first; t; t = t->next )
  106. if ( !strcasecmp( t->name(), name ) )
  107. {
  108. /* reset boxtypes */
  109. Fl::reload_scheme();
  110. printf( "Theme set to %s\n", t->name() );
  111. t->_init_func();
  112. Fl_Theme::_current = t;
  113. conf_set( "theme", t->name() );
  114. for ( Fl_Window *w = Fl::first_window(); w; w = Fl::next_window( w ) )
  115. w->redraw();
  116. return 1;
  117. }
  118. return 0;
  119. }
  120. void
  121. Fl_Color_Scheme::add ( Fl_Color_Scheme *t )
  122. {
  123. t->next = first;
  124. first = t;
  125. total++;
  126. }
  127. Fl_Color_Scheme **
  128. Fl_Color_Scheme::get ( void )
  129. {
  130. Fl_Color_Scheme **r = (Fl_Color_Scheme**) malloc( sizeof( Fl_Color_Scheme* ) * ( total + 1 ) );
  131. int i = 0;
  132. for ( Fl_Color_Scheme *t = first; t; t = t->next, i++ )
  133. r[i] = t;
  134. r[i] = 0;
  135. return r;
  136. }
  137. void
  138. Fl_Color_Scheme::save ( void )
  139. {
  140. if ( ! dont_save )
  141. {
  142. conf_set( "background", Fl::get_color( FL_BACKGROUND_COLOR ) );
  143. conf_set( "foreground", Fl::get_color( FL_FOREGROUND_COLOR ) );
  144. conf_set( "background2", Fl::get_color( FL_BACKGROUND2_COLOR ) );
  145. }
  146. for ( Fl_Window *w = Fl::first_window(); w; w = Fl::next_window( w ) )
  147. w->redraw();
  148. }
  149. int
  150. Fl_Color_Scheme::set ( const char *name )
  151. {
  152. for ( Fl_Color_Scheme *t = first; t; t = t->next )
  153. if ( !strcasecmp( t->name(), name ) )
  154. {
  155. uchar r, g, b;
  156. Fl::get_color( t->_bg, r, g, b );
  157. Fl::background( r, g, b );
  158. Fl::get_color( t->_bg2, r, g, b );
  159. Fl::background2( r, g, b );
  160. Fl::get_color( t->_fg, r, g, b );
  161. Fl::foreground( r, g, b );
  162. /* Fl::get_color( t->_sel, r, g, b ); */
  163. /* Fl::selection( r, g, b ); */
  164. conf_set( "color_scheme", t->name() );
  165. save();
  166. return 1;
  167. }
  168. return 0;
  169. }