~israeldahl/jwm-settings-manager/trunk

« back to all changes in this revision

Viewing changes to src/uikeyboard.cpp

  • Committer: Israel Dahl
  • Date: 2014-07-06 02:48:28 UTC
  • Revision ID: israeldahl@gmail.com-20140706024828-1bt17riyy2ep06bt
actually added the themes, buttons, etc...
* Alpha Version update
 * Desktop
 - Added Rox checkers, and getters and setters, but haven't finished/enabled it
 - Finished gradient support
 - finished Single color support
 - moved the image setting code to flDesktop(h/cpp)
 * Window
 - fixed Window icon code to reliably open the directory containing icons
 - added 'BoxShaped' window buttons

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// "$Id: keyboard.cxx 9303 2012-03-26 16:54:54Z manolo $"
3
 
//
4
 
 
5
 
//
6
 
// Copyright 1998-2010 by Bill Spitzak and others.
7
 
//
8
 
// This library is free software. Distribution and use rights are outlined in
9
 
// the file "COPYING" which should have been included with this file.  If this
10
 
// file is missing or damaged, see the license at:
11
 
//
12
 
//     http://www.fltk.org/COPYING.php
13
 
//
14
 
// Please report all bugs and problems on the following page:
15
 
//
16
 
//     http://www.fltk.org/str.php
17
 
//
18
 
 
19
 
//
20
 
// Keyboard/event test program for the Fast Light Tool Kit (FLTK).
21
 
//
22
 
// Continuously display FLTK's event state.
23
 
//
24
 
// Known bugs:
25
 
//
26
 
// X insists on reporting the state *before* the shift key was
27
 
// pressed, rather than after, on shift key events.  I fixed this for
28
 
// the mouse buttons, but it did not seem worth it for shift.
29
 
//
30
 
// X servers do not agree about any shift flags after except shift, ctrl,
31
 
// lock, and alt.  They may also not agree about the symbols for the extra
32
 
// keys Micro$oft put on the keyboard.
33
 
//
34
 
// On IRIX the backslash key does not work.  A bug in XKeysymToKeycode?
35
 
//
36
 
#include "../include/keyboard.h"
37
 
#include "../fltk/keyboard-ui.h"
38
 
 
39
 
#include <string.h>
40
 
 
41
 
 
42
 
// these are used to identify which buttons are which:
43
 
void key_cb(Fl_Button*, void*) {}
44
 
void shift_cb(Fl_Button*, void*) {}
45
 
void wheel_cb(Fl_Dial*, void*) {}
46
 
 
47
 
// this is used to stop Esc from exiting the program:
48
 
int handle(int e) {
49
 
  return (e == FL_SHORTCUT); // eat all keystrokes
50
 
}
51
 
 
52
 
int MyWindow::handle(int msg) {
53
 
  if (msg==FL_MOUSEWHEEL)
54
 
  {
55
 
    roller_x->value( roller_x->value() + Fl::e_dx * roller_x->step() );
56
 
    roller_y->value( roller_y->value() + Fl::e_dy * roller_y->step() );
57
 
    return 1;
58
 
  }
59
 
  return 0;
60
 
}
61
 
 
62
 
struct keycode_table{int n; const char* text;} table[] = {
63
 
  {FL_Escape, "Escape"},
64
 
  {FL_BackSpace, "BackSpace"},
65
 
  {FL_Tab, "Tab"},
66
 
  {FL_Iso_Key, "Iso_Key"},
67
 
  {FL_Enter, "Enter"},
68
 
  {FL_Print, "Print"},
69
 
  {FL_Scroll_Lock, "Scroll_Lock"},
70
 
  {FL_Pause, "Pause"},
71
 
  {FL_Insert, "Insert"},
72
 
  {FL_Home, "Home"},
73
 
  {FL_Page_Up, "Page_Up"},
74
 
  {FL_Delete, "Delete"},
75
 
  {FL_End, "End"},
76
 
  {FL_Page_Down, "Page_Down"},
77
 
  {FL_Left, "Left"},
78
 
  {FL_Up, "Up"},
79
 
  {FL_Right, "Right"},
80
 
  {FL_Down, "Down"},
81
 
  {FL_Shift_L, "Shift"},
82
 
  {FL_Shift_R, "Shift"},
83
 
  {FL_Control_L, "Control"},
84
 
