]> git.lizzy.rs Git - plan9front.git/commitdiff
devmouse: refactor screen blanking logic
authorcinap_lenrek <cinap_lenrek@felloff.net>
Sat, 18 Mar 2017 15:58:27 +0000 (16:58 +0100)
committercinap_lenrek <cinap_lenrek@felloff.net>
Sat, 18 Mar 2017 15:58:27 +0000 (16:58 +0100)
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
sys/man/3/vga
sys/src/9/omap/screen.c
sys/src/9/omap/screen.h
sys/src/9/pc/devvga.c
sys/src/9/pc/screen.h
sys/src/9/port/devdraw.c
sys/src/9/port/devmouse.c

index 11bf6f3ee76b1c2130e1cf9e0a6ef7b1122a9bfa..078faff9a8e59a3b140efcf5c0a2772e128ded47 100644 (file)
@@ -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.
index d17858008a811046a99bbe3ad5996c7073d72ed6..e633de6d53f7590dbe14ccfb8e175c6d50df46c8 100644 (file)
@@ -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
index d4fe4a69620607aa9f6d03c6e844a5aa05122338..fe122e4eb3633861d328708987a239979a67d5d3 100644 (file)
@@ -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);
index 3c5b0dea4f99a445383308c6ac3e3e70002619d5..882428056a1d9171a8643ce2ebba2740d1b55118 100644 (file)
@@ -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 */
index e980011d8ab98bc6ea288bd8a572d66ae8db8413..2ed322cb44583b1eba76fa932cf27cc52a4e3c4e 100644 (file)
@@ -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)
index 46bf0f4cc90fcbf382d478b202af9d2f000eec40..646edd6e2a58da266aadaa2eb884d78355944acd 100644 (file)
@@ -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;
index b5053064c9fa42cc28153736844eed1bc2ae9805..0fe5f2e7afb516fe3fafc1eba79f6fd5e0bdb70e 100644 (file)
@@ -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;
-}
index c3010b01289ab4f2a204868b9692d38edc1cac0f..74db2587b7d146593cb4dd833181af771b18b856 100644 (file)
@@ -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();
        }
 }