ref: 1a2aefcf119e21345e41466d3d28bddcd6d6488a
parent: 08453422b1b8ac1daaba8000fb07d6551fb155b8
author: cinap_lenrek <[email protected]>
date: Sat Mar 18 12:58:27 EDT 2017
devmouse: refactor screen blanking logic devmouse controls the screen blanking timeout, so move the code there avoiding cross calls between modules. the only function that needs to be provided is blankscreen(), which gets called with drawlock locked. the blank timeout is set thru /dev/mousectl now, so kernels without devvga can set it. blanking now only happens while /dev/mouse is read. so this avoids accidentally blanking the screen on cpu servers that do not have a mouse to unblank it.
--- a/sys/man/3/mouse
+++ b/sys/man/3/mouse
@@ -151,6 +151,18 @@
clears the mouse
to its default state.
.TP
+.B blank
+Blank the screen.
+The screen also blanks after 30 minutes of inactivity.
+The screen can be unblanked by moving the mouse.
+.TP
+.BI blanktime " minutes"
+Set the timeout before the
+screen blanks; the default is 30 minutes.
+If
+.I minutes
+is zero, blanking is disabled.
+.TP
.B twitch
unblanks the screen and resets the idle timeout as if the
mouse was twitched.
--- a/sys/man/3/vga
+++ b/sys/man/3/vga
@@ -141,22 +141,6 @@
or
.BR 8 .
.TP
-.B blank
-Blank the screen.
-This consists of setting the hardware
-color map to all black as well as, on some controllers, setting the
-VGA hsync and vsync signals so as to turn off
-VESA DPMS-compliant monitors.
-The screen also blanks after 30 minutes of inactivity.
-The screen can be unblanked by moving the mouse.
-.TP
-.BI blanktime " minutes"
-Set the timeout before the
-screen blanks; the default is 30 minutes.
-If
-.I minutes
-is zero, blanking is disabled.
-.TP
.BI hwaccel " mode"
Depending on whether
.I mode
@@ -195,8 +179,7 @@
.BR off ,
enable or disable the use of DPMS blanking
(see
-.B blank
-above).
+.IR mouse (3)).
.TP
.BI linear " size align"
Use a linear screen aperture of size
--- a/sys/src/9/omap/screen.c
+++ b/sys/src/9/omap/screen.c
@@ -394,8 +394,6 @@
gscreen->width = Wid * (Depth / BI2BY) / BY2WD;
flushmemscreen(gscreen->r);
- blanktime = 3; /* minutes */
-
if (first) {
iprint("on: blue for 3 seconds...");
delay(3*1000);
--- a/sys/src/9/omap/screen.h
+++ b/sys/src/9/omap/screen.h
@@ -42,10 +42,8 @@
extern void deletescreenimage(void);
extern void resetscreenimage(void);
extern int drawhasclients(void);
-extern ulong blanktime;
extern void setscreenimageclipr(Rectangle);
extern void drawflush(void);
-extern int drawidletime(void);
extern QLock drawlock;
#define ishwimage(i) 0 /* for ../port/devdraw.c */
--- a/sys/src/9/pc/devvga.c
+++ b/sys/src/9/pc/devvga.c
@@ -33,8 +33,6 @@
enum {
CMactualsize,
- CMblank,
- CMblanktime,
CMdrawinit,
CMhwaccel,
CMhwblank,
@@ -45,7 +43,6 @@
CMsize,
CMtextmode,
CMtype,
- CMunblank,
CMsoftscreen,
CMpcidev,
};
@@ -52,8 +49,6 @@
static Cmdtab vgactlmsg[] = {
CMactualsize, "actualsize", 2,
- CMblank, "blank", 1,
- CMblanktime, "blanktime", 2,
CMdrawinit, "drawinit", 1,
CMhwaccel, "hwaccel", 2,
CMhwblank, "hwblank", 2,
@@ -64,7 +59,6 @@
CMsize, "size", 3,
CMtextmode, "textmode", 1,
CMtype, "type", 2,
- CMunblank, "unblank", 1,
CMsoftscreen, "softscreen", 2,
CMpcidev, "pcidev", 2,
};
@@ -212,8 +206,6 @@
physgscreenr.max.x, physgscreenr.max.y);
}
- len += snprint(p+len, READSTR-len, "blank time %lud idle %d state %s\n",
- blanktime, drawidletime(), scr->isblank ? "off" : "on");
len += snprint(p+len, READSTR-len, "hwaccel %s\n", hwaccel ? "on" : "off");
len += snprint(p+len, READSTR-len, "hwblank %s\n", hwblank ? "on" : "off");
len += snprint(p+len, READSTR-len, "panning %s\n", panning ? "on" : "off");
@@ -430,18 +422,6 @@
align = strtoul(cb->f[2], 0, 0);
if(screenaperture(size, align) < 0)
error("not enough free address space");
- return;
-
- case CMblank:
- drawblankscreen(1);
- return;
-
- case CMunblank:
- drawblankscreen(0);
- return;
-
- case CMblanktime:
- blanktime = strtoul(cb->f[1], 0, 0);
return;
case CMpanning:
--- a/sys/src/9/pc/screen.h
+++ b/sys/src/9/pc/screen.h
@@ -118,7 +118,6 @@
int (*scroll)(VGAscr*, Rectangle, Rectangle);
void (*blank)(VGAscr*, int);
ulong id; /* internal identifier for driver use */
- int isblank;
int overlayinit;
int softscreen;
};
@@ -130,9 +129,9 @@
};
/* mouse.c */
-extern void mousectl(Cmdbuf*);
-extern void mouseresize(void);
-extern void mouseredraw(void);
+extern void mousectl(Cmdbuf*);
+extern void mouseresize(void);
+extern void mouseredraw(void);
/* screen.c */
extern int hwaccel; /* use hw acceleration */
@@ -162,10 +161,8 @@
extern void deletescreenimage(void);
extern void resetscreenimage(void);
extern int drawhasclients(void);
-extern ulong blanktime;
extern void setscreenimageclipr(Rectangle);
extern void drawflush(void);
-extern int drawidletime(void);
extern QLock drawlock;
/* vga.c */
@@ -174,7 +171,6 @@
extern void vgalinearpci(VGAscr*);
extern void vgalinearaddr(VGAscr*, ulong, int);
-extern void drawblankscreen(int);
extern void vgablank(VGAscr*, int);
extern Lock vgascreenlock;
--- a/sys/src/9/port/devdraw.c
+++ b/sys/src/9/port/devdraw.c
@@ -50,8 +50,6 @@
typedef struct Refx Refx;
typedef struct DName DName;
-ulong blanktime = 30; /* in minutes; a half hour */
-
struct Draw
{
int clientid;
@@ -61,8 +59,6 @@
DName* name;
int vers;
int softscreen;
- int blanked; /* screen turned off */
- ulong blanktime; /* time of last operation */
};
struct Client
@@ -2146,37 +2142,4 @@
cr*0x01010101, cg*0x01010101, cb*0x01010101);
}
}
-}
-
-void
-drawblankscreen(int blank)
-{
- if(blank == sdraw.blanked)
- return;
- if(up != nil && islo() && candlock()){
- blankscreen(blank);
- sdraw.blanked = blank;
- dunlock();
- }
-}
-
-/*
- * record activity on screen, changing blanking as appropriate
- */
-void
-drawactive(int active)
-{
- if(active){
- drawblankscreen(0);
- sdraw.blanktime = MACHP(0)->ticks;
- }else{
- if(blanktime && sdraw.blanktime && TK2SEC(MACHP(0)->ticks - sdraw.blanktime)/60 >= blanktime)
- drawblankscreen(1);
- }
-}
-
-int
-drawidletime(void)
-{
- return TK2SEC(MACHP(0)->ticks - sdraw.blanktime)/60;
}
--- a/sys/src/9/port/devmouse.c
+++ b/sys/src/9/port/devmouse.c
@@ -53,6 +53,8 @@
CMbuttonmap,
CMscrollswap,
CMswap,
+ CMblank,
+ CMblanktime,
CMtwitch,
CMwildcard,
};
@@ -62,7 +64,9 @@
CMbuttonmap, "buttonmap", 0,
CMscrollswap, "scrollswap", 0,
CMswap, "swap", 1,
- CMtwitch, "twitch", 0,
+ CMblank, "blank", 1,
+ CMblanktime, "blanktime", 2,
+ CMtwitch, "twitch", 1,
CMwildcard, "*", 0,
};
@@ -71,6 +75,7 @@
Cursor curs;
void Cursortocursor(Cursor*);
+void mouseblankscreen(int);
int mousechanged(void*);
void mouseredraw(void);
@@ -96,6 +101,7 @@
static int mouseswap;
static int scrollswap;
static ulong mousetime;
+static ulong blanktime = 30; /* in minutes; a half hour */
extern Memimage* gscreen;
@@ -197,6 +203,7 @@
error(Einuse);
mouse.lastcounter = mouse.counter;
mouse.resize = 0;
+ mousetime = seconds();
/* wet floor */
case Qcursor:
incref(&mouse);
@@ -220,6 +227,7 @@
return;
case Qmouse:
mouse.open = 0;
+ mouseblankscreen(0);
/* wet floor */
case Qcursor:
if(decref(&mouse) != 0)
@@ -259,9 +267,14 @@
return n;
case Qmouse:
- while(mousechanged(0) == 0)
- sleep(&mouse.r, mousechanged, 0);
+ while(!mousechanged(nil)){
+ tsleep(&mouse.r, mousechanged, nil, 30*1000);
+ if(blanktime && !mousechanged(nil) &&
+ (seconds() - mousetime) >= blanktime*60)
+ mouseblankscreen(1);
+ }
mousetime = seconds();
+ mouseblankscreen(0);
ilock(&mouse);
if(mouse.ri != mouse.wi)
@@ -399,8 +412,16 @@
setbuttonmap(cb->f[1]);
break;
+ case CMblank:
+ mouseblankscreen(1);
+ break;
+
+ case CMblanktime:
+ blanktime = strtoul(cb->f[1], 0, 0);
+ /* wet floor */
case CMtwitch:
- drawactive(1);
+ mousetime = seconds();
+ mouseblankscreen(0);
break;
case CMwildcard:
@@ -501,7 +522,21 @@
qunlock(&drawlock);
}
+void
+mouseblankscreen(int blank)
+{
+ static int blanked;
+ if(blank == blanked)
+ return;
+ qlock(&drawlock);
+ if(blanked != blank){
+ blankscreen(blank);
+ blanked = blank;
+ }
+ qunlock(&drawlock);
+}
+
static int
shouldredraw(void*)
{
@@ -514,22 +549,13 @@
static void
mouseproc(void*)
{
- ulong counter;
-
- counter = ~0;
while(waserror())
;
for(;;){
- if(mouse.redraw){
- mouse.redraw = 0;
- cursoroff();
- cursoron();
- }
-
- drawactive(mouse.counter != counter);
- counter = mouse.counter;
-
- tsleep(&mouse.redrawr, shouldredraw, 0, 20*1000);
+ sleep(&mouse.redrawr, shouldredraw, nil);
+ mouse.redraw = 0;
+ cursoroff();
+ cursoron();
}
}