~ubuntu-branches/ubuntu/edgy/flwm/edgy

« back to all changes in this revision

Viewing changes to main.C

  • Committer: Bazaar Package Importer
  • Author(s): Bill Allombert
  • Date: 2006-06-30 01:17:06 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060630011706-9uvut959burvqxdj
Tags: 1.01-1
* New upstream release
  + This release catch the release of the Alt key again. Closes: #246089.
  + The following patches were applied upstream (Thanks Bill Spitzak).
    100_fl_filename_name 101_visible_focus 102_charstruct 103_man_typo
    104_g++-4.1_warning 105_double_ampersand 201_background_color
  + Add 100_double_ampersand to fix atypo in this release.
* debian/watch: added.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
class Fl_Root : public Fl_Window {
44
44
  int handle(int);
45
45
public:
46
 
  Fl_Root() : Fl_Window(0,0,Fl::w(),Fl::h()) {}
 
46
  Fl_Root() : Fl_Window(0,0,Fl::w(),Fl::h()) {
 
47
#if FL_MAJOR_VERSION > 1
 
48
    clear_double_buffer();
 
49
#endif
 
50
  }
47
51
  void show() {
48
52
    if (!shown()) Fl_X::set_xid(this, RootWindow(fl_display, fl_screen));
49
53
  }
 
54
  void flush() {}
50
55
};
51
56
Fl_Window *Root;
52
57
 
69
74
// fltk calls this for any events it does not understand:
70
75
static int flwm_event_handler(int e) {
71
76
  if (!e) { // XEvent that fltk did not understand.
72
 
    Window window = fl_xevent->xany.window;
 
77
    XWindow window = fl_xevent->xany.window;
73
78
    // unfortunately most of the redirect events put the interesting
74
79
    // window id in a different place:
75
80
    switch (fl_xevent->type) {
107
112
      const XMapRequestEvent* e = &(fl_xevent->xmaprequest);
108
113
      (void)new Frame(e->window);
109
114
      return 1;}
110
 
    case KeyRelease: {
 
115
#if FL_MAJOR_VERSION<2
 
116
    // this was needed for *some* earlier versions of fltk
 
117
    case KeyRelease:
111
118
      if (!Fl::grab()) return 0;
112
 
      // see if they released the alt key:
113
 
      unsigned long keysym =
 
119
      Fl::e_keysym =
114
120
        XKeycodeToKeysym(fl_display, fl_xevent->xkey.keycode, 0);
115
 
      if (keysym == FL_Alt_L || keysym == FL_Alt_R) {
116
 
        Fl::e_keysym = FL_Enter;
117
 
        return Fl::grab()->handle(FL_KEYBOARD);
118
 
      }
119
 
      return 0;}
120
 
    }
121
 
  } else if (e == FL_SHORTCUT) {
 
121
      goto KEYUP;
 
122
#endif
 
123
    }
 
