aboutsummaryrefslogtreecommitdiffstats
path: root/src/matchbox-stroke-action.c
blob: 7bf45346c731b73ab3da02ad7b8cefbae5f0159f (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "matchbox-stroke.h"

struct MBStrokeAction
{
  MBStrokeActionType type;
  MBStroke          *stroke_app;

  union 
  {
    struct 
    {
      uchar *data;
    } 
    utf8char; 

    struct 
    {
      KeySym data;
    } 
    keysym; 

    struct 
    {
      int data; /* ??? */
    } 
    modifier; 

    struct 
    {
      char *name;
    } 
    mode; 

    struct 
    {
      char *data;
    } 
    exec; 

  } u;
};

MBStrokeAction*
mb_stroke_action_new(MBStroke *stroke_app)
{
  MBStrokeAction *action = NULL;

  action = util_malloc0(sizeof(MBStrokeAction));

  action->stroke_app = stroke_app;
  action->type       = MBStrokeActionNone;

  return action;
}

MBStrokeActionType
mb_stroke_action_type(MBStrokeAction *action)
{
  return action->type;
}

void
mb_stroke_action_set_as_utf8char(MBStrokeAction      *action,
				 const unsigned char *utf8char)
{
  action->type             = MBStrokeActionChar;
  action->u.utf8char.data = strdup(utf8char); 
}

const unsigned char*
mb_stroke_action_get_utf8char(MBStrokeAction *action)
{
  if (action->type == MBStrokeActionChar)
    return action->u.utf8char.data;

  return NULL;
}

void
mb_stroke_action_set_as_keysym(MBStrokeAction *action ,
			       KeySym          keysym)
{
  action->type          = MBStrokeActionXKeySym;
  action->u.keysym.data = keysym; 
}

KeySym
mb_stroke_action_get_keysym(MBStrokeAction *action)
{
  if (action->type == MBStrokeActionXKeySym)
    return action->u.keysym.data; 
  
  return NoSymbol;
}


void
mb_stroke_action_set_as_mode_switch(MBStrokeAction *action,
				    char           *mode_name)
{
  action->type          = MBStrokeActionModeSwitch;
  action->u.mode.name   = strdup(mode_name); 
}

const char*
mb_stroke_action_get_mode_switch(MBStrokeAction *action)
{
  if (action->type == MBStrokeActionModeSwitch)
    return action->u.mode.name;

  return NULL;
}

void
mb_stroke_action_execute(MBStrokeAction *action)
{
  MBStroke *stroke_app;

  if (!action) 
    return;

  stroke_app = action->stroke_app;

  switch (action->type)
    {
    case MBStrokeActionChar:
      mb_stroke_ui_key_press_release(stroke_app->ui,
				     mb_stroke_action_get_utf8char(action),
				     0);
      break;
    case MBStrokeActionXKeySym:
      mb_kbd_ui_keysym_press_release(stroke_app->ui,
				     mb_stroke_action_get_keysym(action),
				     0);
      break;
    case MBStrokeActionModeSwitch:
      /* switch mode here */
      break;
    case MBStrokeActionModifier:

      break;
    case MBStrokeActionExec:

      break;
    default:
  break;

    }
}