  {FL_Control_R, "Control"},
85
 
  {FL_Caps_Lock, "Caps_Lock"},
86
 
  {FL_Alt_L, "Alt"},
87
 
  {FL_Alt_R, "Alt"},
88
 
  {FL_Meta_L, "Meta"},
89
 
  {FL_Meta_R, "Meta"},
90
 
  {FL_Menu, "Menu"},
91
 
  {FL_Help, "Help"},
92
 
  {FL_Num_Lock, "Num_Lock"},
93
 
  {FL_KP_Enter, "Enter"},
94
 
  {FL_Volume_Down, "XF86AudioLowerVolume"},
95
 
  {FL_Volume_Up, "XF86AudioRaiseVolume"},
96
 
  {FL_Volume_Mute, "XF86AudioMute"},
97
 
  {FL_Media_Play,"XF86AudioPause"},
98
 
  {FL_Media_Stop,"XF86AudioStop"},
99
 
  {FL_Media_Prev,"XF86AudioPrev"},
100
 
  {FL_Media_Next,"XF86AudioNext"},
101
 
  {FL_Home_Page,"XF86HomePage"},
102
 
  {FL_Mail,"XF86Mail"},
103
 
  {FL_Search,"XF86Search"},
104
 
  {FL_Back,"XF86Back"},
105
 
  {FL_Forward,"XF86Forward"},
106
 
  {FL_Sleep,"XF86Standby"},
107
 
  {FL_Favorites,"XF86Favorites"}
108
 
};
109
 
 
110
 
//  {FL_Stop,"XF86??"},
111
 
//  {FL_Refresh,"XF86Refresh???"}
112
 
int main(int argc, char** argv) {
113
 
  Fl::add_handler(handle);
114
 
  MyWindow *window = make_window();
115
 
  window->show(argc,argv);
116
 
  while (Fl::wait()) {
117
 
    const char *str;
118
 
    
119
 
    // update all the buttons with the current key and shift state:
120
 
    for (int i = 0; i < window->children(); i++) {
121
 
      Fl_Widget* b = window->child(i);
122
 
      if (b->callback() == (Fl_Callback*)key_cb) {
123
 
        int i = b->argument();
124
 
        if (!i) i = b->label()[0];
125
 
        Fl_Button *btn = ((Fl_Button*)b);
126
 
        int state = Fl::event_key(i);
127
 
        if (btn->value()!=state)
128
 
          btn->value(state);
129
 
      } else if (b->callback() == (Fl_Callback*)shift_cb) {
130
 
        int i = b->argument();
131
 
        Fl_Button *btn = ((Fl_Button*)b);
132
 
        int state = Fl::event_state(i);
133
 
        if (btn->value()!=state)
134
 
          btn->value(state);
135
 
      }
136
 
    }
137
 
 
138
 
    // figure out the keyname:
139
 
    char buffer[100];
140
 
    const char *keyname = buffer;
141
 
    int k = Fl::event_key();
142
 
    if (!k)
143
 
      keyname = "0";
144
 
    else if (k < 256) {
145
 
      sprintf(buffer, "'%c'", k);
146
 
    } else if (k > FL_F && k <= FL_F_Last) {
147
 
      sprintf(buffer, "FL_F+%d", k - FL_F);
148
 
    } else if (k >= FL_KP && k <= FL_KP_Last) {
149
 
      sprintf(buffer, "FL_KP+'%c'", k-FL_KP);
150
 
    } else if (k >= FL_Button && k <= FL_Button+7) {
151
 
      sprintf(buffer, "FL_Button+%d", k-FL_Button);
152
 
    } else {
153
 
      sprintf(buffer, "0x%04x", k);
154
 
      for (int i = 0; i < int(sizeof(table)/sizeof(*table)); i++)
155
 
        if (table[i].n == k) {keyname = table[i].text; break;}
156
 
    }
157
 
    if (strcmp(key_output->value(), keyname))
158
 
      key_output->value(keyname);
159
 
 
160
 
    str = Fl::event_text();
161
 
    if (strcmp(text_output->value(), str))
162
 
      text_output->value(str);
163
 
  }
164
 
  return 0;
165
 
}
166
 
 
167
 
//
168
 
// End of "$Id: keyboard.cxx 9303 2012-03-26 16:54:54Z manolo $".
169
 
//