summaryrefslogtreecommitdiff
path: root/src/user/popups/popup.c
blob: 9cdccb4e3f0bec5f8b7a9554850d3ac3a9882ffd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <popups/popup.h>

#include <knob/format.h>
#include <knob/heap.h>

#include <pland/syscall.h>

void handle_actions(struct popup *p) {
  if (p->has_quit)
    return;
  struct window_action a;
  while (1) {
    _get_win_action(p->handle, &a);
    if (a.action_type == NOT_READY)
      return;
    if ((a.action_type == KEY_DOWN)) {
    //syslogf("got key 0x%2x, 0x%3x", a.as_key.key_id, a.as_key.modifiers);
      for (const struct key_packet *kp = p->quit_binds; kp->key_id; ++kp) {
      //syslogf("checking against 0x%2x, 0x%3x", kp->key_id, kp->modifiers);
        if ((a.as_key.key_id == kp->key_id) && (a.as_key.modifiers == kp->modifiers)) {
          p->has_quit = true;
          p->quit_as = a.as_key;
          return;
        }
      }
    }
  }
}

void delete_popup(struct popup *p) {
  _delete_window(p->handle);
  free_block(p->pixbuf);
}

void make_modal(struct popup *p) {
  handle_actions(p);
  while (!p->has_quit) {
    _wait_for_action();
    _yield_task();
    handle_actions(p);
  }
  delete_popup(p);
}