From 1a2aefcf119e21345e41466d3d28bddcd6d6488a Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sat, 18 Mar 2017 16:58:27 +0100 Subject: [PATCH] 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. --- sys/man/3/mouse | 12 ++++++++ sys/man/3/vga | 19 +------------ sys/src/9/omap/screen.c | 2 -- sys/src/9/omap/screen.h | 2 -- sys/src/9/pc/devvga.c | 20 ------------- sys/src/9/pc/screen.h | 10 ++----- sys/src/9/port/devdraw.c | 37 ------------------------ sys/src/9/port/devmouse.c | 60 ++++++++++++++++++++++++++++----------- 8 files changed, 59 insertions(+), 103 deletions(-) diff --git a/sys/man/3/mouse b/sys/man/3/mouse index 11bf6f3ee..078faff9a 100644 --- a/sys/man/3/mouse +++ b/sys/man/3/mouse @@ -151,6 +151,18 @@ unlike 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. diff --git a/sys/man/3/vga b/sys/man/3/vga index d17858008..e633de6d5 100644 --- a/sys/man/3/vga +++ b/sys/man/3/vga @@ -141,22 +141,6 @@ which must be either 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 @@ or .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 diff --git a/sys/src/9/omap/screen.c b/sys/src/9/omap/screen.c index d4fe4a696..fe122e4eb 100644 --- a/sys/src/9/omap/screen.c +++ b/sys/src/9/omap/screen.c @@ -394,8 +394,6 @@ screeninit(void) gscreen->width = Wid * (Depth / BI2BY) / BY2WD; flushmemscreen(gscreen->r); - blanktime = 3; /* minutes */ - if (first) { iprint("on: blue for 3 seconds..."); delay(3*1000); diff --git a/sys/src/9/omap/screen.h b/sys/src/9/omap/screen.h index 3c5b0dea4..882428056 100644 --- a/sys/src/9/omap/screen.h +++ b/sys/src/9/omap/screen.h @@ -42,10 +42,8 @@ extern void swcursorunhide(void); 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 */ diff --git a/sys/src/9/pc/devvga.c b/sys/src/9/pc/devvga.c index e980011d8..2ed322cb4 100644 --- a/sys/src/9/pc/devvga.c +++ b/sys/src/9/pc/devvga.c @@ -33,8 +33,6 @@ static Dirtab vgadir[] = { enum { CMactualsize, - CMblank, - CMblanktime, CMdrawinit, CMhwaccel, CMhwblank, @@ -45,15 +43,12 @@ enum { CMsize, CMtextmode, CMtype, - CMunblank, CMsoftscreen, CMpcidev, }; 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 @@ static Cmdtab vgactlmsg[] = { CMsize, "size", 3, CMtextmode, "textmode", 1, CMtype, "type", 2, - CMunblank, "unblank", 1, CMsoftscreen, "softscreen", 2, CMpcidev, "pcidev", 2, }; @@ -212,8 +206,6 @@ vgaread(Chan* c, void* a, long n, vlong off) 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"); @@ -432,18 +424,6 @@ vgactl(Cmdbuf *cb) 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: if(strcmp(cb->f[1], "on") == 0){ if(scr == nil || scr->cur == nil) diff --git a/sys/src/9/pc/screen.h b/sys/src/9/pc/screen.h index 46bf0f4cc..646edd6e2 100644 --- a/sys/src/9/pc/screen.h +++ b/sys/src/9/pc/screen.h @@ -118,7 +118,6 @@ struct VGAscr { 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 @@ enum { }; /* 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 swcursorunhide(void); 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 vgaimageinit(ulong); extern void vgalinearpci(VGAscr*); extern void vgalinearaddr(VGAscr*, ulong, int); -extern void drawblankscreen(int); extern void vgablank(VGAscr*, int); extern Lock vgascreenlock; diff --git a/sys/src/9/port/devdraw.c b/sys/src/9/port/devdraw.c index b5053064c..0fe5f2e7a 100644 --- a/sys/src/9/port/devdraw.c +++ b/sys/src/9/port/devdraw.c @@ -50,8 +50,6 @@ typedef struct Refresh Refresh; typedef struct Refx Refx; typedef struct DName DName; -ulong blanktime = 30; /* in minutes; a half hour */ - struct Draw { int clientid; @@ -61,8 +59,6 @@ struct Draw DName* name; int vers; int softscreen; - int blanked; /* screen turned off */ - ulong blanktime; /* time of last operation */ }; 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; -} diff --git a/sys/src/9/port/devmouse.c b/sys/src/9/port/devmouse.c index c3010b012..74db2587b 100644 --- a/sys/src/9/port/devmouse.c +++ b/sys/src/9/port/devmouse.c @@ -53,6 +53,8 @@ enum CMbuttonmap, CMscrollswap, CMswap, + CMblank, + CMblanktime, CMtwitch, CMwildcard, }; @@ -62,7 +64,9 @@ static Cmdtab mousectlmsg[] = 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 @@ Cursorinfo cursor; Cursor curs; void Cursortocursor(Cursor*); +void mouseblankscreen(int); int mousechanged(void*); void mouseredraw(void); @@ -96,6 +101,7 @@ static uchar buttonmap[8] = { 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 @@ mouseopen(Chan *c, int omode) error(Einuse); mouse.lastcounter = mouse.counter; mouse.resize = 0; + mousetime = seconds(); /* wet floor */ case Qcursor: incref(&mouse); @@ -220,6 +227,7 @@ mouseclose(Chan *c) return; case Qmouse: mouse.open = 0; + mouseblankscreen(0); /* wet floor */ case Qcursor: if(decref(&mouse) != 0) @@ -259,9 +267,14 @@ mouseread(Chan *c, void *va, long n, vlong off) 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 @@ mousewrite(Chan *c, void *va, long n, vlong) 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,6 +522,20 @@ Cursortocursor(Cursor *c) 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 @@ shouldredraw(void*) 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(); } }