Skip to content
Permalink
Browse files

media-keys: Add labels for the rfkill OSD

Which should hopefully make the icons a bit clearer.

Signed-off-by: Zhang Xianwei <zhang.xianwei8@zte.com.cn>
  • Loading branch information...
zhangxianwei8 authored and lukefromdc committed Nov 11, 2018
1 parent ea4ab83 commit 9e7a5675cd0efb6c939ca8ed81eaee96065a7ded
@@ -17,14 +17,24 @@
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="acme_label">
<property name="visible">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkProgressBar" id="acme_volume_progressbar">
<property name="visible">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
</object>
@@ -581,7 +581,8 @@ do_eject_action (MsdMediaKeysManager *manager)
/* Show the dialogue */
dialog_init (manager);
msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog),
"media-eject");
"media-eject",
NULL);
dialog_show (manager);

/* Clean up the drive selection and exit if no suitable
@@ -606,7 +607,8 @@ do_touchpad_osd_action (MsdMediaKeysManager *manager, gboolean state)
{
dialog_init (manager);
msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog),
state ? "input-touchpad" : "touchpad-disabled");
state ? "input-touchpad" : "touchpad-disabled",
NULL);
dialog_show (manager);
}

@@ -844,14 +846,21 @@ set_rfkill_complete (GObject *object,
g_debug ("Finished changing rfkill, property %s is now %s",
data->property, data->target_state ? "true" : "false");

if (data->bluetooth)
msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (data->manager->priv->dialog),
data->target_state ? "bluetooth-disabled-symbolic"
: "bluetooth-active-symbolic");
else
msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (data->manager->priv->dialog),
data->target_state ? "airplane-mode-symbolic"
: "network-wireless-signal-excellent-symbolic");
if (data->bluetooth){
if (data->target_state)
msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (data->manager->priv->dialog),
"bluetooth-disabled-symbolic", _("Bluetooth disabled"));
else
msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (data->manager->priv->dialog),
"bluetooth-active-symbolic", _("Bluetooth enabled"));
} else {
if (data->target_state)
msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (data->manager->priv->dialog),
"airplane-mode-symbolic", _("Airplane mode enabled"));
else
msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (data->manager->priv->dialog),
"network-wireless-signal-excellent-symbolic", _("Airplane mode disabled"));
}
dialog_show (data->manager);
out:
g_free (data->property);
@@ -880,7 +889,8 @@ do_rfkill_action (MsdMediaKeysManager *manager,

if (get_rfkill_property (manager, hw_mode)) {
msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog),
"airplane-mode-symbolic");
"airplane-mode-symbolic",
_("Hardware Airplane Mode"));
dialog_show (manager);
return;
}
@@ -38,12 +38,14 @@ struct MsdMediaKeysWindowPrivate
{
MsdMediaKeysWindowAction action;
char *icon_name;
char *description;

guint volume_muted : 1;
int volume_level;

GtkImage *image;
GtkWidget *progress;
GtkWidget *label;
};

G_DEFINE_TYPE (MsdMediaKeysWindow, msd_media_keys_window, MSD_TYPE_OSD_WINDOW)
@@ -62,6 +64,18 @@ volume_controls_set_visible (MsdMediaKeysWindow *window,
}
}

static void
description_label_set_visible (MsdMediaKeysWindow *window,
gboolean visible)
{
if (visible) {
gtk_label_set_text (GTK_LABEL (window->priv->label), window->priv->description);
gtk_widget_show (window->priv->label);
} else {
gtk_widget_hide (window->priv->label);
}
}

static void
window_set_icon_name (MsdMediaKeysWindow *window,
const char *name)
@@ -80,6 +94,7 @@ action_changed (MsdMediaKeysWindow *window)
switch (window->priv->action) {
case MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME:
volume_controls_set_visible (window, TRUE);
description_label_set_visible (window, FALSE);

if (window->priv->volume_muted) {
window_set_icon_name (window, "audio-volume-muted");
@@ -90,6 +105,7 @@ action_changed (MsdMediaKeysWindow *window)
break;
case MSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM:
volume_controls_set_visible (window, FALSE);
description_label_set_visible (window, TRUE);
window_set_icon_name (window, window->priv->icon_name);
break;
default:
@@ -147,16 +163,20 @@ msd_media_keys_window_set_action (MsdMediaKeysWindow *window,

void
msd_media_keys_window_set_action_custom (MsdMediaKeysWindow *window,
const char *icon_name)
const char *icon_name,
const char *description)
{
g_return_if_fail (MSD_IS_MEDIA_KEYS_WINDOW (window));
g_return_if_fail (icon_name != NULL);

if (window->priv->action != MSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM ||
g_strcmp0 (window->priv->icon_name, icon_name) != 0) {
g_strcmp0 (window->priv->icon_name, icon_name) != 0 ||
g_strcmp0 (window->priv->description, description) != 0) {
window->priv->action = MSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM;
g_free (window->priv->icon_name);
window->priv->icon_name = g_strdup (icon_name);
g_free (window->priv->description);
window->priv->description = g_strdup (description);
action_changed (window);
} else {
msd_osd_window_update_and_hide (MSD_OSD_WINDOW (window));
@@ -388,6 +408,23 @@ render_speaker (MsdMediaKeysWindow *window,
return TRUE;
}

static void
draw_description_label (MsdMediaKeysWindow *window,
cairo_t *cr,
double _y0,
double width)
{
cairo_text_extents_t extents;

cairo_set_source_rgb (cr, 1, 1, 1);
cairo_set_font_size (cr, 14);

/* centered text */
cairo_text_extents (cr, window->priv->description, &extents);
cairo_move_to (cr, width / 2 - extents.width / 2, _y0);
cairo_show_text (cr, window->priv->description);
}

