Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1MfiYW-0001kG-4P for mharc-grub-devel@gnu.org; Mon, 24 Aug 2009 19:02:28 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MfiYT-0001gl-SP for grub-devel@gnu.org; Mon, 24 Aug 2009 19:02:25 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MfiYO-0001X9-SJ for grub-devel@gnu.org; Mon, 24 Aug 2009 19:02:24 -0400 Received: from [199.232.76.173] (port=43951 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MfiYO-0001Wz-Ii for grub-devel@gnu.org; Mon, 24 Aug 2009 19:02:20 -0400 Received: from smarthost01.mail.zen.net.uk ([212.23.3.140]:40241) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MfiYM-0003fz-Tq for grub-devel@gnu.org; Mon, 24 Aug 2009 19:02:19 -0400 Received: from [82.69.40.219] (helo=riva.pelham.vpn.ucam.org) by smarthost01.mail.zen.net.uk with esmtp (Exim 4.63) (envelope-from ) id 1MfiYM-0006G7-2M for grub-devel@gnu.org; Mon, 24 Aug 2009 23:02:18 +0000 Received: from cjwatson by riva.pelham.vpn.ucam.org with local (Exim 3.36 #1 (Debian)) for grub-devel@gnu.org id 1MfiYL-00028n-00; Tue, 25 Aug 2009 00:02:17 +0100 Date: Tue, 25 Aug 2009 00:02:17 +0100 From: Colin Watson To: The development of GRUB 2 Message-ID: <20090824230217.GM11691@riva.ucam.org> Mail-Followup-To: The development of GRUB 2 References: <20090812153520.GA11691@riva.ucam.org> <20090812221431.GD11691@riva.ucam.org> <20090824092406.GE11691@riva.ucam.org> <20090824122352.GB18956@thorin> <20090824220419.GA31998@riva.ucam.org> <20090824224120.GC25093@thorin> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20090824224120.GC25093@thorin> User-Agent: Mutt/1.5.18 (2008-05-17) X-Originating-Smarthost01-IP: [82.69.40.219] X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: Re: [PATCH] Detect key modifier status in 'sleep --interruptible' X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Aug 2009 23:02:26 -0000 On Tue, Aug 25, 2009 at 12:41:20AM +0200, Robert Millan wrote: > On Mon, Aug 24, 2009 at 11:04:19PM +0100, Colin Watson wrote: > > +/* See http://heim.ifi.uio.no/~stanisls/helppc/bios_data_area.html for a > > + description of the BIOS Data Area layout. */ > > +struct grub_machine_bios_data_area > > +{ > > + grub_uint8_t unused1[0x17]; > > + grub_uint8_t keyboard_flag_lower; /* 0x17 */ > > + grub_uint8_t keyboard_flag_upper; /* 0x17 */ > > + grub_uint8_t unused2[0xf0 - 0x19]; > > +}; > > Why split the keyboard field in upper/lower? We have working 16-bit types :-) We only need the lower one and counterintuitively (for a little-endian system) I seemed to have to look at bits 8-11 of the 16-bit type rather than bits 0-3. Life was too short to worry about what was wrong and I decided to only fetch the byte we needed. I suppose we could delete the declaration of keyboard_flag_upper. > > +static int > > +grub_check_keyboard (void) > > +{ > > + int mods = grub_getkeystatus (); > > + if (mods >= 0 && (mods & GRUB_TERM_STATUS_SHIFT) != 0) > > + return 1; > > + > > + if (grub_checkkey () >= 0 && > > + GRUB_TERM_ASCII_CHAR (grub_getkey ()) == GRUB_TERM_ESC) > > + return 1; > > + > > + return 0; > > +} > > I'm not sure if hardcoding ESC and SHIFT here makes this a bit too ad-hoc. Maybe not much more than the previous hardcoding of Escape alone? > IIRC you had a more generic approach in mind? We talked on IRC about adding a magic "keystatus" environment variable that user code could inspect. I'm not sure whether this will actually make things any simpler at the moment, though - I don't think there's a way to do bitwise operations in the shell-like scripting interface (you can use 'test' to test greater/less than, but nothing like "&"). Would three magic variables, keystatus_shift, keystatus_ctrl, and keystatus_alt, be too inelegant? I'm open to other ideas. 'sleep --interruptible 0' is not an entirely natural way to express what I'm looking for, so I'm not particularly attached to it. 'if sleep --interruptible 0; then set timeout=0; fi' is suboptimal because it means that if either (a) core.img is too old to have getkeystatus support or (b) the current console driver does not support getkeystatus then the menu will be skipped without a way to access it at run-time. I'd much rather have something that allowed zero-timeout-with-Shift-to-access-menu if and only if we have a new enough core.img and the console driver has getkeystatus support, and otherwise degraded to something else sensible. -- Colin Watson [cjwatson@ubuntu.com]