1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
Description: Show country code if country flag is not available.
Author: Adam Sloboda <ja@disorder.sk>
Forwarded: no
Last-Update: 2008-03-24
---
--- gkrellm-xkb-1.05.orig/flags/unknown.xpm
+++ gkrellm-xkb-1.05/flags/unknown.xpm
@@ -20,16 +20,16 @@ static char *flag_xpm_unknown[] = {
/* pixels */
";;;;;;;;;;;;;;;;;;;;;",
";;;;;;;;;;;;;;;;;;;;;",
-";;;;;;;#O. X@;;;;;;;;",
-";;;;;;; O*=@ +;;;;;;;",
-";;;;;;;;;;;; ;;;;;;;",
-";;;;;;;;;;;& .;;;;;;;",
-";;;;;;;;;;=oX&;;;;;;;",
-";;;;;;;;;$X %;;;;;;;;",
-";;;;;;;;; *;;;;;;;;;",
-";;;;;;;;; ;;;;;;;;;;",
";;;;;;;;;;;;;;;;;;;;;",
-";;;;;;;;; ;;;;;;;;;;",
-";;;;;;;;; ;;;;;;;;;;",
+";;;;;;;;;;;;;;;;;;;;;",
+";;;;;;;;;;;;;;;;;;;;;",
+";;;;;;;;;;;;;;;;;;;;;",
+";;;;;;;;;;;;;;;;;;;;;",
+";;;;;;;;;;;;;;;;;;;;;",
+";;;;;;;;;;;;;;;;;;;;;",
+";;;;;;;;;;;;;;;;;;;;;",
+";;;;;;;;;;;;;;;;;;;;;",
+";;;;;;;;;;;;;;;;;;;;;",
+";;;;;;;;;;;;;;;;;;;;;",
";;;;;;;;;;;;;;;;;;;;;"
};
--- gkrellm-xkb-1.05.orig/main.c
+++ gkrellm-xkb-1.05/main.c
@@ -105,6 +105,9 @@ static GkrellmTicks *pGK;
static int force_redraw = 0;
static int update_locked = 0;
+#define STYLE_NAME "xkb"
+static gint style_id;
+
static struct {
const char *country_code;
char **flag_pointer;
@@ -197,6 +200,7 @@ static GkrellmMonitor plugin_mon = { /*
/* }}} */
GkrellmMonitor *gkrellm_init_plugin(void) { /* {{{ */
+ style_id = gkrellm_add_meter_style(&plugin_mon, STYLE_NAME);
monitor = &plugin_mon;
pGK = gkrellm_ticks();
return monitor;
@@ -334,6 +338,7 @@ static void draw_flag(int redraw) { /* {
int num_groups = 0;
xkbGroup groups[XKB_MAX_GROUPS];
int active_group;
+ static int current_group;
int flag_width, flag_height;
int loc_x, loc_y;
static GdkPixmap *flag_pix = NULL;
@@ -341,6 +346,7 @@ static void draw_flag(int redraw) { /* {
static GdkPixmap *num_pix = NULL;
static GdkPixmap *bg_scaled = NULL;
static GkrellmDecal *decal_flag = NULL;
+ static GkrellmDecal *decal_text = NULL;
static GkrellmDecal *decal_caps = NULL;
static GkrellmDecal *decal_num = NULL;
static GkrellmDecal *decal_bg = NULL;
@@ -371,10 +377,12 @@ static void draw_flag(int redraw) { /* {
}
if (! (redraw || force_redraw ||
- current_flag == NULL || current_flag != groups[active_group].flag_xpm ||
+ current_flag == NULL || /* current_flag != groups[active_group].flag_xpm || */
+ current_group != active_group ||
ind_caps != ind_caps_prev || ind_num != ind_num_prev))
goto cleanup;
+ current_group = active_group;
/* fprintf(stderr, "Redrawing...\n"); */
ind_caps_prev = ind_caps;
@@ -388,6 +396,9 @@ static void draw_flag(int redraw) { /* {
if (!redraw && decal_flag) {
gkrellm_destroy_decal(decal_flag); decal_flag = NULL;
}
+ if (!redraw && decal_text) {
+ gkrellm_destroy_decal(decal_text); decal_text = NULL;
+ }
if (!redraw && decal_caps) {
gkrellm_destroy_decal(decal_caps); decal_caps = NULL;
}
@@ -435,6 +446,26 @@ static void draw_flag(int redraw) { /* {
decal_caps = gkrellm_create_decal_pixmap(panel, caps_pix, NULL, 0, NULL, 0, loc_y);
decal_num = gkrellm_create_decal_pixmap(panel, num_pix, NULL, 0, NULL,
gkrellm_chart_width() - 14, loc_y);
+
+ /* Also draw country code if we don't have flag */
+ gchar **xkb_rules;
+ if (current_flag == flag_xpm_unknown &&
+ (xkb_rules = parse_xkb_rules_names())) {
+ GkrellmStyle *style;
+ GkrellmTextstyle *ts, *ts_alt;
+ style = gkrellm_meter_style(style_id);
+ ts = gkrellm_meter_textstyle(style_id);
+ ts_alt = gkrellm_meter_alt_textstyle(style_id);
+
+ decal_text = gkrellm_create_decal_text(panel, "XX", ts, style, -1, -1, 0);
+ int string_w = gkrellm_gdk_string_width(decal_text->text_style.font, xkb_rules[active_group]);
+ decal_text->x = loc_x + (flag_width/2) - (string_w/2);
+ decal_text->y = loc_y + 2;
+ gkrellm_draw_decal_text(panel, decal_text, xkb_rules[active_group], 0);
+
+ g_strfreev(xkb_rules);
+ }
+
gkrellm_draw_decal_pixmap(panel, decal_flag, 0);
gkrellm_draw_decal_pixmap(panel, decal_caps, 0);
gkrellm_draw_decal_pixmap(panel, decal_num, 0);
|