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