124
  } else if (e == FL_KEYUP) {
 
125
#if FL_MAJOR_VERSION<2
 
126
  KEYUP:
 
127
#endif
 
128
    if (!Fl::grab()) return 0;
 
129
    // when alt key released, pretend they hit enter & pick menu item
 
130
    if (Fl::event_key()==FL_Alt_L || Fl::event_key()==FL_Alt_R) {
 
131
      Fl::e_keysym = FL_Enter;
 
132
#if FL_MAJOR_VERSION>1
 
133
      return Fl::modal()->handle(FL_KEYBOARD);
 
134
#else
 
135
      return Fl::grab()->handle(FL_KEYBOARD);
 
136
#endif
 
137
    }
 
138
    return 0;
 
139
  } else if (e == FL_SHORTCUT || e == FL_KEYBOARD) {
122
140
#if FL_MAJOR_VERSION == 1 && FL_MINOR_VERSION == 0 && FL_PATCH_VERSION < 3
123
141
    // make the tab keys work in the menus in older fltk's:
124
142
    // (they do not cycle around however, so a new fltk is a good idea)
189
207
#endif
190
208
 
191
209
static const char* cfg, *cbg;
 
210
#if FL_MAJOR_VERSION>1
 
211
static fltk::Cursor* cursor = FL_CURSOR_ARROW;
 
212
extern FL_API fltk::Color fl_cursor_fg;
 
213
extern FL_API fltk::Color fl_cursor_bg;
 
214
#else
192
215
static int cursor = FL_CURSOR_ARROW;
193
 
 
194
 
static void color_setup(Fl_Color slot, const char* arg, ulong value) {
195
 
  if (arg) {
196
 
    XColor x;
197
 
    if (XParseColor(fl_display, fl_colormap, arg, &x))
198
 
      value = ((x.red>>8)<<24)|((x.green>>8)<<16)|((x.blue));
199
 
  }
200
 
  Fl::set_color(slot, value);
201
 
}
 
216
#endif
202
217
 
203
218
static void initialize() {
204
219
 
205
220
  Display* d = fl_display;
206
221
 
207
222
#ifdef TEST
208
 
  Window w = XCreateSimpleWindow(d, root,
 
223
  XWindow w = XCreateSimpleWindow(d, RootWindow(d, fl_screen),
209
224
                                 100, 100, 200, 300, 10,
210
225
                                 BlackPixel(fl_display, 0),
211
226
//                               WhitePixel(fl_display, 0));
212
227
                                 0x1234);
213
228
  Frame* frame = new Frame(w);
 
229
  frame->label("flwm test window");
214
230
  XSelectInput(d, w,
215
231
               ExposureMask | StructureNotifyMask |
216
232
               KeyPressMask | KeyReleaseMask | FocusChangeMask |
230
246
               ButtonPressMask | ButtonReleaseMask | 
231
247
               EnterWindowMask | LeaveWindowMask |
232
248
               KeyPressMask | KeyReleaseMask | KeymapStateMask);
233
 
  color_setup(CURSOR_FG_SLOT, cfg, CURSOR_FG_COLOR<<8);
234
 
  color_setup(CURSOR_BG_SLOT, cbg, CURSOR_BG_COLOR<<8);
 
249
#if FL_MAJOR_VERSION>1
 
250
  Root->cursor(cursor);
 
251
#else
235
252
  Root->cursor((Fl_Cursor)cursor, CURSOR_FG_SLOT, CURSOR_BG_SLOT);
 
253
#endif
 
254
  Fl::visible_focus(0);
236
255
 
237
256
#ifdef TITLE_FONT
238
257
  Fl::set_font(TITLE_FONT_SLOT, TITLE_FONT);
247
266
  // Gnome crap:
248
267
  // First create a window that can be watched to see if wm dies:
249
268
  Atom a = XInternAtom(d, "_WIN_SUPPORTING_WM_CHECK", False);
250
 
  Window win = XCreateSimpleWindow(d, fl_xid(Root), -200, -200, 5, 5, 0, 0, 0);
 
269
  XWindow win = XCreateSimpleWindow(d, fl_xid(Root), -200, -200, 5, 5, 0, 0, 0);
251
270
  CARD32 val = win;
252
271
  XChangeProperty(d, fl_xid(Root), a, XA_CARDINAL, 32, PropModeReplace, (uchar*)&val, 1);
253
272
  XChangeProperty(d, win, a, XA_CARDINAL, 32, PropModeReplace, (uchar*)&val, 1);
287
306
 
288
307
  // find all the windows and create a Frame for each:
289
308
  unsigned int n;
290
 
  Window w1, w2, *wins;
 
309
  XWindow w1, w2, *wins;
291
310
  XWindowAttributes attr;
292
311
  XQueryTree(d, fl_xid(Root), &w1, &w2, &wins, &n);
293
312
  for (i = 0; i < n; ++i) {
298
317
  XFree((void *)wins);
299
318
 
300
319
#endif
301
 
  Fl::visible_focus(0);
302
320
}
303
321
 
304
322
////////////////////////////////////////////////////////////////
329
347
    cfg = v;
330
348
  } else if (!strcmp(s, "cbg")) {
331
349
    cbg = v;
 
350
#if FL_MAJOR_VERSION < 2
332
351
  } else if (*s == 'c') {
333
352
    cursor = atoi(v);
 
353
#endif
334
354
  } else if (*s == 'v') {
335
355
    int visid = atoi(v);
336
356
    fl_open_display();
351
371
  return 2;
352
372
}
353
373
 
 
374
#if FL_MAJOR_VERSION<2
 
375
static void color_setup(Fl_Color slot, const char* arg, ulong value) {
 
376
  if (arg) {
 
377
    XColor x;
 
378
    if (XParseColor(fl_display, fl_colormap, arg, &x))
 
379
      value = ((x.red>>8)<<24)|((x.green>>8)<<16)|((x.blue));
 
380
  }
 
381
  Fl::set_color(slot, value);
 
382
}
 
383
#endif
 
384
 
354
385
int main(int argc, char** argv) {
355
386
  program_name = fl_filename_name(argv[0]);
356
387
  int i; if (Fl::args(argc, argv, i, arg) < argc) Fl::error(
370
401
#ifndef FL_NORMAL_SIZE // detect new versions of fltk where this is a variable
371
402
  FL_NORMAL_SIZE = 12;
372
403
#endif
 
404
#if FL_MAJOR_VERSION>1
 
405
  if (cfg) fl_cursor_fg = fltk::color(cfg);
 
406
  if (cbg) fl_cursor_bg = fltk::color(cbg);
 
407
#else
 
408
  fl_open_display();
 
409
  color_setup(CURSOR_FG_SLOT, cfg, CURSOR_FG_COLOR<<8);
 
410
  color_setup(CURSOR_BG_SLOT, cbg, CURSOR_BG_COLOR<<8);
373
411
  Fl::set_color(FL_SELECTION_COLOR,0,0,128);
374
 
  Root = new Fl_Root();
 
412
#endif
 
413
  Fl_Root root;
 
414
  Root = &root;
 
415
#if FL_MAJOR_VERSION>1
 
416
  // show() is not a virtual function in fltk2.0, this fools it:
 
417
  fltk::load_theme();
 
418
  root.show();
 
419
#endif
375
420
  Root->show(argc,argv); // fools fltk into using -geometry to set the size
376
421
  XSetErrorHandler(xerror_handler);
377
422
  initialize();