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