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.
This commit is contained in:
cinap_lenrek 2017-03-18 16:58:27 +01:00
parent 08453422b1
commit 1a2aefcf11
8 changed files with 59 additions and 103 deletions

View file

@ -151,6 +151,18 @@ unlike
clears the mouse clears the mouse
to its default state. to its default state.
.TP .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 .B twitch
unblanks the screen and resets the idle timeout as if the unblanks the screen and resets the idle timeout as if the
mouse was twitched. mouse was twitched.

View file

@ -141,22 +141,6 @@ which must be either
or or
.BR 8 . .BR 8 .
.TP .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" .BI hwaccel " mode"
Depending on whether Depending on whether
.I mode .I mode
@ -195,8 +179,7 @@ or
.BR off , .BR off ,
enable or disable the use of DPMS blanking enable or disable the use of DPMS blanking
(see (see
.B blank .IR mouse (3)).
above).
.TP .TP
.BI linear " size align" .BI linear " size align"
Use a linear screen aperture of size Use a linear screen aperture of size

View file

@ -394,8 +394,6 @@ screeninit(void)
gscreen->width = Wid * (Depth / BI2BY) / BY2WD; gscreen->width = Wid * (Depth / BI2BY) / BY2WD;
flushmemscreen(gscreen->r); flushmemscreen(gscreen->r);
blanktime = 3; /* minutes */
if (first) { if (first) {
iprint("on: blue for 3 seconds..."); iprint("on: blue for 3 seconds...");
delay(3*1000); delay(3*1000);

View file

@ -42,10 +42,8 @@ extern void swcursorunhide(void);
extern void deletescreenimage(void); extern void deletescreenimage(void);
extern void resetscreenimage(void); extern void resetscreenimage(void);
extern int drawhasclients(void); extern int drawhasclients(void);
extern ulong blanktime;
extern void setscreenimageclipr(Rectangle); extern void setscreenimageclipr(Rectangle);
extern void drawflush(void); extern void drawflush(void);
extern int drawidletime(void);
extern QLock drawlock; extern QLock drawlock;
#define ishwimage(i) 0 /* for ../port/devdraw.c */ #define ishwimage(i) 0 /* for ../port/devdraw.c */

View file

@ -33,8 +33,6 @@ static Dirtab vgadir[] = {
enum { enum {
CMactualsize, CMactualsize,
CMblank,
CMblanktime,
CMdrawinit, CMdrawinit,
CMhwaccel, CMhwaccel,
CMhwblank, CMhwblank,
@ -45,15 +43,12 @@ enum {
CMsize, CMsize,
CMtextmode, CMtextmode,
CMtype, CMtype,
CMunblank,
CMsoftscreen, CMsoftscreen,
CMpcidev, CMpcidev,
}; };
static Cmdtab vgactlmsg[] = { static Cmdtab vgactlmsg[] = {
CMactualsize, "actualsize", 2, CMactualsize, "actualsize", 2,
CMblank, "blank", 1,
CMblanktime, "blanktime", 2,
CMdrawinit, "drawinit", 1, CMdrawinit, "drawinit", 1,
CMhwaccel, "hwaccel", 2, CMhwaccel, "hwaccel", 2,
CMhwblank, "hwblank", 2, CMhwblank, "hwblank", 2,
@ -64,7 +59,6 @@ static Cmdtab vgactlmsg[] = {
CMsize, "size", 3, CMsize, "size", 3,
CMtextmode, "textmode", 1, CMtextmode, "textmode", 1,
CMtype, "type", 2, CMtype, "type", 2,
CMunblank, "unblank", 1,
CMsoftscreen, "softscreen", 2, CMsoftscreen, "softscreen", 2,
CMpcidev, "pcidev", 2, CMpcidev, "pcidev", 2,
}; };
@ -212,8 +206,6 @@ vgaread(Chan* c, void* a, long n, vlong off)
physgscreenr.max.x, physgscreenr.max.y); 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, "hwaccel %s\n", hwaccel ? "on" : "off");
len += snprint(p+len, READSTR-len, "hwblank %s\n", hwblank ? "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"); len += snprint(p+len, READSTR-len, "panning %s\n", panning ? "on" : "off");
@ -432,18 +424,6 @@ vgactl(Cmdbuf *cb)
error("not enough free address space"); error("not enough free address space");
return; return;
case CMblank:
drawblankscreen(1);
return;
case CMunblank:
drawblankscreen(0);
return;
case CMblanktime:
blanktime = strtoul(cb->f[1], 0, 0);
return;
case CMpanning: case CMpanning:
if(strcmp(cb->f[1], "on") == 0){ if(strcmp(cb->f[1], "on") == 0){
if(scr == nil || scr->cur == nil) if(scr == nil || scr->cur == nil)

View file

@ -118,7 +118,6 @@ struct VGAscr {
int (*scroll)(VGAscr*, Rectangle, Rectangle); int (*scroll)(VGAscr*, Rectangle, Rectangle);
void (*blank)(VGAscr*, int); void (*blank)(VGAscr*, int);
ulong id; /* internal identifier for driver use */ ulong id; /* internal identifier for driver use */
int isblank;
int overlayinit; int overlayinit;
int softscreen; int softscreen;
}; };
@ -130,9 +129,9 @@ enum {
}; };
/* mouse.c */ /* mouse.c */
extern void mousectl(Cmdbuf*); extern void mousectl(Cmdbuf*);
extern void mouseresize(void); extern void mouseresize(void);
extern void mouseredraw(void); extern void mouseredraw(void);
/* screen.c */ /* screen.c */
extern int hwaccel; /* use hw acceleration */ extern int hwaccel; /* use hw acceleration */
@ -162,10 +161,8 @@ extern void swcursorunhide(void);
extern void deletescreenimage(void); extern void deletescreenimage(void);
extern void resetscreenimage(void); extern void resetscreenimage(void);
extern int drawhasclients(void); extern int drawhasclients(void);
extern ulong blanktime;
extern void setscreenimageclipr(Rectangle); extern void setscreenimageclipr(Rectangle);
extern void drawflush(void); extern void drawflush(void);
extern int drawidletime(void);
extern QLock drawlock; extern QLock drawlock;
/* vga.c */ /* vga.c */
@ -174,7 +171,6 @@ extern void vgaimageinit(ulong);
extern void vgalinearpci(VGAscr*); extern void vgalinearpci(VGAscr*);
extern void vgalinearaddr(VGAscr*, ulong, int); extern void vgalinearaddr(VGAscr*, ulong, int);
extern void drawblankscreen(int);
extern void vgablank(VGAscr*, int); extern void vgablank(VGAscr*, int);
extern Lock vgascreenlock; extern Lock vgascreenlock;

View file

@ -50,8 +50,6 @@ typedef struct Refresh Refresh;
typedef struct Refx Refx; typedef struct Refx Refx;
typedef struct DName DName; typedef struct DName DName;
ulong blanktime = 30; /* in minutes; a half hour */
struct Draw struct Draw
{ {
int clientid; int clientid;
@ -61,8 +59,6 @@ struct Draw
DName* name; DName* name;
int vers; int vers;
int softscreen; int softscreen;
int blanked; /* screen turned off */
ulong blanktime; /* time of last operation */
}; };
struct Client struct Client
@ -2147,36 +2143,3 @@ drawcmap(void)
} }
} }
} }
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;
}

