Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jun 6th, 2010  |  syntax: None  |  size: 11.65 KB  |  hits: 118  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. diff -ruN src-old/bubble.c src/bubble.c
  2. --- src-old/bubble.c    2009-10-20 11:48:09.000000000 +0300
  3. +++ src/bubble.c        2009-12-05 01:13:41.000000000 +0200
  4. @@ -122,25 +122,25 @@
  5.  // FIXME: this is in class Defaults already, but not yet hooked up so for the
  6.  // moment we use the macros here, these values reflect the visual-guideline
  7.  // for jaunty notifications
  8. -#define TEXT_TITLE_COLOR_R 1.0f
  9. -#define TEXT_TITLE_COLOR_G 1.0f
  10. -#define TEXT_TITLE_COLOR_B 1.0f
  11. -#define TEXT_TITLE_COLOR_A 1.0f
  12. -
  13. -#define TEXT_BODY_COLOR_R  0.91f
  14. -#define TEXT_BODY_COLOR_G  0.91f
  15. -#define TEXT_BODY_COLOR_B  0.91f
  16. -#define TEXT_BODY_COLOR_A  1.0f
  17. +float TEXT_TITLE_COLOR_R = 1.0f;
  18. +float TEXT_TITLE_COLOR_G = 1.0f;
  19. +float TEXT_TITLE_COLOR_B = 1.0f;
  20. +float TEXT_TITLE_COLOR_A = 1.0f;
  21. +
  22. +float TEXT_BODY_COLOR_R  = 0.91f;
  23. +float TEXT_BODY_COLOR_G  = 0.91f;
  24. +float TEXT_BODY_COLOR_B  = 0.91f;
  25. +float TEXT_BODY_COLOR_A  = 1.0f;
  26.  
  27.  #define TEXT_SHADOW_COLOR_R 0.0f
  28.  #define TEXT_SHADOW_COLOR_G 0.0f
  29.  #define TEXT_SHADOW_COLOR_B 0.0f
  30. -#define TEXT_SHADOW_COLOR_A 1.0f
  31. +float TEXT_SHADOW_COLOR_A  = 1.0f;
  32.  
  33. -#define BUBBLE_BG_COLOR_R  0.15f
  34. -#define BUBBLE_BG_COLOR_G  0.15f
  35. -#define BUBBLE_BG_COLOR_B  0.15f
  36. -#define BUBBLE_BG_COLOR_A  0.9f
  37. +float BUBBLE_BG_COLOR_R  = 0.07f;
  38. +float BUBBLE_BG_COLOR_G  = 0.07f;
  39. +float BUBBLE_BG_COLOR_B  = 0.07f;
  40. +float BUBBLE_BG_COLOR_A  = 0.9f;
  41.  
  42.  #define INDICATOR_UNLIT_R  1.0f
  43.  #define INDICATOR_UNLIT_G  1.0f
  44. diff -ruN src-old/defaults.c src/defaults.c
  45. --- src-old/defaults.c  2009-10-20 11:29:52.000000000 +0300
  46. +++ src/defaults.c      2009-12-04 04:46:41.000000000 +0200
  47. @@ -114,40 +114,41 @@
  48.  /* these values are interpreted as em-measurements and do comply to the
  49.   * visual guide for jaunty-notifications */
  50.  #define DEFAULT_DESKTOP_BOTTOM_GAP    6.0f
  51. -#define DEFAULT_BUBBLE_WIDTH         24.0f
  52. -#define DEFAULT_BUBBLE_MIN_HEIGHT     5.0f
  53. -#define DEFAULT_BUBBLE_MAX_HEIGHT    12.2f
  54. -#define DEFAULT_BUBBLE_VERT_GAP       0.5f
  55. -#define DEFAULT_BUBBLE_HORZ_GAP       0.5f
  56. +float DEFAULT_BUBBLE_WIDTH  = 24.0f;
  57. +float DEFAULT_BUBBLE_MIN_HEIGHT  = 5.0f;
  58. +float DEFAULT_BUBBLE_MAX_HEIGHT  = 12.2f;
  59. +float DEFAULT_BUBBLE_VERT_GAP  = 0.5f;
  60. +float DEFAULT_BUBBLE_HORZ_GAP  = 0.5f;
  61.  #define DEFAULT_BUBBLE_SHADOW_SIZE    0.7f
  62.  #define DEFAULT_BUBBLE_SHADOW_COLOR  "#000000"
  63.  #define DEFAULT_BUBBLE_BG_COLOR      "#131313"
  64.  #define DEFAULT_BUBBLE_BG_OPACITY    "#cc"
  65.  #define DEFAULT_BUBBLE_HOVER_OPACITY "#66"
  66. -#define DEFAULT_BUBBLE_CORNER_RADIUS 0.375f
  67. +float DEFAULT_BUBBLE_CORNER_RADIUS  = 0.375f;
  68.  #define DEFAULT_CONTENT_SHADOW_SIZE  0.125f
  69.  #define DEFAULT_CONTENT_SHADOW_COLOR "#000000"
  70. -#define DEFAULT_MARGIN_SIZE          1.0f
  71. -#define DEFAULT_ICON_SIZE            3.0f
  72. -#define DEFAULT_GAUGE_SIZE           0.625f
  73. -#define DEFAULT_GAUGE_OUTLINE_WIDTH  0.125f
  74. +float DEFAULT_MARGIN_SIZE  = 1.0f;
  75. +float DEFAULT_ICON_SIZE  = 3.0f;
  76. +float DEFAULT_GAUGE_SIZE  = 0.625f;
  77. +#define DEFAULT_GAUGE_OUTLINE_WIDTH     0.125f
  78.  #define DEFAULT_TEXT_FONT_FACE       "Sans"
  79.  #define DEFAULT_TEXT_TITLE_COLOR     "#ffffff"
  80. -#define DEFAULT_TEXT_TITLE_WEIGHT    TEXT_WEIGHT_BOLD
  81. -#define DEFAULT_TEXT_TITLE_SIZE      1.0f
  82. +short DEFAULT_TEXT_TITLE_WEIGHT  = TEXT_WEIGHT_BOLD;
  83. +float DEFAULT_TEXT_TITLE_SIZE  = 1.0f;
  84.  #define DEFAULT_TEXT_BODY_COLOR      "#eaeaea"
  85. -#define DEFAULT_TEXT_BODY_WEIGHT     TEXT_WEIGHT_NORMAL
  86. -#define DEFAULT_TEXT_BODY_SIZE       0.9f
  87. +short DEFAULT_TEXT_BODY_WEIGHT  = TEXT_WEIGHT_NORMAL;
  88. +float DEFAULT_TEXT_BODY_SIZE  = 0.9f;
  89.  #define DEFAULT_PIXELS_PER_EM        10.0f
  90.  #define DEFAULT_SYSTEM_FONT_SIZE     10.0f
  91.  #define DEFAULT_SCREEN_DPI           96.0f
  92.  #define DEFAULT_GRAVITY              GRAVITY_NORTH_EAST
  93. +short SLOT_ALLOCATION  = SLOT_ALLOCATION_DYNAMIC;
  94.  
  95.  /* these values are interpreted as milliseconds-measurements and do comply to
  96.   * the visual guide for jaunty-notifications */
  97. -#define DEFAULT_FADE_IN_TIMEOUT      250
  98. -#define DEFAULT_FADE_OUT_TIMEOUT     1000
  99. -#define DEFAULT_ON_SCREEN_TIMEOUT    10000
  100. +float DEFAULT_FADE_IN_TIMEOUT  = 250;
  101. +float DEFAULT_FADE_OUT_TIMEOUT  = 1000;
  102. +float DEFAULT_ON_SCREEN_TIMEOUT  = 10000;
  103.  
  104.  /* GConf-keys to watch */
  105.  #define GCONF_UI_FONT_NAME        "/desktop/gnome/interface/font_name"
  106. @@ -755,7 +756,7 @@
  107.         }
  108.  
  109.         // use fixed slot-allocation for async. and sync. bubbles
  110. -       self->slot_allocation = SLOT_ALLOCATION_FIXED;
  111. +       self->slot_allocation = SLOT_ALLOCATION;
  112.  }
  113.  
  114.  static void
  115. diff -ruN src-old/main.c src/main.c
  116. --- src-old/main.c      2009-10-20 11:29:52.000000000 +0300
  117. +++ src/main.c  2009-12-05 01:14:36.000000000 +0200
  118. @@ -25,6 +25,10 @@
  119.  ** with this program.  If not, see <http://www.gnu.org/licenses/>.
  120.  **
  121.  *******************************************************************************/
  122. +#define _GNU_SOURCE    /* getline */
  123. +#include <unistd.h>    /* getuid */
  124. +#include <pwd.h>       /* getpwuid */
  125. +#include <sys/types.h>
  126.  
  127.  #include <string.h>
  128.  #include <stdlib.h>
  129. @@ -39,6 +43,197 @@
  130.  
  131.  #define ICONS_DIR  (DATADIR G_DIR_SEPARATOR_S "notify-osd" G_DIR_SEPARATOR_S "icons")
  132.  
  133. +/* begin hack */
  134. +extern float TEXT_TITLE_COLOR_R;
  135. +extern float TEXT_TITLE_COLOR_G;
  136. +extern float TEXT_TITLE_COLOR_B;
  137. +extern float TEXT_TITLE_COLOR_A;
  138. +
  139. +extern float TEXT_BODY_COLOR_R;
  140. +extern float TEXT_BODY_COLOR_G;
  141. +extern float TEXT_BODY_COLOR_B;
  142. +extern float TEXT_BODY_COLOR_A;
  143. +
  144. +extern float TEXT_SHADOW_COLOR_A;
  145. +
  146. +extern float BUBBLE_BG_COLOR_R;
  147. +extern float BUBBLE_BG_COLOR_G;
  148. +extern float BUBBLE_BG_COLOR_B;
  149. +extern float BUBBLE_BG_COLOR_A;
  150. +
  151. +extern float DEFAULT_TEXT_TITLE_SIZE;
  152. +extern float DEFAULT_TEXT_BODY_SIZE;
  153. +extern float DEFAULT_ON_SCREEN_TIMEOUT;
  154. +
  155. +extern short DEFAULT_TEXT_TITLE_WEIGHT;
  156. +extern short DEFAULT_TEXT_BODY_WEIGHT;
  157. +extern short SLOT_ALLOCATION;
  158. +
  159. +extern float DEFAULT_MARGIN_SIZE;
  160. +extern float DEFAULT_BUBBLE_CORNER_RADIUS;
  161. +extern float DEFAULT_BUBBLE_WIDTH;
  162. +extern float DEFAULT_BUBBLE_VERT_GAP;
  163. +extern float DEFAULT_BUBBLE_HORZ_GAP;
  164. +extern float DEFAULT_ICON_SIZE;
  165. +extern float DEFAULT_GAUGE_SIZE;
  166. +
  167. +void parse_color(unsigned int c, float* r, float* g, float* b)
  168. +{
  169. +    *b = (float)(c & 0xFF) / (float)(0xFF);
  170. +    c >>= 8;
  171. +    *g = (float)(c & 0xFF) / (float)(0xFF);
  172. +    c >>= 8;
  173. +    *r = (float)(c & 0xFF) / (float)(0xFF);
  174. +}
  175. +
  176. +
  177. +void load_settings(void)
  178. +{
  179. +    char file[PATH_MAX];
  180. +    uid_t uid = getuid();
  181. +    const char* settings_file_name = ".notify-osd";
  182. +    
  183. +    struct passwd* pw = getpwuid(uid);
  184. +    if (!pw) {
  185. +        fprintf(stderr,
  186. +                "failed to retrieve home directory. using default settings.\n");
  187. +        return;
  188. +    }
  189. +    /* $HOME/.notify-osd */
  190. +    snprintf(file, sizeof(file), "%s%s%s", pw->pw_dir,
  191. +             G_DIR_SEPARATOR_S, settings_file_name);
  192. +
  193. +    FILE* fp = fopen(file, "r");
  194. +
  195. +    if (!fp) {
  196. +        fprintf(stderr, "could not open '%s'. using default settings.\n", file);
  197. +        return;
  198. +
  199. +    }
  200. +    printf("reading settings from '%s'\n", file);
  201. +
  202. +    char* buf = NULL;
  203. +    size_t size = 0;
  204. +    char key[32], value[32];
  205. +    float fvalue;
  206. +    unsigned int ivalue;
  207. +
  208. +    while(getline(&buf, &size, fp) != -1) {
  209. +        if (sscanf(buf, "%31s = %31s", key, value) != 2)
  210. +            continue;
  211. +        if (!strcmp(key, "bubble-background-color") &&
  212. +            sscanf(value, "%x", &ivalue)) {
  213. +
  214. +            parse_color(ivalue, &BUBBLE_BG_COLOR_R, &BUBBLE_BG_COLOR_G,
  215. +                        &BUBBLE_BG_COLOR_B);
  216. +            
  217. +
  218. +        } else if (!strcmp(key, "bubble-background-opacity") &&
  219. +                   sscanf(value, "%f", &fvalue)) {
  220. +            
  221. +            BUBBLE_BG_COLOR_A = fvalue*0.01;
  222. +            
  223. +        } else if (!strcmp(key, "text-title-color")  &&
  224. +                   sscanf(value, "%x", &ivalue) ) {
  225. +
  226. +            parse_color(ivalue, &TEXT_TITLE_COLOR_R, &TEXT_TITLE_COLOR_G,
  227. +                        &TEXT_TITLE_COLOR_B);
  228. +            
  229. +        } else if (!strcmp(key, "text-title-opacity") &&
  230. +                   sscanf(value, "%f", &fvalue) ) {
  231. +            
  232. +            TEXT_TITLE_COLOR_A = fvalue*0.01;
  233. +            
  234. +        } else if (!strcmp(key, "text-body-color")  &&
  235. +                   sscanf(value, "%x", &ivalue) ) {
  236. +
  237. +            parse_color(ivalue, &TEXT_BODY_COLOR_R, &TEXT_BODY_COLOR_G,
  238. +                        &TEXT_BODY_COLOR_B);
  239. +
  240. +        } else if (!strcmp(key, "text-body-opacity") &&
  241. +                   sscanf(value, "%f", &fvalue) ) {
  242. +            
  243. +            TEXT_BODY_COLOR_A = fvalue*0.01;
  244. +            
  245. +        } else if (!strcmp(key, "text-shadow-opacity") &&
  246. +                   sscanf(value, "%f", &fvalue) ) {
  247. +            
  248. +            TEXT_SHADOW_COLOR_A = fvalue*0.01;
  249. +            
  250. +        } else if (!strcmp(key, "text-title-size") &&
  251. +                   sscanf(value, "%f", &fvalue) ) {
  252. +            DEFAULT_TEXT_TITLE_SIZE = fvalue*0.01;
  253. +            
  254. +        } else if (!strcmp(key, "text-body-size") &&
  255. +                   sscanf(value, "%f", &fvalue) ) {
  256. +            DEFAULT_TEXT_BODY_SIZE = fvalue*0.01;
  257. +            
  258. +        } else if (!strcmp(key, "bubble-expire-timeout") &&
  259. +                   sscanf(value, "%f", &fvalue) ) {
  260. +            DEFAULT_ON_SCREEN_TIMEOUT = fvalue*1000;
  261. +            
  262. +        } else if (!strcmp(key, "text-title-weight")) {
  263. +                                       if (!strcmp(value, "bold")) {
  264. +                                               DEFAULT_TEXT_TITLE_WEIGHT = 700;
  265. +                                       } else  if (!strcmp(value, "normal")) {
  266. +                                               DEFAULT_TEXT_TITLE_WEIGHT = 400;
  267. +                                       } else  if (!strcmp(value, "light")) {
  268. +                                               DEFAULT_TEXT_TITLE_WEIGHT = 300;
  269. +                                       }
  270. +        } else if (!strcmp(key, "text-body-weight")) {
  271. +                                       if (!strcmp(value, "bold")) {
  272. +                                               DEFAULT_TEXT_BODY_WEIGHT = 700;
  273. +                                       } else  if (!strcmp(value, "normal")) {
  274. +                                               DEFAULT_TEXT_BODY_WEIGHT = 400;
  275. +                                       } else  if (!strcmp(value, "light")) {
  276. +                                               DEFAULT_TEXT_BODY_WEIGHT = 300;
  277. +                                       }
  278. +        } else if (!strcmp(key, "text-margin-size") &&
  279. +                   sscanf(value, "%f", &fvalue) ) {
  280. +            DEFAULT_MARGIN_SIZE = fvalue*0.1;
  281. +            
  282. +        } else if (!strcmp(key, "bubble-corner-radius") &&
  283. +                   sscanf(value, "%f", &fvalue) ) {
  284. +            DEFAULT_BUBBLE_CORNER_RADIUS = fvalue*0.01;
  285. +            
  286. +        } else if (!strcmp(key, "bubble-width") &&
  287. +                   sscanf(value, "%f", &fvalue) ) {
  288. +            DEFAULT_BUBBLE_WIDTH = fvalue*0.1;
  289. +            
  290. +        } else if (!strcmp(key, "slot-allocation")) {
  291. +                                       if (!strcmp(value, "dynamic")) {
  292. +                                               SLOT_ALLOCATION = SLOT_ALLOCATION_DYNAMIC;
  293. +                                       } else  if (!strcmp(value, "fixed")) {
  294. +                                               SLOT_ALLOCATION = SLOT_ALLOCATION_FIXED;
  295. +                                       }
  296. +        } else if (!strcmp(key, "bubble-vertical-gap") &&
  297. +                   sscanf(value, "%f", &fvalue) ) {
  298. +            DEFAULT_BUBBLE_VERT_GAP = fvalue*0.1;
  299. +            
  300. +        } else if (!strcmp(key, "bubble-horizontal-gap") &&
  301. +                   sscanf(value, "%f", &fvalue) ) {
  302. +            DEFAULT_BUBBLE_HORZ_GAP = fvalue*0.1;
  303. +            
  304. +        } else if (!strcmp(key, "bubble-icon-size") &&
  305. +                   sscanf(value, "%f", &fvalue) ) {
  306. +            DEFAULT_ICON_SIZE = fvalue*0.1;
  307. +            
  308. +        } else if (!strcmp(key, "bubble-gauge-size") &&
  309. +                   sscanf(value, "%f", &fvalue) ) {
  310. +            DEFAULT_GAUGE_SIZE = fvalue*0.1;
  311. +            
  312. +        }
  313. +        
  314. +    }
  315. +
  316. +    if (buf) {
  317. +        free(buf);
  318. +    }
  319. +
  320. +    fclose(fp);
  321. +}
  322. +/* end hack */
  323. +
  324.  int
  325.  main (int    argc,
  326.        char** argv)
  327. @@ -58,6 +253,8 @@
  328.         gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(),
  329.                                           ICONS_DIR);
  330.  
  331. +       load_settings();
  332. +      
  333.         defaults = defaults_new ();
  334.         observer = observer_new ();
  335.         stack = stack_new (defaults, observer);