1 /* 2 * Copyright 2007-2011, Haiku Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * François Revol, revol@free.fr 7 * Axel Dörfler, axeld@pinc-software.de 8 */ 9 10 11 #include <getopt.h> 12 #include <stdio.h> 13 14 #include <Application.h> 15 #include <InterfaceDefs.h> 16 #include <String.h> 17 18 #include <private/interface/DecoratorPrivate.h> 19 20 21 using namespace BPrivate; 22 23 24 static int sColorWhich = -1; 25 static struct option const kLongOptions[] = { 26 {"activetab", required_argument, &sColorWhich, B_WINDOW_TAB_COLOR}, 27 {"frame", required_argument, &sColorWhich, B_WINDOW_INACTIVE_TAB_COLOR}, //XXX:?? 28 {"activeborder", required_argument, &sColorWhich, -1}, //XXX:?? 29 {"inactiveborder", required_argument, &sColorWhich, -1}, //XXX:?? 30 {"activetitle", required_argument, &sColorWhich, B_WINDOW_TEXT_COLOR}, 31 {"inactivetitle", required_argument, &sColorWhich, B_WINDOW_INACTIVE_TEXT_COLOR}, 32 //temporary stuff 33 // grep ' B_.*_COLOR' headers/os/interface/InterfaceDefs.h | awk '{ print "I(" substr(tolower($1),3) ", " $1 ")," }' 34 #define I(l,v) \ 35 { #l, required_argument, &sColorWhich, v }, \ 36 { #v, required_argument, &sColorWhich, v } 37 38 I(panel_background_color, B_PANEL_BACKGROUND_COLOR), 39 I(panel_text_color, B_PANEL_TEXT_COLOR), 40 I(document_background_color, B_DOCUMENT_BACKGROUND_COLOR), 41 I(document_text_color, B_DOCUMENT_TEXT_COLOR), 42 I(control_background_color, B_CONTROL_BACKGROUND_COLOR), 43 I(control_text_color, B_CONTROL_TEXT_COLOR), 44 I(control_border_color, B_CONTROL_BORDER_COLOR), 45 I(control_highlight_color, B_CONTROL_HIGHLIGHT_COLOR), 46 I(navigation_base_color, B_NAVIGATION_BASE_COLOR), 47 I(navigation_pulse_color, B_NAVIGATION_PULSE_COLOR), 48 I(shine_color, B_SHINE_COLOR), 49 I(shadow_color, B_SHADOW_COLOR), 50 I(menu_background_color, B_MENU_BACKGROUND_COLOR), 51 I(menu_selected_background_color, B_MENU_SELECTED_BACKGROUND_COLOR), 52 I(menu_item_text_color, B_MENU_ITEM_TEXT_COLOR), 53 I(menu_selected_item_text_color, B_MENU_SELECTED_ITEM_TEXT_COLOR), 54 I(menu_selected_border_color, B_MENU_SELECTED_BORDER_COLOR), 55 I(tooltip_background_color, B_TOOL_TIP_BACKGROUND_COLOR), 56 I(tooltip_text_color, B_TOOL_TIP_TEXT_COLOR), 57 I(success_color, B_SUCCESS_COLOR), 58 I(failure_color, B_FAILURE_COLOR), 59 I(keyboard_navigation_color, B_KEYBOARD_NAVIGATION_COLOR), 60 I(menu_selection_background_color, B_MENU_SELECTION_BACKGROUND_COLOR), 61 I(desktop_color, B_DESKTOP_COLOR), 62 I(window_tab_color, B_WINDOW_TAB_COLOR), 63 I(window_text_color, B_WINDOW_TEXT_COLOR), 64 I(window_inactive_tab_color, B_WINDOW_INACTIVE_TAB_COLOR), 65 I(window_inactive_text_color, B_WINDOW_INACTIVE_TEXT_COLOR), 66 {"sum", required_argument, 0, 's'}, 67 {"refresh", no_argument, 0, 'r'}, 68 {"help", no_argument, 0, 'h'}, 69 {NULL} 70 }; 71 72 73 extern const char *__progname; 74 static const char *sProgramName = __progname; 75 76 77 void 78 usage(void) 79 { 80 printf("%s [-sum md5sum] [colID colspec] [-refresh]\n", sProgramName); 81 printf("Tweak the default window decorator colors.\n"); 82 printf("\t-sum deprecated option, kept for compatibility\n"); 83 printf("\t-refresh refresh the entire display (force update)\n"); 84 printf("\tcolID can be:\n"); 85 printf("\t-activetab\n"); 86 printf("\t-frame\n"); 87 printf("\t-activeborder\n"); 88 printf("\t-inactiveborder\n"); 89 printf("\t-activetitle\n"); 90 printf("\t-inactivetitle\n"); 91 printf("\tcolspec is a 6 digit hexadecimal color number. \n" 92 "\t\t\t(rrggbb, html format)\n"); 93 } 94 95 96 static int 97 UpdateUIColor(color_which which, const char *str) 98 { 99 rgb_color color; 100 unsigned int r, g, b; 101 if (which < 0) 102 return -1; 103 // parse 104 if (!str || !str[0]) 105 return -1; 106 if (str[0] == '#') 107 str++; 108 if (sscanf(str, "%02x%02x%02x", &r, &g, &b) < 3) 109 return -1; 110 color.red = r; 111 color.green = g; 112 color.blue = b; 113 color.alpha = 255; 114 //printf("setting %d to {%d, %d, %d, %d}\n", which, r, g, b, 255); 115 set_ui_color(which, color); 116 return B_OK; 117 } 118 119 int 120 main(int argc, char **argv) 121 { 122 BApplication app("application/x-vnd.Haiku-WindowShade"); 123 int c; 124 125 // parse command line parameters 126 127 while ((c = getopt_long_only(argc, argv, "h", kLongOptions, NULL)) != -1) { 128 switch (c) { 129 case 0: 130 UpdateUIColor((color_which)sColorWhich, optarg); 131 break; 132 case 'h': 133 usage(); 134 return 0; 135 default: 136 usage(); 137 return 1; 138 139 case 'r': 140 { 141 // TODO: refresh (but shouldn't be needed) 142 BString name; 143 if (get_decorator(name)) 144 set_decorator(name); 145 break; 146 } 147 148 case 's': 149 // IGNORED, for compatibility with original app 150 break; 151 } 152 sColorWhich = -1; 153 } 154 155 return 0; 156 } 157