summaryrefslogtreecommitdiff
path: root/plugins/keyboard/keyaction.c
blob: e3b9aca4cacbb39db1dc9d89bd1d43f9ddc380fd (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
151
152
153
154
155
156
157
158
159
#include "keyaction.h"
#include <glib.h>

void keyaction_set_none(KeyAction *a, guint index)
{
    a->type[index] = DataType_Bool;
}

void keyaction_set_bool(KeyAction *a, guint index, gboolean b)
{
    a->type[index] = DataType_Bool;
    a->data[index].b = b;
}

void keyaction_set_int(KeyAction *a, guint index, int i)
{
    a->type[index] = DataType_Int;
    a->data[index].i = i;
}

void keyaction_set_uint(KeyAction *a, guint index, guint u)
{
    a->type[index] = DataType_Uint;
    a->data[index].u = u;
}

void keyaction_set_string(KeyAction *a, guint index, char *s)
{
    a->type[index] = DataType_String;
    a->data[index].s = g_strdup(s);
}

void keyaction_free(KeyAction *a)
{
    guint i;

    for (i = 0; i < 2; ++i)
        if (a->type[i] == DataType_String)
            g_free(a->data[i].s);
}

void keyaction_do(KeyAction *a, Client *c)
{
    switch (a->action) {
    case Action_Execute:
        g_assert(a->type[0] == DataType_String);
        action_execute(a->data[0].s);
        break;
    case Action_Iconify:
        if (c != NULL) action_iconify(c);
        break;
    case Action_Raise:
        if (c != NULL) action_raise(c);
        break;
    case Action_Lower:
        if (c != NULL) action_lower(c);
        break;
    case Action_Close:
        if (c != NULL) action_close(c);
        break;
    case Action_Shade:
        if (c != NULL) action_shade(c);
        break;
    case Action_Unshade:
        if (c != NULL) action_unshade(c);
        break;
    case Action_ToggleShade:
        if (c != NULL) action_toggle_shade(c);
        break;
    case Action_ToggleOmnipresent:
        if (c != NULL) action_toggle_omnipresent(c);
        break;
    case Action_MoveRelative:
        g_assert(a->type[0] == DataType_Int);
        g_assert(a->type[1] == DataType_Int);
        if (c != NULL) action_move_relative(c, a->data[0].i, a->data[1].i);
        break;
    case Action_ResizeRelative:
        g_assert(a->type[0] == DataType_Int);
        g_assert(a->type[1] == DataType_Int);
        if (c != NULL) action_resize_relative(c, a->data[0].i, a->data[1].i);
        break;
    case Action_MaximizeFull:
        if (c != NULL) action_maximize_full(c);
        break;
    case Action_UnmaximizeFull:
        if (c != NULL) action_unmaximize_full(c);
        break;
    case Action_ToggleMaximizeFull:
        if (c != NULL) action_toggle_maximize_full(c);
        break;
    case Action_MaximizeHorz:
        if (c != NULL) action_maximize_horz(c);
        break;
    case Action_UnmaximizeHorz:
        if (c != NULL) action_unmaximize_horz(c);
        break;
    case Action_ToggleMaximizeHorz:
        if (c != NULL) action_toggle_maximize_horz(c);
        break;
    case Action_MaximizeVert:
        if (c != NULL) action_maximize_vert(c);
        break;
    case Action_UnmaximizeVert:
        if (c != NULL) action_unmaximize_vert(c);
        break;
    case Action_ToggleMaximizeVert:
        if (c != NULL) action_toggle_maximize_vert(c);
        break;
    case Action_SendToDesktop:
        g_assert(a->type[0] == DataType_Uint);
        if (c != NULL) action_send_to_desktop(c, a->data[0].u);
        break;
    case Action_SendToNextDesktop:
        g_assert(a->type[0] == DataType_Bool);
        g_assert(a->type[1] == DataType_Bool);
        if (c != NULL) action_send_to_next_desktop(c, a->data[0].b,
                                                   a->data[1].b);
        break;
    case Action_SendToPreviousDesktop:
        g_assert(a->type[0] == DataType_Bool);
        g_assert(a->type[1] == DataType_Bool);
        if (c != NULL) action_send_to_previous_desktop(c, a->data[0].b,
                                                       a->data[1].b);
        break;
    case Action_Desktop:
        g_assert(a->type[0] == DataType_Uint);
        action_desktop(a->data[0].u);
        break;
    case Action_NextDesktop:
        g_assert(a->type[0] == DataType_Bool);
        action_next_desktop(a->data[0].b);
        break;
    case Action_PreviousDesktop:
        g_assert(a->type[0] == DataType_Bool);
        action_previous_desktop(a->data[0].b);
        break;
    case Action_NextDesktopColumn:
        g_assert(a->type[0] == DataType_Bool);
        action_next_desktop_column(a->data[0].b);
        break;
    case Action_PreviousDesktopColumn:
        g_assert(a->type[0] == DataType_Bool);
        action_previous_desktop_column(a->data[0].b);
        break; 
    case Action_NextDesktopRow:
        g_assert(a->type[0] == DataType_Bool);
        action_next_desktop_row(a->data[0].b);
        break;
    case Action_PreviousDesktopRow:
        g_assert(a->type[0] == DataType_Bool);
        action_previous_desktop_row(a->data[0].b);
        break; 
    case Action_ToggleDecorations:
        if (c != NULL) action_toggle_decorations(c);
        break; 
   }
}