~ubuntu-branches/ubuntu/trusty/grub2/trusty-updates

« back to all changes in this revision

Viewing changes to commands/keystatus.c

Tags: upstream-1.99~20101122
ImportĀ upstreamĀ versionĀ 1.99~20101122

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* keystatus.c - Command to check key modifier status.  */
2
 
/*
3
 
 *  GRUB  --  GRand Unified Bootloader
4
 
 *  Copyright (C) 2009  Free Software Foundation, Inc.
5
 
 *
6
 
 *  GRUB is free software: you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation, either version 3 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  GRUB is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
18
 
 */
19
 
 
20
 
#include <grub/dl.h>
21
 
#include <grub/misc.h>
22
 
#include <grub/extcmd.h>
23
 
#include <grub/term.h>
24
 
#include <grub/i18n.h>
25
 
 
26
 
static const struct grub_arg_option options[] =
27
 
  {
28
 
    {"shift", 's', 0, N_("Check Shift key."), 0, 0},
29
 
    {"ctrl", 'c', 0, N_("Check Control key."), 0, 0},
30
 
    {"alt", 'a', 0, N_("Check Alt key."), 0, 0},
31
 
    {0, 0, 0, 0, 0, 0}
32
 
  };
33
 
 
34
 
#define grub_cur_term_input     grub_term_get_current_input ()
35
 
 
36
 
static grub_err_t
37
 
grub_cmd_keystatus (grub_extcmd_t cmd,
38
 
                    int argc __attribute__ ((unused)),
39
 
                    char **args __attribute__ ((unused)))
40
 
{
41
 
  struct grub_arg_list *state = cmd->state;
42
 
  int expect_mods = 0;
43
 
  int mods;
44
 
 
45
 
  if (state[0].set)
46
 
    expect_mods |= GRUB_TERM_STATUS_SHIFT;
47
 
  if (state[1].set)
48
 
    expect_mods |= GRUB_TERM_STATUS_CTRL;
49
 
  if (state[2].set)
50
 
    expect_mods |= GRUB_TERM_STATUS_ALT;
51
 
 
52
 
  grub_dprintf ("keystatus", "expect_mods: %d\n", expect_mods);
53
 
 
54
 
  /* Without arguments, just check whether getkeystatus is supported at
55
 
     all.  */
56
 
  if (expect_mods == 0)
57
 
    {
58
 
      grub_term_input_t term;
59
 
      int nterms = 0;
60
 
 
61
 
      FOR_ACTIVE_TERM_INPUTS (term)
62
 
        if (!term->getkeystatus)
63
 
          return grub_error (GRUB_ERR_TEST_FAILURE, "false");
64
 
        else
65
 
          nterms++;
66
 
      if (!nterms)
67
 
        return grub_error (GRUB_ERR_TEST_FAILURE, "false");
68
 
      return 0;
69
 
    }
70
 
 
71
 
  mods = grub_getkeystatus ();
72
 
  grub_dprintf ("keystatus", "mods: %d\n", mods);
73
 
  if (mods >= 0 && (mods & expect_mods) != 0)
74
 
    return 0;
75
 
  else
76
 
    return grub_error (GRUB_ERR_TEST_FAILURE, "false");
77
 
}
78
 
 
79
 
static grub_extcmd_t cmd;
80
 
 
81
 
GRUB_MOD_INIT(keystatus)
82
 
{
83
 
  cmd = grub_register_extcmd ("keystatus", grub_cmd_keystatus,
84
 
                              GRUB_COMMAND_FLAG_BOTH,
85
 
                              N_("[--shift] [--ctrl] [--alt]"),
86
 
                              N_("Check key modifier status."),
87
 
                              options);
88
 
}
89
 
 
90
 
GRUB_MOD_FINI(keystatus)
91
 
{
92
 
  grub_unregister_extcmd (cmd);
93
 
}