|
|
@@ -65,6 +65,19 @@ static int bar_pwr_tip_want; /* tooltip computed for this frame */
|
|
|
static int bar_pwr_tip_on; /* tooltip pixels currently on screen */
|
|
|
static int bar_pwr_tip_on_x, bar_pwr_tip_on_y;
|
|
|
static unsigned int bar_pwr_tip_on_w, bar_pwr_tip_on_h;
|
|
|
+/* Brightness OSD: a centered bubble shown after the kernel's backlight
|
|
|
+ * seq changes, then hidden after OSD_MS. */
|
|
|
+#define OSD_MS 3000
|
|
|
+#define OSD_W 210
|
|
|
+#define OSD_H 60
|
|
|
+static int osd_show; /* should be visible this frame */
|
|
|
+static int osd_visible; /* pixels are on screen */
|
|
|
+static int osd_level;
|
|
|
+static unsigned int osd_until;
|
|
|
+static unsigned int osd_seen_seq;
|
|
|
+static int osd_seen_valid;
|
|
|
+static int osd_x, osd_y;
|
|
|
+static unsigned int osd_w, osd_h;
|
|
|
static char bar_msg[24];
|
|
|
static unsigned int bar_msg_until;
|
|
|
static int bar_msg_dirty;
|
|
|
@@ -865,6 +878,98 @@ static void bar_tooltip_overlay(struct wm_present_info *p)
|
|
|
bar_pwr_tip_on_w, bar_pwr_tip_on_h);
|
|
|
}
|
|
|
|
|
|
+/* Center the brightness bubble in the work area, clamped on small screens. */
|
|
|
+static void osd_geom(void)
|
|
|
+{
|
|
|
+ int x, y;
|
|
|
+
|
|
|
+ osd_w = OSD_W;
|
|
|
+ osd_h = OSD_H;
|
|
|
+ x = ((int)fbw - (int)osd_w) / 2;
|
|
|
+ y = WM_BAR_H + ((int)fbh - WM_BAR_H - (int)osd_h) * 3 / 5;
|
|
|
+ if (x < 0)
|
|
|
+ x = 0;
|
|
|
+ if (x + (int)osd_w > (int)fbw)
|
|
|
+ x = (int)fbw - (int)osd_w;
|
|
|
+ if (y < WM_BAR_H)
|
|
|
+ y = WM_BAR_H;
|
|
|
+ if (y + (int)osd_h > (int)fbh)
|
|
|
+ y = (int)fbh - (int)osd_h;
|
|
|
+ osd_x = x;
|
|
|
+ osd_y = y;
|
|
|
+}
|
|
|
+
|
|
|
+/* A small sun: a filled circle plus four rays, all from 1-pixel fills. */
|
|
|
+static void osd_sun(int cx, int cy)
|
|
|
+{
|
|
|
+ static const unsigned char half[11] = { 2, 4, 5, 6, 6, 6, 6, 6, 5, 4, 2 };
|
|
|
+ int i;
|
|
|
+
|
|
|
+ for (i = -5; i <= 5; i++)
|
|
|
+ usurf_fill(&screen, cx - half[i + 5], cy + i,
|
|
|
+ half[i + 5] * 2 + 1, 1, 0xFFD250u);
|
|
|
+ usurf_fill(&screen, cx - 1, cy - 9, 2, 3, 0xFFD250u);
|
|
|
+ usurf_fill(&screen, cx - 1, cy + 7, 2, 3, 0xFFD250u);
|
|
|
+ usurf_fill(&screen, cx - 9, cy - 1, 3, 2, 0xFFD250u);
|
|
|
+ usurf_fill(&screen, cx + 7, cy - 1, 3, 2, 0xFFD250u);
|
|
|
+}
|
|
|
+
|
|
|
+static void osd_draw(void)
|
|
|
+{
|
|
|
+ char pct[8];
|
|
|
+ unsigned int n = 0;
|
|
|
+ unsigned int bar_x, bar_y, bar_w;
|
|
|
+ int x, y, tw;
|
|
|
+
|
|
|
+ osd_geom();
|
|
|
+ x = osd_x;
|
|
|
+ y = osd_y;
|
|
|
+ usurf_fill(&screen, x, y, osd_w, osd_h, 0x26263Au);
|
|
|
+ usurf_fill(&screen, x, y, osd_w, 1, 0x70709Au);
|
|
|
+ usurf_fill(&screen, x, y + (int)osd_h - 1, osd_w, 1, 0x70709Au);
|
|
|
+ usurf_fill(&screen, x, y + 1, 1, osd_h - 2, 0x70709Au);
|
|
|
+ usurf_fill(&screen, x + (int)osd_w - 1, y + 1, 1, osd_h - 2,
|
|
|
+ 0x70709Au);
|
|
|
+ osd_sun(x + 22, y + (int)osd_h / 2);
|
|
|
+
|
|
|
+ if (osd_level >= 100) {
|
|
|
+ pct[n++] = '1';
|
|
|
+ pct[n++] = '0';
|
|
|
+ pct[n++] = '0';
|
|
|
+ } else {
|
|
|
+ if (osd_level >= 10)
|
|
|
+ pct[n++] = (char)('0' + osd_level / 10);
|
|
|
+ pct[n++] = (char)('0' + osd_level % 10);
|
|
|
+ }
|
|
|
+ pct[n++] = '%';
|
|
|
+ pct[n] = '\0';
|
|
|
+
|
|
|
+ usurf_text(&screen, x + 42, y + 9, "Brightness", 0xE8E8F6u,
|
|
|
+ x, y, osd_w, osd_h);
|
|
|
+ tw = (int)usurf_text_width(&screen, pct);
|
|
|
+ usurf_text(&screen, x + (int)osd_w - 14 - tw, y + 9, pct,
|
|
|
+ 0xFFD250u, x, y, osd_w, osd_h);
|
|
|
+
|
|
|
+ bar_x = (unsigned int)(x + 42);
|
|
|
+ bar_y = (unsigned int)(y + 35);
|
|
|
+ bar_w = osd_w - 42 - 14;
|
|
|
+ usurf_fill(&screen, (int)bar_x, (int)bar_y, bar_w, 10, 0x44445Au);
|
|
|
+ usurf_fill(&screen, (int)bar_x, (int)bar_y,
|
|
|
+ (bar_w * (unsigned int)osd_level + 50) / 100, 10,
|
|
|
+ 0xFFD250u);
|
|
|
+}
|
|
|
+
|
|
|
+/* Put the power tooltip and the brightness OSD back on top after a render
|
|
|
+ * pass that may have overwritten them. */
|
|
|
+static void wm_overlays(struct wm_present_info *p)
|
|
|
+{
|
|
|
+ bar_tooltip_overlay(p);
|
|
|
+ if (osd_show) {
|
|
|
+ osd_draw();
|
|
|
+ add_rect(p, osd_x, osd_y, osd_w, osd_h);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/* A focused window is topmost, so the shadow contains exactly its pixels in
|
|
|
* the old rectangle. Move that block and repaint only the old part the new
|
|
|
* rectangle does not cover. When either rectangle is partly off-screen the
|
|
|
@@ -904,7 +1009,7 @@ static void move_window_pixels(struct uwin *u, int ox, int oy, int nx, int ny)
|
|
|
for (k = 0; k < np; k++)
|
|
|
add_rect(&present, pieces[k].x, pieces[k].y,
|
|
|
pieces[k].w, pieces[k].h);
|
|
|
- bar_tooltip_overlay(&present);
|
|
|
+ wm_overlays(&present);
|
|
|
u_wm_present(&present);
|
|
|
}
|
|
|
|
|
|
@@ -928,7 +1033,7 @@ static void redraw_geom(struct uwin *u, int ox, int oy,
|
|
|
for (i = 0; i < present.count; i++)
|
|
|
draw_rect(present.rect[i].x, present.rect[i].y,
|
|
|
present.rect[i].w, present.rect[i].h);
|
|
|
- bar_tooltip_overlay(&present);
|
|
|
+ wm_overlays(&present);
|
|
|
u_wm_present(&present);
|
|
|
}
|
|
|
}
|
|
|
@@ -1026,6 +1131,32 @@ static void do_update(struct wm_status *st)
|
|
|
int kexec_changed = (st->kexec_busy != bar_kexec_busy) ||
|
|
|
(st->kexec_busy && st->kexec_progress != bar_kexec_progress);
|
|
|
unsigned int msg_now = u_ticks_ms();
|
|
|
+ int osd_hide = 0, osd_repaint = 0;
|
|
|
+
|
|
|
+ /* The kernel bumps backlight_seq on every brightness key/command.
|
|
|
+ * Pop the OSD on a change and keep it up for OSD_MS after the last
|
|
|
+ * one. The first poll only records the current sequence, so a WM
|
|
|
+ * restart does not flash a stale bubble. */
|
|
|
+ if (st->backlight_present) {
|
|
|
+ if (!osd_seen_valid) {
|
|
|
+ osd_seen_valid = 1;
|
|
|
+ osd_seen_seq = st->backlight_seq;
|
|
|
+ } else if (st->backlight_seq != osd_seen_seq) {
|
|
|
+ osd_seen_seq = st->backlight_seq;
|
|
|
+ osd_level = (int)st->backlight_level;
|
|
|
+ osd_until = msg_now + OSD_MS;
|
|
|
+ osd_show = 1;
|
|
|
+ }
|
|
|
+ } else if (osd_show) {
|
|
|
+ osd_show = 0;
|
|
|
+ osd_hide = 1;
|
|
|
+ }
|
|
|
+ if (osd_show && (int)(msg_now - osd_until) >= 0) {
|
|
|
+ osd_show = 0;
|
|
|
+ osd_hide = 1;
|
|
|
+ }
|
|
|
+ if (osd_hide && osd_visible)
|
|
|
+ osd_repaint = 1;
|
|
|
|
|
|
/* Spawn the first terminal once the kernel says the storage scan is
|
|
|
* done, so a shell command can never race the mount table. */
|
|
|
@@ -1226,6 +1357,9 @@ static void do_update(struct wm_status *st)
|
|
|
draw_rect(0, 0, fbw, fbh);
|
|
|
draw_bar();
|
|
|
bar_tooltip_commit();
|
|
|
+ if (osd_show)
|
|
|
+ osd_draw();
|
|
|
+ osd_visible = osd_show;
|
|
|
present.count = 0;
|
|
|
add_rect(&present, 0, 0, fbw, fbh);
|
|
|
present.immediate = 0;
|
|
|
@@ -1243,6 +1377,12 @@ static void do_update(struct wm_status *st)
|
|
|
/* Partial cell/canvas updates and the bar clock. */
|
|
|
present.count = 0;
|
|
|
present.immediate = 0;
|
|
|
+ if (osd_repaint) {
|
|
|
+ add_rect(&present, osd_x, osd_y, osd_w, osd_h);
|
|
|
+ need = 1;
|
|
|
+ }
|
|
|
+ if (osd_show)
|
|
|
+ need = 1;
|
|
|
if (bar_dirty) {
|
|
|
need = 1;
|
|
|
add_rect(&present, 0, 0, fbw, WM_BAR_H);
|
|
|
@@ -1295,6 +1435,11 @@ static void do_update(struct wm_status *st)
|
|
|
} else {
|
|
|
bar_pwr_tip_on = 0;
|
|
|
}
|
|
|
+ if (osd_show) {
|
|
|
+ osd_draw();
|
|
|
+ add_rect(&present, osd_x, osd_y, osd_w, osd_h);
|
|
|
+ }
|
|
|
+ osd_visible = osd_show;
|
|
|
|
|
|
for (i = 0; i < WM_MAX_WINDOWS; i++) {
|
|
|
struct uwin *u = &wins[i];
|
|
|
@@ -1546,7 +1691,7 @@ static void handle_mouse(struct wm_status *st)
|
|
|
present.rect[i].y,
|
|
|
present.rect[i].w,
|
|
|
present.rect[i].h);
|
|
|
- bar_tooltip_overlay(&present);
|
|
|
+ wm_overlays(&present);
|
|
|
u_wm_present(&present);
|
|
|
}
|
|
|
}
|