gtk-theme-config.vala 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. using Gtk;
  2. // add all strings from the desktop files here that need
  3. // to be translated (Title and generic name are already
  4. // here). Update accordingly.
  5. const string COMMENT = N_("Configure GTK theme colors");
  6. class ThemeConfigWindow : ApplicationWindow {
  7. Label selectbg_label;
  8. Label selectfg_label;
  9. ColorButton selectbg_button;
  10. ColorButton selectfg_button;
  11. ColorButton panelbg_button;
  12. ColorButton panelfg_button;
  13. ColorButton menubg_button;
  14. ColorButton menufg_button;
  15. Switch select_switch;
  16. Switch panel_switch;
  17. Switch menu_switch;
  18. Button revert_button;
  19. Button apply_button;
  20. Gdk.RGBA color_rgb;
  21. File config_dir;
  22. File home_dir;
  23. File gtk3_config_file;
  24. File gtk2_config_file;
  25. File theme_path;
  26. string color_hex;
  27. string color_scheme;
  28. string selectbg_value;
  29. string selectfg_value;
  30. string panelbg_value;
  31. string panelfg_value;
  32. string menubg_value;
  33. string menufg_value;
  34. internal ThemeConfigWindow (ThemeConfigApp app) {
  35. Object (application: app, title: _("Theme Configuration"));
  36. // Set window properties
  37. this.window_position = WindowPosition.CENTER;
  38. this.resizable = false;
  39. this.border_width = 10;
  40. // Set window icon
  41. try {
  42. this.icon = IconTheme.get_default ().load_icon ("gtk-theme-config", 48, 0);
  43. } catch (Error e) {
  44. stderr.printf ("Could not load application icon: %s\n", e.message);
  45. }
  46. // Methods
  47. create_widgets ();
  48. connect_signals ();
  49. }
  50. void set_values () {
  51. // Set default values
  52. selectbg_value = "#398ee7";
  53. selectfg_value = "#eeeeee";
  54. panelbg_value = "#cccccc";
  55. panelfg_value = "#333333";
  56. menubg_value = "#eeeeee";
  57. menufg_value = "#333333";
  58. select_switch.set_active (false);
  59. panel_switch.set_active (false);
  60. menu_switch.set_active (false);
  61. // Read the current values
  62. var settings = new GLib.Settings ("org.gnome.desktop.interface");
  63. var color_scheme = settings.get_string ("gtk-color-scheme");
  64. var theme_name = settings.get_string ("gtk-theme");
  65. // Set paths of config files
  66. config_dir = File.new_for_path (Environment.get_user_config_dir ());
  67. home_dir = File.new_for_path (Environment.get_home_dir ());
  68. gtk3_config_file = config_dir.get_child ("gtk-3.0").get_child ("gtk.css");
  69. gtk2_config_file = home_dir.get_child (".gtkrc-2.0");
  70. // Create path if doesn't exist
  71. if (!gtk3_config_file.get_parent().query_exists ()) {
  72. try {
  73. gtk3_config_file.get_parent().make_directory_with_parents(null);
  74. } catch (Error e) {
  75. stderr.printf ("Could not create parent directory: %s\n", e.message);
  76. }
  77. }
  78. // Detect current theme path
  79. if (gtk3_config_file.query_exists ()) {
  80. theme_path = gtk3_config_file;
  81. } else if (home_dir.get_child (".themes/%s/gtk-3.0/gtk-main.css".printf (theme_name)).query_exists ()) {
  82. theme_path = home_dir.get_child (".themes/%s/gtk-3.0/gtk-main.css".printf (theme_name));
  83. } else if (home_dir.get_child (".themes/%s/gtk-3.0/gtk.css".printf (theme_name)).query_exists ()) {
  84. theme_path = home_dir.get_child (".themes/%s/gtk-3.0/gtk.css".printf (theme_name));
  85. } else if (File.parse_name ("/usr/share/themes/%s/gtk-3.0/gtk-main.css".printf (theme_name)).query_exists ()) {
  86. theme_path = File.parse_name ("/usr/share/themes/%s/gtk-3.0/gtk-main.css".printf (theme_name));
  87. } else if (File.parse_name ("/usr/share/themes/%s/gtk-3.0/gtk.css".printf (theme_name)).query_exists ()) {
  88. theme_path = File.parse_name ("/usr/share/themes/%s/gtk-3.0/gtk.css".printf (theme_name));
  89. }
  90. // Read the current theme file
  91. try {
  92. var dis = new DataInputStream (theme_path.read ());
  93. string line;
  94. while ((line = dis.read_line (null)) != null) {
  95. if ("@define-color selected_bg_color" in line) {
  96. selectbg_value = line.substring (32, line.length-33);
  97. if ("@" in selectbg_value) {
  98. selectbg_value = "#398ee7";
  99. }
  100. }
  101. if ("@define-color selected_fg_color" in line) {
  102. selectfg_value = line.substring (32, line.length-33);
  103. if ("@" in selectfg_value) {
  104. selectfg_value = "#eeeeee";
  105. }
  106. }
  107. if ("@define-color panel_bg_color" in line) {
  108. panelbg_value = line.substring (29, line.length-30);
  109. if ("@" in panelbg_value) {
  110. panelbg_value = "#cccccc";
  111. }
  112. }
  113. if ("@define-color panel_fg_color" in line) {
  114. panelfg_value = line.substring (29, line.length-30);
  115. if ("@" in panelfg_value) {
  116. panelfg_value = "#333333";
  117. }
  118. }
  119. if ("@define-color menu_bg_color" in line) {
  120. menubg_value = line.substring (28, line.length-29);
  121. if ("@" in menubg_value) {
  122. menubg_value = "#eeeeee";
  123. }
  124. }
  125. if ("@define-color menu_fg_color" in line) {
  126. menufg_value = line.substring (28, line.length-29);
  127. if ("@" in menufg_value) {
  128. menufg_value = "#333333";
  129. }
  130. }
  131. if ("/* select-on */" in line) {
  132. select_switch.set_active (true);
  133. }
  134. if ("/* panel-on */" in line) {
  135. panel_switch.set_active (true);
  136. }
  137. if ("/* menu-on */" in line) {
  138. menu_switch.set_active (true);
  139. }
  140. }
  141. } catch (Error e) {
  142. stderr.printf ("Could not read user theme: %s\n", e.message);
  143. }
  144. // Read the current color scheme
  145. if (";" in color_scheme) {
  146. string[] parts = color_scheme.split_set(";");
  147. if ("selected_bg_color:#" in parts[0] && "selected_fg_color:#" in parts[1]) {
  148. selectbg_value = parts[0].substring (18, parts[0].length-18);
  149. selectfg_value = parts[1].substring (18, parts[1].length-18);
  150. select_switch.set_active (true);
  151. }
  152. }
  153. // Set colors
  154. Gdk.RGBA color = Gdk.RGBA ();
  155. color.parse (selectbg_value);
  156. selectbg_button.set_rgba (color);
  157. color.parse (selectfg_value);
  158. selectfg_button.set_rgba (color);
  159. color.parse (panelbg_value);
  160. panelbg_button.set_rgba (color);
  161. color.parse (panelfg_value);
  162. panelfg_button.set_rgba (color);
  163. color.parse (menubg_value);
  164. menubg_button.set_rgba (color);
  165. color.parse (menufg_value);
  166. menufg_button.set_rgba (color);
  167. apply_button.set_sensitive (false);
  168. }
  169. void create_widgets () {
  170. // Create and setup widgets
  171. var select_heading = new Label ("<b>" + _("Custom highlight colors") + "</b>");
  172. select_heading.set_use_markup (true);
  173. select_heading.set_halign (Align.START);
  174. var panel_heading = new Label ("<b>" + _("Custom panel colors") + "</b>");
  175. panel_heading.set_use_markup (true);
  176. panel_heading.set_halign (Align.START);
  177. var menu_heading = new Label ("<b>" + _("Custom menu colors") + "</b>");
  178. menu_heading.set_use_markup (true);
  179. menu_heading.set_halign (Align.START);
  180. selectbg_label = new Label (_("Highlight background"));
  181. selectbg_label.set_halign (Align.START);
  182. selectfg_label = new Label (_("Highlight text"));
  183. selectfg_label.set_halign (Align.START);
  184. var panelbg_label = new Label (_("Panel background"));
  185. panelbg_label.set_halign (Align.START);
  186. var panelfg_label = new Label (_("Panel text"));
  187. panelfg_label.set_halign (Align.START);
  188. var menubg_label = new Label (_("Menu background"));
  189. menubg_label.set_halign (Align.START);
  190. var menufg_label = new Label (_("Menu text"));
  191. menufg_label.set_halign (Align.START);
  192. selectbg_button = new ColorButton ();
  193. selectfg_button = new ColorButton ();
  194. panelbg_button = new ColorButton ();
  195. panelfg_button = new ColorButton ();
  196. menubg_button = new ColorButton ();
  197. menufg_button = new ColorButton ();
  198. select_switch = new Switch ();
  199. select_switch.set_halign (Align.END);
  200. panel_switch = new Switch ();
  201. panel_switch.set_halign (Align.END);
  202. menu_switch = new Switch ();
  203. menu_switch.set_halign (Align.END);
  204. revert_button = new Button.with_label (_("Reset"));
  205. apply_button = new Button.with_label (_("Apply"));
  206. // Buttons
  207. var buttons = new ButtonBox (Orientation.HORIZONTAL);
  208. buttons.set_layout (ButtonBoxStyle.EDGE);
  209. buttons.add (revert_button);
  210. buttons.add (apply_button);
  211. // Layout widgets
  212. var grid = new Grid ();
  213. grid.set_column_homogeneous (true);
  214. grid.set_row_homogeneous (true);
  215. grid.set_column_spacing (5);
  216. grid.set_row_spacing (5);
  217. grid.attach (select_heading, 0, 0, 1, 1);
  218. grid.attach_next_to (select_switch, select_heading, PositionType.RIGHT, 1, 1);
  219. grid.attach (selectbg_label, 0, 1, 1, 1);
  220. grid.attach_next_to (selectbg_button, selectbg_label, PositionType.RIGHT, 1, 1);
  221. grid.attach (selectfg_label, 0, 2, 1, 1);
  222. grid.attach_next_to (selectfg_button, selectfg_label, PositionType.RIGHT, 1, 1);
  223. grid.attach (panel_heading, 0, 3, 1, 1);
  224. grid.attach_next_to (panel_switch, panel_heading, PositionType.RIGHT, 1, 1);
  225. grid.attach (panelbg_label, 0, 4, 1, 1);
  226. grid.attach_next_to (panelbg_button, panelbg_label, PositionType.RIGHT, 1, 1);
  227. grid.attach (panelfg_label, 0, 5, 1, 1);
  228. grid.attach_next_to (panelfg_button, panelfg_label, PositionType.RIGHT, 1, 1);
  229. grid.attach (menu_heading, 0, 6, 1, 1);
  230. grid.attach_next_to (menu_switch, menu_heading, PositionType.RIGHT, 1, 1);
  231. grid.attach (menubg_label, 0, 7, 1, 1);
  232. grid.attach_next_to (menubg_button, menubg_label, PositionType.RIGHT, 1, 1);
  233. grid.attach (menufg_label, 0, 8, 1, 1);
  234. grid.attach_next_to (menufg_button, menufg_label, PositionType.RIGHT, 1, 1);
  235. grid.attach (buttons, 0, 9, 2, 1);
  236. this.add (grid);
  237. set_values ();
  238. }
  239. void connect_signals () {
  240. selectbg_button.color_set.connect (() => {
  241. on_selectbg_color_set ();
  242. apply_button.set_sensitive (true);
  243. });
  244. selectfg_button.color_set.connect (() => {
  245. on_selectfg_color_set ();
  246. apply_button.set_sensitive (true);
  247. });
  248. panelbg_button.color_set.connect (() => {
  249. on_panelbg_color_set ();
  250. apply_button.set_sensitive (true);
  251. });
  252. panelfg_button.color_set.connect (() => {
  253. on_panelfg_color_set ();
  254. apply_button.set_sensitive (true);
  255. });
  256. menubg_button.color_set.connect (() => {
  257. on_menubg_color_set ();
  258. apply_button.set_sensitive (true);
  259. });
  260. menufg_button.color_set.connect (() => {
  261. on_menufg_color_set ();
  262. apply_button.set_sensitive (true);
  263. });
  264. select_switch.notify["active"].connect (() => {
  265. apply_button.set_sensitive (true);
  266. });
  267. panel_switch.notify["active"].connect (() => {
  268. apply_button.set_sensitive (true);
  269. });
  270. menu_switch.notify["active"].connect (() => {
  271. apply_button.set_sensitive (true);
  272. });
  273. revert_button.clicked.connect (() => {
  274. on_config_reset ();
  275. revert_button.set_sensitive (false);
  276. });
  277. apply_button.clicked.connect (() => {
  278. on_config_set ();
  279. apply_button.set_sensitive (false);
  280. revert_button.set_sensitive (true);
  281. });
  282. }
  283. void rgb_to_hex () {
  284. int r = (int)Math.round (color_rgb.red * 255);
  285. int g = (int)Math.round (color_rgb.green * 255);
  286. int b = (int)Math.round (color_rgb.blue * 255);
  287. color_hex = "#%02x%02x%02x".printf (r, g, b);
  288. }
  289. void on_selectbg_color_set () {
  290. color_rgb = selectbg_button.get_rgba ();
  291. rgb_to_hex ();
  292. selectbg_value = color_hex;
  293. select_switch.set_active (true);
  294. }
  295. void on_selectfg_color_set () {
  296. color_rgb = selectfg_button.get_rgba ();
  297. rgb_to_hex ();
  298. selectfg_value = color_hex;
  299. select_switch.set_active (true);
  300. }
  301. void on_panelbg_color_set () {
  302. color_rgb = panelbg_button.get_rgba ();
  303. rgb_to_hex ();
  304. panelbg_value = color_hex;
  305. panel_switch.set_active (true);
  306. }
  307. void on_panelfg_color_set () {
  308. color_rgb = panelfg_button.get_rgba ();
  309. rgb_to_hex ();
  310. panelfg_value = color_hex;
  311. panel_switch.set_active (true);
  312. }
  313. void on_menubg_color_set () {
  314. color_rgb = menubg_button.get_rgba ();
  315. rgb_to_hex ();
  316. menubg_value = color_hex;
  317. menu_switch.set_active (true);
  318. }
  319. void on_menufg_color_set () {
  320. color_rgb = menufg_button.get_rgba ();
  321. rgb_to_hex ();
  322. menufg_value = color_hex;
  323. menu_switch.set_active (true);
  324. }
  325. void on_config_set () {
  326. set_color_scheme ();
  327. write_config ();
  328. notify_change ();
  329. }
  330. void on_config_reset () {
  331. reset_color_scheme ();
  332. reset_config ();
  333. set_values ();
  334. notify_change ();
  335. }
  336. void set_color_scheme () {
  337. // Determine color scheme
  338. if (select_switch.get_active()) {
  339. color_scheme = "\"selected_bg_color:%s;selected_fg_color:%s;\"".printf (selectbg_value, selectfg_value);
  340. } else {
  341. color_scheme = "\"\"";
  342. }
  343. // Set color scheme
  344. try {
  345. Process.spawn_command_line_sync ("gsettings set org.gnome.desktop.interface gtk-color-scheme %s".printf (color_scheme));
  346. } catch (Error e) {
  347. stderr.printf ("Could not set color scheme for gtk3: %s\n", e.message);
  348. }
  349. try {
  350. Process.spawn_command_line_sync ("gconftool-2 -s /desktop/gnome/interface/gtk_color_scheme -t string %s".printf (color_scheme));
  351. } catch (Error e) {
  352. stderr.printf ("Could not set color scheme for gtk2: %s\n", e.message);
  353. }
  354. if (File.parse_name ("/usr/bin/xfconf-query").query_exists ()) {
  355. try {
  356. Process.spawn_command_line_sync ("xfconf-query -n -c xsettings -p /Gtk/ColorScheme -t string -s %s".printf (color_scheme));
  357. } catch (Error e) {
  358. stderr.printf ("Could not set color scheme for xfce: %s\n", e.message);
  359. }
  360. }
  361. }
  362. void reset_color_scheme () {
  363. try {
  364. Process.spawn_command_line_sync ("gsettings reset org.gnome.desktop.interface gtk-color-scheme");
  365. } catch (Error e) {
  366. stderr.printf ("Could not reset color scheme for gtk3: %s\n", e.message);
  367. }
  368. try {
  369. Process.spawn_command_line_sync ("gconftool-2 -u /desktop/gnome/interface/gtk_color_scheme");
  370. } catch (Error e) {
  371. stderr.printf ("Could not reset color scheme for gtk2: %s\n", e.message);
  372. }
  373. if (File.parse_name ("/usr/bin/xfconf-query").query_exists ()) {
  374. try {
  375. Process.spawn_command_line_sync ("xfconf-query -c xsettings -p /Gtk/ColorScheme -r");
  376. } catch (Error e) {
  377. stderr.printf ("Could not reset color scheme for xfce: %s\n", e.message);
  378. }
  379. }
  380. }
  381. void reset_config () {
  382. try {
  383. if (gtk3_config_file.query_exists ()) {
  384. gtk3_config_file.delete ();
  385. }
  386. } catch (Error e) {
  387. stderr.printf ("Could not delete previous gtk3 configuration: %s\n", e.message);
  388. }
  389. try {
  390. if (gtk2_config_file.query_exists ()) {
  391. gtk2_config_file.delete ();
  392. }
  393. } catch (Error e) {
  394. stderr.printf ("Could not delete previous gtk2 configuration: %s\n", e.message);
  395. }
  396. }
  397. void write_config () {
  398. // Determine states
  399. string select_state1;
  400. string select_state2;
  401. string panel_state1;
  402. string panel_state2;
  403. string menu_state1;
  404. string menu_state2;
  405. string panel_gtk2;
  406. string menu_gtk2;
  407. if (select_switch.get_active()) {
  408. select_state1 = "/* select-on */";
  409. select_state2 = "/* select-on */";
  410. } else {
  411. select_state1 = "/* select-off";
  412. select_state2 = "select-off */";
  413. }
  414. if (panel_switch.get_active()) {
  415. panel_state1 = "/* panel-on */";
  416. panel_state2 = "/* panel-on */";
  417. panel_gtk2 = ("style \"gtk-theme-config-panel\" {\n" +
  418. "\tbg[NORMAL] = \"%s\"\n" +
  419. "\tbg[PRELIGHT] = shade(1.1,\"%s\")\n" +
  420. "\tbg[ACTIVE] = shade(0.9,\"%s\")\n" +
  421. "\tbg[SELECTED] = shade(0.97,\"%s\")\n" +
  422. "\tfg[NORMAL] = \"%s\"\n" +
  423. "\tfg[PRELIGHT] = \"%s\"\n" +
  424. "\tfg[SELECTED] = \"%s\"\n" +
  425. "\tfg[ACTIVE] = \"%s\"\n" +
  426. "}\n\n" +
  427. "widget \"*PanelWidget*\" style \"gtk-theme-config-panel\"\n" +
  428. "widget \"*PanelApplet*\" style \"gtk-theme-config-panel\"\n" +
  429. "widget \"*fast-user-switch*\" style \"gtk-theme-config-panel\"\n" +
  430. "widget \"*CPUFreq*Applet*\" style \"gtk-theme-config-panel\"\n" +
  431. "widget \"*indicator-applet*\" style \"gtk-theme-config-panel\"\n" +
  432. "class \"PanelApp*\" style \"gtk-theme-config-panel\"\n" +
  433. "class \"PanelToplevel*\" style \"gtk-theme-config-panel\"\n" +
  434. "widget_class \"*PanelToplevel*\" style \"gtk-theme-config-panel\"\n" +
  435. "widget_class \"*notif*\" style \"gtk-theme-config-panel\"\n" +
  436. "widget_class \"*Notif*\" style \"gtk-theme-config-panel\"\n" +
  437. "widget_class \"*Tray*\" style \"gtk-theme-config-panel\" \n" +
  438. "widget_class \"*tray*\" style \"gtk-theme-config-panel\"\n" +
  439. "widget_class \"*computertemp*\" style \"gtk-theme-config-panel\"\n" +
  440. "widget_class \"*Applet*Tomboy*\" style \"gtk-theme-config-panel\"\n" +
  441. "widget_class \"*Applet*Netstatus*\" style \"gtk-theme-config-panel\"\n" +
  442. "widget \"*gdm-user-switch-menubar*\" style \"gtk-theme-config-panel\"\n" +
  443. "widget \"*Xfce*Panel*\" style \"gtk-theme-config-panel\"\n" +
  444. "class \"*Xfce*Panel*\" style \"gtk-theme-config-panel\"\n").printf (panelbg_value, panelbg_value, panelbg_value, panelbg_value, panelfg_value, panelfg_value, panelfg_value, panelfg_value);
  445. } else {
  446. panel_state1 = "/* panel-off";
  447. panel_state2 = "panel-off */";
  448. panel_gtk2 = "";
  449. }
  450. if (menu_switch.get_active()) {
  451. menu_state1 = "/* menu-on */";
  452. menu_state2 = "/* menu-on */";
  453. menu_gtk2 = ("style \"gtk-theme-config-menu\" {\n" +
  454. "\tbase[NORMAL] = \"%s\"\n" +
  455. "\tbg[NORMAL] = \"%s\"\n" +
  456. "\tbg[ACTIVE] = \"%s\"\n" +
  457. "\tbg[INSENSITIVE] = \"%s\"\n" +
  458. "\ttext[NORMAL] = \"%s\"\n" +
  459. "\tfg[NORMAL] = \"%s\"\n" +
  460. "}\n\n" +
  461. "widget_class\"*<GtkMenu>*\"style\"gtk-theme-config-menu\"\n").printf (menubg_value, menubg_value, menubg_value, menubg_value, menufg_value, menufg_value);
  462. } else {
  463. menu_state1 = "/* menu-off";
  464. menu_state2 = "menu-off */";;
  465. menu_gtk2 = "";
  466. }
  467. // Write config
  468. try {
  469. var dos = new DataOutputStream (gtk3_config_file.replace (null, false, FileCreateFlags.REPLACE_DESTINATION));
  470. dos.put_string ("/* Custom styles */\n\n");
  471. string text = ("%s\n" +
  472. "@define-color selected_bg_color %s;\n" +
  473. "@define-color selected_fg_color %s;\n" +
  474. "@define-color theme_selected_bg_color @selected_bg_color;\n" +
  475. "@define-color theme_selected_fg_color @selected_fg_color;\n" +
  476. "%s\n\n" +
  477. "%s\n" +
  478. "@define-color panel_bg_color %s;\n" +
  479. "@define-color panel_fg_color %s;\n\n" +
  480. "PanelWidget,\n" +
  481. "PanelApplet,\n" +
  482. "PanelToplevel,\n" +
  483. "PanelSeparator,\n" +
  484. "PanelApplet > GtkMenuBar.menubar,\n" +
  485. "PanelApplet > GtkMenuBar.menubar.menuitem,\n" +
  486. "PanelMenuBar.menubar,\n" +
  487. "PanelMenuBar.menubar.menuitem,\n" +
  488. "PanelAppletFrame,\n" +
  489. "UnityPanelWidget,\n" +
  490. ".gnome-panel-menu-bar,\n" +
  491. ".unity-panel {\n" +
  492. "\tbackground-image: -gtk-gradient(linear,left top,left bottom,from(shade(@panel_bg_color,1.2)),to(shade(@panel_bg_color,0.8)));\n" +
  493. "\tcolor: @panel_fg_color;\n" +
  494. "}\n\n" +
  495. ".unity-panel.menuitem,\n" +
  496. ".unity-panel .menuitem {\n" +
  497. "\tcolor: @panel_fg_color;\n" +
  498. "}\n\n" +
  499. ".unity-panel.menubar.menuitem:hover,\n" +
  500. ".unity-panel.menubar .menuitem *:hover {\n" +
  501. "\tborder-color: shade(@panel_bg_color, 0.7);\n" +
  502. "\tborder-image: none;\n" +
  503. "\tbackground-image: -gtk-gradient(linear,left top,left bottom,from(shade(@panel_bg_color, 0.97)),to(shade(@panel_bg_color, 0.82)));\n" +
  504. "\tcolor: @panel_fg_color;\n" +
  505. "}\n\n" +
  506. "PanelApplet .button {\n" +
  507. "\tborder-color: transparent;\n" +
  508. "\tborder-image: none;\n" +
  509. "\tbackground-image: -gtk-gradient(linear,left top,left bottom,from(shade(@panel_bg_color,1.2)),to(shade(@panel_bg_color,0.8)));\n" +
  510. "\tcolor: @panel_fg_color;\n" +
  511. "\tbox-shadow: none;\n" +
  512. "\ttext-shadow: none;\n" +
  513. "\t-unico-inner-stroke-width: 0;\n" +
  514. "}\n\n" +
  515. "PanelApplet .button:active {\n" +
  516. "\tborder-color: shade(@panel_bg_color,0.8);\n" +
  517. "\tborder-image: none;\n" +
  518. "\tbackground-image: -gtk-gradient(linear,left top,left bottom,from(shade(shade(@panel_bg_color,1.02),0.9)),to(shade(shade(@panel_bg_color,1.02),0.95)));\n" +
  519. "\tcolor: @panel_fg_color;\n" +
  520. "\tbox-shadow: none;\n" +
  521. "\ttext-shadow: none;\n" +
  522. "\t-unico-inner-stroke-width: 0;\n" +
  523. "}\n\n" +
  524. "PanelApplet .button:prelight {\n" +
  525. "\tborder-color: transparent;\n" +
  526. "\tborder-image: none;\n" +
  527. "\tbackground-image: -gtk-gradient(linear,left top,left bottom,from(shade(@panel_bg_color,1.2)),to(shade(@panel_bg_color,1.0)));\n" +
  528. "\tcolor: @panel_fg_color;\n" +
  529. "\tbox-shadow: none;\n" +
  530. "\ttext-shadow: none;\n" +
  531. "\t-unico-inner-stroke-width: 0;\n" +
  532. "}\n\n" +
  533. "PanelApplet .button:active:prelight {\n" +
  534. "\tborder-color: shade(@panel_bg_color,0.8);\n" +
  535. "\tborder-image: none;\n" +
  536. "\tbackground-image: -gtk-gradient(linear,left top,left bottom,from(shade(shade(@panel_bg_color,1.02),1.0)),to(shade(shade(@panel_bg_color,1.02),1.05)));\n" +
  537. "\tcolor: @panel_fg_color;\n" +
  538. "\tbox-shadow: none;\n" +
  539. "\ttext-shadow: none;\n" +
  540. "\t-unico-inner-stroke-width: 0;\n" +
  541. "}\n\n" +
  542. "WnckPager,\n" +
  543. "WnckTasklist {\n" +
  544. "\tbackground-color: @panel_bg_color;\n" +
  545. "}\n\n" +
  546. "%s\n\n" +
  547. "%s\n" +
  548. "@define-color menu_bg_color %s;\n" +
  549. "@define-color menu_fg_color %s;\n\n" +
  550. "GtkTreeMenu.menu,\n" +
  551. "GtkMenuToolButton.menu,\n" +
  552. "GtkComboBox .menu {\n" +
  553. "\tbackground-color: @menu_bg_color;\n" +
  554. "}\n\n" +
  555. ".primary-toolbar .button .menu,\n" +
  556. ".toolbar .menu,\n" +
  557. ".toolbar .primary-toolbar .menu,\n" +
  558. ".menu,\n" +
  559. "#toolbar-popup {\n" +
  560. "\tborder-style: none;\n" +
  561. "\tbackground-image: none;\n" +
  562. "\tbackground-color: @menu_bg_color;\n" +
  563. "\tcolor: @menu_fg_color;\n" +
  564. "\tbox-shadow: none;\n" +
  565. "\ttext-shadow: none;\n" +
  566. "\t-unico-inner-stroke-width: 0;\n" +
  567. "}\n\n" +
  568. ".menu.button:hover,\n" +
  569. ".menu.button:active,\n" +
  570. ".menu.button:active:insensitive,\n" +
  571. ".menu.button:insensitive,\n" +
  572. ".menu.button {\n" +
  573. "\tbackground-color: @menu_bg_color;\n" +
  574. "\tbackground-image: none;\n" +
  575. "}\n\n" +
  576. "GtkTreeMenu .menuitem * {\n" +
  577. "\tcolor: @menu_fg_color;\n" +
  578. "}\n\n" +
  579. ".menuitem,\n" +
  580. ".menu .menuitem {\n" +
  581. "\tbackground-color: transparent;\n" +
  582. "}\n\n" +
  583. ".menu .menuitem:active,\n" +
  584. ".menu .menuitem:hover {\n" +
  585. "\tbackground-color: @theme_selected_bg_color;\n" +
  586. "}\n\n" +
  587. ".menuitem.check,\n" +
  588. ".menuitem.radio,\n" +
  589. ".menuitem.check:hover,\n" +
  590. ".menuitem.radio:hover,\n" +
  591. ".menuitem.check:active,\n" +
  592. ".menuitem.radio:active {\n" +
  593. "\tbackground-color: transparent;\n" +
  594. "}\n\n" +
  595. ".menu .menuitem:insensitive,\n" +
  596. ".menu .menuitem *:insensitive {\n" +
  597. "\tcolor: mix(@menu_fg_color,@menu_bg_color,0.5);\n" +
  598. "}\n\n" +
  599. ".menuitem.arrow {\n" +
  600. "\tcolor: alpha(@menu_fg_color, 0.6);\n" +
  601. "}\n\n" +
  602. ".menuitem .entry {\n" +
  603. "\tborder-color: shade(@menu_bg_color,0.7);\n" +
  604. "\tborder-image: none;\n" +
  605. "\tbackground-color: @menu_bg_color;\n" +
  606. "\tbackground-image: none;\n" +
  607. "\tcolor: @menu_fg_color;\n" +
  608. "}\n\n" +
  609. ".menuitem .accelerator {\n" +
  610. "\tcolor: alpha(@menu_fg_color,0.6);\n" +
  611. "}\n\n" +
  612. ".menuitem .accelerator:insensitive {\n" +
  613. "\tcolor: alpha(mix(@menu_fg_color,@menu_bg_color,0.5),0.6);\n" +
  614. "\ttext-shadow: none;\n" +
  615. "}\n\n" +
  616. ".menuitem.separator {\n" +
  617. "\tbackground-color: transparent;\n" +
  618. "\tcolor: shade(@menu_bg_color, 0.9);\n" +
  619. "}\n\n" +
  620. ".menuitem GtkCalendar,\n" +
  621. ".menuitem GtkCalendar.button,\n" +
  622. ".menuitem GtkCalendar.header,\n" +
  623. ".menuitem GtkCalendar.view {\n" +
  624. "\tborder-color: shade(@menu_bg_color,0.8);\n" +
  625. "\tborder-image: none;\n" +
  626. "\tbackground-color: @menu_bg_color;\n" +
  627. "\tbackground-image: none;\n" +
  628. "\tcolor: @menu_fg_color;\n" +
  629. "}\n\n" +
  630. ".menuitem GtkCalendar:inconsistent {\n" +
  631. "\tcolor: mix(@menu_fg_color,@menu_bg_color,0.5);\n" +
  632. "}\n\n" +
  633. "%s\n").printf (select_state1, selectbg_value, selectfg_value, select_state2, panel_state1, panelbg_value, panelfg_value, panel_state2, menu_state1, menubg_value, menufg_value, menu_state2);
  634. uint8[] data = text.data;
  635. long written = 0;
  636. while (written < data.length) {
  637. written += dos.write (data[written:data.length]);
  638. }
  639. } catch (Error e) {
  640. stderr.printf ("Could not write gtk3 configuration: %s\n", e.message);
  641. }
  642. try {
  643. var dos = new DataOutputStream (gtk2_config_file.replace (null, false, FileCreateFlags.REPLACE_DESTINATION));
  644. dos.put_string ("# Custom styles\n\n");
  645. string text = "%s\n%s".printf(panel_gtk2, menu_gtk2);
  646. uint8[] data = text.data;
  647. long written = 0;
  648. while (written < data.length) {
  649. written += dos.write (data[written:data.length]);
  650. }
  651. } catch (Error e) {
  652. stderr.printf ("Could not write gtk2 configuration: %s\n", e.message);
  653. }
  654. }
  655. void notify_change() {
  656. try {
  657. Process.spawn_command_line_async("notify-send -h int:transient:1 -i \"gtk-theme-config\" \"Changes applied.\" \"You might need to restart running applications.\"");
  658. } catch (Error e) {
  659. stderr.printf ("Could not display notification: %s\n", e.message);
  660. }
  661. }
  662. }
  663. class ThemeConfigApp : Gtk.Application {
  664. internal ThemeConfigApp () {
  665. Object (application_id: "org.themeconfig.app");
  666. }
  667. protected override void activate () {
  668. var window = new ThemeConfigWindow (this);
  669. window.show_all ();
  670. }
  671. }
  672. int main (string[] args) {
  673. return new ThemeConfigApp ().run (args);
  674. }