fbcon: user-defined cursor blink interval

Started by Scot Doyle on Jan 26, 2015 · 6 messages from 3 authors · Last reply Jan 30, 2015

Series

2 patches, 2 files

+83 −2

Subsystems (3)

Maintainers (3)

STALE4304d SUPERSEDED

Status: Superseded by v6 (posted 2015-01-30). [go to v6]

Revision v4 (5 revisions archived).

Revisions (5)
  1. rfc
  2. v3 [diff against previous]
  3. v4 current [diff against previous]
  4. v5 [diff against previous]
  5. v6 [diff against previous]

open the first message on its own page

  1. [PATCH v4 1/2] fbcon: store cursor blink interval in fbcon_ops
    Revisions and related patches
    Revisions (5)
    1. rfc
    2. v3 [diff against previous]
    3. v4 current [diff against previous]
    4. v5 [diff against previous]
    5. v6 [diff against previous]
  2. [PATCH v4 2/2] fbcon: expose cursor blink interval via sysfs
    Revisions and related patches
    Revisions (5)
    1. rfc
    2. v3 [diff against previous]
    3. v4 current [diff against previous]
    4. v5 [diff against previous]
    5. v6 [diff against previous]
Message details and related content
Since users prefer different fbcon cursor blink intervals, allow the
interval to be set via sysfs. The current interval of 200 milliseconds
is retained as the default. Tested with intelfb.

v2:  Use kstrtos16() instead of kstrtoul() and min_t() as suggested by
     Geert Uytterhoeven
v3:  Add error messages as suggested by Tomi Valkeinen
v4:  Add rationale into patch descriptions as suggested by
     Richard Weinberger

Scot Doyle (2):
  fbcon: store cursor blink interval in fbcon_ops
  fbcon: expose cursor blink interval via sysfs

 drivers/video/console/fbcon.c | 84 +++++++++++++++++++++++++++++++++++++++++--
 drivers/video/console/fbcon.h |  1 +
 2 files changed, 83 insertions(+), 2 deletions(-)

-- 
2.1.4

[PATCH v4 1/2] fbcon: store cursor blink interval in fbcon_ops

Message details and related content
fbcon toggles cursor display state every 200 milliseconds when blinking.
Since users prefer different toggle intervals, prepare to expose the
interval via sysfs by moving it to fbdev_ops and setting the default
to 200 milliseconds.

Signed-off-by: Scot Doyle <redacted>
---
 drivers/video/console/fbcon.c | 5 +++--
 drivers/video/console/fbcon.h | 1 +
 2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
index ea43724..7a2030b 100644
--- a/drivers/video/console/fbcon.c
+++ b/drivers/video/console/fbcon.c
@@ -405,7 +405,7 @@ static void cursor_timer_handler(unsigned long dev_addr)
 	struct fbcon_ops *ops = info->fbcon_par;
 
 	queue_work(system_power_efficient_wq, &info->queue);
-	mod_timer(&ops->cursor_timer, jiffies + HZ/5);
+	mod_timer(&ops->cursor_timer, jiffies + ops->blink_jiffies);
 }
 
 static void fbcon_add_cursor_timer(struct fb_info *info)
@@ -420,7 +420,7 @@ static void fbcon_add_cursor_timer(struct fb_info *info)
 
 		init_timer(&ops->cursor_timer);
 		ops->cursor_timer.function = cursor_timer_handler;
-		ops->cursor_timer.expires = jiffies + HZ / 5;
+		ops->cursor_timer.expires = jiffies + ops->blink_jiffies;
 		ops->cursor_timer.data = (unsigned long ) info;
 		add_timer(&ops->cursor_timer);
 		ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
@@ -959,6 +959,7 @@ static const char *fbcon_startup(void)
 	ops->currcon = -1;
 	ops->graphics = 1;
 	ops->cur_rotate = -1;
+	ops->blink_jiffies = msecs_to_jiffies(200);
 	info->fbcon_par = ops;
 	p->con_rotate = initial_rotation;
 	set_blitting_type(vc, info);
diff --git a/drivers/video/console/fbcon.h b/drivers/video/console/fbcon.h
index 6bd2e0c..642c4e7 100644
--- a/drivers/video/console/fbcon.h
+++ b/drivers/video/console/fbcon.h
@@ -70,6 +70,7 @@ struct fbcon_ops {
 	struct fb_cursor cursor_state;
 	struct display *p;
         int    currcon;	                /* Current VC. */
+	int    blink_jiffies;
 	int    cursor_flash;
 	int    cursor_reset;
 	int    blank_state;
-- 
2.1.4

[PATCH v4 2/2] fbcon: expose cursor blink interval via sysfs

Message details and related content
fbcon toggles cursor display state every 200 milliseconds when blinking.
Since users prefer different toggle intervals, expose the interval via
/sys/class/graphics/fbcon/cursor_blink_ms so that it may be customized.

Values written to the interface set the approximate time interval in
milliseconds between cursor toggles, from 1 to 32767. Since the interval
is stored internally as a number of jiffies, the millisecond value read
from the interface may not exactly match the entered value.

An outstanding blink timer is reset after a new value is entered.

If the cursor blink is disabled, either via the 'cursor_blink' boolean
setting or some other mechanism, the 'cursor_blink_ms' setting may still
be modified. The new value will be used if the blink is reactivated.

Signed-off-by: Scot Doyle <redacted>
---
 drivers/video/console/fbcon.c | 79 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)
diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
index 7a2030b..19620d2 100644
--- a/drivers/video/console/fbcon.c
+++ b/drivers/video/console/fbcon.c
@@ -3495,11 +3495,90 @@ err:
 	return count;
 }
 
+static ssize_t show_cursor_blink_ms(struct device *device,
+				    struct device_attribute *attr, char *buf)
+{
+	struct fb_info *info;
+	struct fbcon_ops *ops;
+	int idx, ms = -1;
+
+	if (fbcon_has_exited) {
+		pr_err("%s: framebuffer console exited", __func__);
+		return 0;
+	}
+
+	console_lock();
+	idx = con2fb_map[fg_console];
+
+	if (idx = -1 || registered_fb[idx] = NULL) {
+		pr_err("%s: no console to framebuffer mapping", __func__);
+		goto err;
+	}
+
+	info = registered_fb[idx];
+
+	if ((ops = info->fbcon_par) = NULL) {
+		pr_err("%s: framebuffer has no device info", __func__);
+		goto err;
+	}
+
+	ms = jiffies_to_msecs(ops->blink_jiffies);
+
+err:
+	console_unlock();
+	return snprintf(buf, PAGE_SIZE, "%d\n", ms);
+}
+
+static ssize_t store_cursor_blink_ms(struct device *device,
+				     struct device_attribute *attr,
+				     const char *buf, size_t count)
+{
+	struct fb_info *info;
+	struct fbcon_ops *ops;
+	int idx;
+	short ms;
+
+	if (fbcon_has_exited) {
+		pr_err("%s: framebuffer console exited", __func__);
+		return count;
+	}
+
+	console_lock();
+	idx = con2fb_map[fg_console];
+
+	if (idx = -1 || registered_fb[idx] = NULL) {
+		pr_err("%s: no console to framebuffer mapping", __func__);
+		goto err;
+	}
+
+	info = registered_fb[idx];
+
+	if ((ops = info->fbcon_par) = NULL) {
+		pr_err("%s: framebuffer has no device info", __func__);
+		goto err;
+	}
+
+	if (!kstrtos16(buf, 0, &ms)) {
+		ops->blink_jiffies = max_t(int, msecs_to_jiffies(ms), 1);
+		if (info->queue.func = fb_flashcursor &&
+		    ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
+			fbcon_del_cursor_timer(info);
+			fbcon_add_cursor_timer(info);
+		}
+	}
+
+err:
+	console_unlock();
+	return count;
+}
+
 static struct device_attribute device_attrs[] = {
 	__ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
 	__ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
 	__ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
 	       store_cursor_blink),
+	__ATTR(cursor_blink_ms, S_IRUGO|S_IWUSR, show_cursor_blink_ms,
+	       store_cursor_blink_ms),
 };
 
 static int fbcon_init_device(void)
-- 
2.1.4
Message details and related content
Am 27.01.2015 um 00:09 schrieb Scot Doyle:
Since users prefer different fbcon cursor blink intervals, allow the
interval to be set via sysfs. The current interval of 200 milliseconds
is retained as the default. Tested with intelfb.

v2:  Use kstrtos16() instead of kstrtoul() and min_t() as suggested by
     Geert Uytterhoeven
v3:  Add error messages as suggested by Tomi Valkeinen
v4:  Add rationale into patch descriptions as suggested by
     Richard Weinberger
Hehe, no need to resend immediately a v4, I'm just curios about the use case. :)
Why do users want a different blink interval? What is the use case?
And what are these users? Most people use a fbcon only for a few moments
to fix/restart X11.

Thanks,
//richard
Message details and related content
On Tue, 27 Jan 2015, Richard Weinberger wrote:
Am 27.01.2015 um 00:09 schrieb Scot Doyle:
quoted
Since users prefer different fbcon cursor blink intervals, allow the
interval to be set via sysfs. The current interval of 200 milliseconds
is retained as the default. Tested with intelfb.

v2:  Use kstrtos16() instead of kstrtoul() and min_t() as suggested by
     Geert Uytterhoeven
v3:  Add error messages as suggested by Tomi Valkeinen
v4:  Add rationale into patch descriptions as suggested by
     Richard Weinberger
Hehe, no need to resend immediately a v4, I'm just curios about the use case. :)
Why do users want a different blink interval? What is the use case?
And what are these users? Most people use a fbcon only for a few moments
to fix/restart X11.

Thanks,
//richard
Ah, I see! With multiple ncurses windows, some of which contain reversed 
characters, a blinking underscore is helpful for locating the cursor.
But, the 200 millisecond interval can be distracting. Another example is 
http://unix.stackexchange.com/questions/55423/how-to-change-cursor-shape-color-and-blinkrate-of-linux-console
Message details and related content
On 27/01/15 01:09, Scot Doyle wrote:
Since users prefer different fbcon cursor blink intervals, allow the
interval to be set via sysfs. The current interval of 200 milliseconds
is retained as the default. Tested with intelfb.

v2:  Use kstrtos16() instead of kstrtoul() and min_t() as suggested by
     Geert Uytterhoeven
v3:  Add error messages as suggested by Tomi Valkeinen
When I said "return an error" I did not mean "print an error message".
You should return an error code from the show and store functions when
something went wrong.

 Tomi


Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help