static void
draw_volume_boxes (MsdMediaKeysWindow *window,
cairo_t *cr,
@@ -574,22 +611,32 @@ draw_action_custom (MsdMediaKeysWindow *window,
double icon_box_height;
double icon_box_x0;
double icon_box_y0;
double label_box_y0;
double label_box_width;
double label_box_height;
gboolean res;

gtk_window_get_size (GTK_WINDOW (window), &window_width, &window_height);

icon_box_width = round (window_width * 0.65);
icon_box_height = round (window_height * 0.65);
label_box_width = round (window_width);
label_box_height = round (window_height * 0.175);

icon_box_x0 = (window_width - icon_box_width) / 2;
icon_box_y0 = (window_height - icon_box_height) / 2;
label_box_y0 = round (window_height - label_box_height / 2);

#if 0
g_message ("icon box: w=%f h=%f _x0=%f _y0=%f",
icon_box_width,
icon_box_height,
icon_box_x0,
icon_box_y0);
g_message ("label box: w=%f h=%f _x0=0.0 _y0=%f",
label_box_width,
label_box_height,
label_box_y0);
#endif

res = render_custom (window,
@@ -602,6 +649,14 @@ draw_action_custom (MsdMediaKeysWindow *window,
icon_box_x0, icon_box_y0,
icon_box_width, icon_box_height);
}

if (window->priv->description != NULL) {
/* draw description label meter */
draw_description_label (window,
cr,
label_box_y0,
label_box_width);
}
}

static void
@@ -650,6 +705,7 @@ msd_media_keys_window_init (MsdMediaKeysWindow *window)

window->priv->image = GTK_IMAGE (gtk_builder_get_object (builder, "acme_image"));
window->priv->progress = GTK_WIDGET (gtk_builder_get_object (builder, "acme_volume_progressbar"));
window->priv->label = GTK_WIDGET (gtk_builder_get_object (builder, "acme_label"));
box = GTK_WIDGET (gtk_builder_get_object (builder, "acme_box"));

if (box != NULL) {
@@ -63,7 +63,8 @@ GtkWidget * msd_media_keys_window_new (void);
void msd_media_keys_window_set_action (MsdMediaKeysWindow *window,
MsdMediaKeysWindowAction action);
void msd_media_keys_window_set_action_custom (MsdMediaKeysWindow *window,
const char *icon_name);
const char *icon_name,
const char *description);
void msd_media_keys_window_set_volume_muted (MsdMediaKeysWindow *window,
gboolean muted);
void msd_media_keys_window_set_volume_level (MsdMediaKeysWindow *window,
@@ -63,19 +63,22 @@ update_state (GtkWidget *window)
break;
case 4:
msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (window),
"media-eject");
"media-eject",
NULL);

gtk_widget_show (window);
break;
case 5:
msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (window),
"touchpad-disabled");
"touchpad-disabled",
NULL);

gtk_widget_show (window);
break;
case 6:
msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (window),
"input-touchpad");
"input-touchpad",
NULL);

gtk_widget_show (window);
break;

0 comments on commit 9e7a567

Please sign in to comment.
You can’t perform that action at this time.