View file

@ -53,6 +53,8 @@ enum
CMbuttonmap, CMbuttonmap,
CMscrollswap, CMscrollswap,
CMswap, CMswap,
CMblank,
CMblanktime,
CMtwitch, CMtwitch,
CMwildcard, CMwildcard,
}; };
@ -62,7 +64,9 @@ static Cmdtab mousectlmsg[] =
CMbuttonmap, "buttonmap", 0, CMbuttonmap, "buttonmap", 0,
CMscrollswap, "scrollswap", 0, CMscrollswap, "scrollswap", 0,
CMswap, "swap", 1, CMswap, "swap", 1,
CMtwitch, "twitch", 0, CMblank, "blank", 1,
CMblanktime, "blanktime", 2,
CMtwitch, "twitch", 1,
CMwildcard, "*", 0, CMwildcard, "*", 0,
}; };
@ -71,6 +75,7 @@ Cursorinfo cursor;
Cursor curs; Cursor curs;
void Cursortocursor(Cursor*); void Cursortocursor(Cursor*);
void mouseblankscreen(int);
int mousechanged(void*); int mousechanged(void*);
void mouseredraw(void); void mouseredraw(void);
@ -96,6 +101,7 @@ static uchar buttonmap[8] = {
static int mouseswap; static int mouseswap;
static int scrollswap; static int scrollswap;
static ulong mousetime; static ulong mousetime;
static ulong blanktime = 30; /* in minutes; a half hour */
extern Memimage* gscreen; extern Memimage* gscreen;
@ -197,6 +203,7 @@ mouseopen(Chan *c, int omode)
error(Einuse); error(Einuse);
mouse.lastcounter = mouse.counter; mouse.lastcounter = mouse.counter;
mouse.resize = 0; mouse.resize = 0;
mousetime = seconds();
/* wet floor */ /* wet floor */
case Qcursor: case Qcursor:
incref(&mouse); incref(&mouse);
@ -220,6 +227,7 @@ mouseclose(Chan *c)
return; return;
case Qmouse: case Qmouse:
mouse.open = 0; mouse.open = 0;
mouseblankscreen(0);
/* wet floor */ /* wet floor */
case Qcursor: case Qcursor:
if(decref(&mouse) != 0) if(decref(&mouse) != 0)
@ -259,9 +267,14 @@ mouseread(Chan *c, void *va, long n, vlong off)
return n; return n;
case Qmouse: case Qmouse:
while(mousechanged(0) == 0) while(!mousechanged(nil)){
sleep(&mouse.r, mousechanged, 0); tsleep(&mouse.r, mousechanged, nil, 30*1000);
if(blanktime && !mousechanged(nil) &&
(seconds() - mousetime) >= blanktime*60)
mouseblankscreen(1);
}
mousetime = seconds(); mousetime = seconds();
mouseblankscreen(0);
ilock(&mouse); ilock(&mouse);
if(mouse.ri != mouse.wi) if(mouse.ri != mouse.wi)
@ -399,8 +412,16 @@ mousewrite(Chan *c, void *va, long n, vlong)
setbuttonmap(cb->f[1]); setbuttonmap(cb->f[1]);
break; break;
case CMblank:
mouseblankscreen(1);
break;
case CMblanktime:
blanktime = strtoul(cb->f[1], 0, 0);
/* wet floor */
case CMtwitch: case CMtwitch:
drawactive(1); mousetime = seconds();
mouseblankscreen(0);
break; break;
case CMwildcard: case CMwildcard:
@ -501,6 +522,20 @@ Cursortocursor(Cursor *c)
qunlock(&drawlock); 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 static int
shouldredraw(void*) shouldredraw(void*)
@ -514,22 +549,13 @@ shouldredraw(void*)
static void static void
mouseproc(void*) mouseproc(void*)
{ {
ulong counter;
counter = ~0;
while(waserror()) while(waserror())
; ;
for(;;){ for(;;){
if(mouse.redraw){ sleep(&mouse.redrawr, shouldredraw, nil);
mouse.redraw = 0; mouse.redraw = 0;
cursoroff(); cursoroff();
cursoron(); cursoron();
}
drawactive(mouse.counter != counter);
counter = mouse.counter;
tsleep(&mouse.redrawr, shouldredraw, 0, 20*1000);
} }
} }