~ubuntu-branches/ubuntu/natty/tilda/natty

« back to all changes in this revision

Viewing changes to src/key_grabber.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2006-07-04 17:25:05 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060704172505-apuw2cvjyde4ygir
Tags: 0.09.3-0ubuntu1
* New upstream release.
* debian/control:
  - added libconfuse-dev to Build-Depends,
  - make sure we build against newest libvte-dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include <stdlib.h>
30
30
#include <string.h>
31
31
#include "tilda.h"
 
32
#include "config.h"
32
33
#include "key_grabber.h"
33
34
#include "../tilda-config.h"
34
35
 
40
41
int screen;
41
42
KeySym key;
42
43
 
 
44
/*
 
45
 * The slide positions are derived from FVMW sources, file fvmm/move_resize.c,
 
46
 * to there added by Greg J. Badros, gjb@cs.washington.edu
 
47
 */
 
48
 
 
49
static float posCFV[] = {.005,.01,.02,.03,.08,.18,.3,.45,.65,.80,.88,.93,.95,.97,.99,1.0};
 
50
/* 0 - ypos, 1 - height, 2 - xpos, 3 - width */
 
51
static gint posIV[4][16]; 
 
52
 
 
53
void generate_animation_positions(struct tilda_window_ *tw)
 
54
{
 
55
    gint i;
 
56
 
 
57
#if DEBUG
 
58
    printf("generate_animation_positions(): %d\n",cfg_getint (tw->tc, "animation_orientation"));
 
59
#endif 
 
60
 
 
61
    gint last_pos_x = cfg_getint (tw->tc, "x_pos");
 
62
    gint last_pos_y = cfg_getint (tw->tc, "y_pos");
 
63
    gint last_width = cfg_getint (tw->tc, "max_width");
 
64
    gint last_height = cfg_getint (tw->tc, "max_height");
 
65
 
 
66
    for (i=0; i<16; i++)
 
67
    {
 
68
        switch (cfg_getint (tw->tc, "animation_orientation"))
 
69
        {
 
70
        case 3: /* right->left RIGHT */
 
71
            /*posIV[3][i] = (gint)(posCFV[i]*last_width); */
 
72
            /*posIV[2][i] = (gint)(last_pos_x+last_width-posIV[3][i]); */
 
73
            posIV[3][i] = last_width;
 
74
            posIV[2][i] = (gint)(last_pos_x+last_width-posCFV[i]*last_width);
 
75
            posIV[1][i] = last_height;
 
76
            posIV[0][i] = last_pos_y;
 
77
            break;
 
78
        case 2: /* left->right LEFT */
 
79
            /*posIV[3][i] = (gint)(posCFV[i]*last_width); */
 
80
            /*posIV[2][i] = last_pos_x; */
 
81
            posIV[3][i] = last_width;
 
82
            posIV[2][i] = (gint)(last_pos_x-last_width+posCFV[i]*last_width);
 
83
            posIV[1][i] = last_height;
 
84
            posIV[0][i] = last_pos_y;
 
85
            break;
 
86
        case 1: /* bottom->top BOTTOM */
 
87
            posIV[3][i] = last_width;
 
88
            posIV[2][i] = last_pos_x;
 
89
            posIV[1][i] = (gint)(posCFV[i]*last_height);        
 
90
            posIV[0][i] = (gint)(last_pos_y+last_height-posIV[1][i]);
 
91
            break;
 
92
        case 0: /* top->bottom TOP */
 
93
        default:
 
94
            posIV[3][i] = last_width;
 
95
            posIV[2][i] = last_pos_x;
 
96
            posIV[1][i] = (gint)(posCFV[i]*last_height);            
 
97
            posIV[0][i] = last_pos_y;
 
98
        }
 
99
    }
 
100
}
 
101
 
43
102
void pull (struct tilda_window_ *tw)
44
103
{
 
104
#ifdef DEBUG
 
105
    puts("pull");
 
106
#endif
 
107
 
 
108
    gint i;
45
109
    gint w, h;
46
110
    static gint pos=0;
47
 
 
 
111
    
48
112
    if (pos == 0)
49
113
    {
50
114
        gdk_threads_enter();
51
 
        
 
115
 
52
116
        pos++;
53
 
        
 
117
 
54
118
        if (gtk_window_is_active ((GtkWindow *) tw->window) == FALSE)
55
119
            gtk_window_present ((GtkWindow *) tw->window);
56
120
        else
57
121
            gtk_widget_show ((GtkWidget *) tw->window);
58
 
            
59
 
        if ((strcasecmp (tw->tc->s_pinned, "true")) == 0)
 
122
 
 
123
        if (cfg_getbool (tw->tc, "pinned"))
60
124
            gtk_window_stick (GTK_WINDOW (tw->window));
61
125
 
62
 
        if ((strcasecmp (tw->tc->s_above, "true")) == 0)
 
126
        if (cfg_getbool (tw->tc, "above"))
63
127
            gtk_window_set_keep_above (GTK_WINDOW (tw->window), TRUE);
64
128
 
65
 
        gtk_window_move ((GtkWindow *) tw->window, tw->tc->x_pos, tw->tc->y_pos);
66
 
        gtk_window_resize ((GtkWindow *) tw->window, tw->tc->max_width, tw->tc->max_height);
67
 
        
 
129
        if (cfg_getbool (tw->tc, ("animation")))
 
130
        {
 
131
            gdk_threads_leave();
 
132
 
 
133
            for (i=0; i<16; i++)
 
134
            {
 
135
                gdk_threads_enter();
 
136
                gtk_window_move ((GtkWindow *) tw->window, posIV[2][i], posIV[0][i]);
 
137
                gtk_window_resize ((GtkWindow *) tw->window, posIV[3][i], posIV[1][i]);
 
138
 
 
139
                gdk_flush();
 
140
                gdk_threads_leave();
 
141
                usleep (cfg_getint (tw->tc, "slide_sleep_usec"));
 
142
            }
 
143
        }
 
144
        else
 
145
        {
 
146
            gtk_window_move ((GtkWindow *) tw->window, cfg_getint (tw->tc, "x_pos"), cfg_getint (tw->tc, "y_pos"));
 
147
            gtk_window_resize ((GtkWindow *) tw->window, cfg_getint (tw->tc, "max_width"), cfg_getint (tw->tc, "max_height"));
 
148
            gdk_flush();
 
149
            gdk_threads_leave();
 
150
        }
 
151
 
 
152
        gdk_threads_enter();
 
153
 
68
154
        gdk_window_focus (tw->window->window, gtk_get_current_event_time ());
69
 
        
 
155
 
70
156
        gdk_flush ();
71
157
        gdk_threads_leave();
72
158
    }
73
 
    else 
 
159
    else
74
160
    {
75
161
        gdk_threads_enter();
76
 
        
 
162
 
77
163
        pos--;
78
 
        
79
 
        gtk_window_resize ((GtkWindow *) tw->window, tw->tc->min_width, tw->tc->min_height);
 
164
 
 
165
        if (cfg_getbool (tw->tc, ("animation")))
 
166
        {
 
167
            gdk_threads_leave();
 
168
            for (i=15; i>=0; i--)
 
169
            {
 
170
                gdk_threads_enter();
 
171
                gtk_window_move ((GtkWindow *) tw->window, posIV[2][i], posIV[0][i]);
 
172
                gtk_window_resize ((GtkWindow *) tw->window, posIV[3][i], posIV[1][i]);
 
173
 
 
174
                gdk_flush();
 
175
                gdk_threads_leave();
 
176
                usleep (cfg_getint (tw->tc, "slide_sleep_usec"));
 
177
            }
 
178
        }
 
179
        else
 
180
        {
 
181
            gtk_window_resize ((GtkWindow *) tw->window, cfg_getint (tw->tc, "min_width"), cfg_getint (tw->tc, "min_height"));
 
182
            gdk_flush();
 
183
            gdk_threads_leave();
 
184
        }
 
185
 
 
186
        gdk_threads_enter();
 
187
 
80
188
        gtk_widget_hide ((GtkWidget *) tw->window);
81
189
 
82
190
        gdk_flush ();
86
194
 
87
195
void key_grab (tilda_window *tw)
88
196
{
 
197
#ifdef DEBUG
 
198
    puts("key_grab");
 
199
#endif
 
200
 
89
201
    XModifierKeymap *modmap;
90
 
    gchar tmp_key[25];
 
202
    gchar tmp_key[32];
91
203
    unsigned int numlockmask = 0;
92
204
    unsigned int modmask = 0;
93
205
    gint i, j;
94
206
 
95
 
    g_strlcpy (tmp_key, tw->tc->s_key, sizeof (tmp_key));
 
207
    g_strlcpy (tmp_key, cfg_getstr (tw->tc, "key"), sizeof (tmp_key));
96
208
 
97
209
    /* Key grabbing stuff taken from yeahconsole who took it from evilwm */
98
210
    modmap = XGetModifierMapping(dpy);
121
233
    if (strstr(tmp_key, "None"))
122
234
        modmask = 0;
123
235
 
124
 
    if (!strstr(tmp_key, "+")) 
 
236
    if (!strstr(tmp_key, "+"))
125
237
        perror ("Key Incorrect -- Read the README or tilda.sf.net for info, rerun as 'tilda -C' to set keybinding\n");
126
 
    
 
238
 
127
239
    if (strtok(tmp_key, "+"))
128
240
        key = XStringToKeysym(strtok(NULL, "+"));
129
241
 
148
260
    screen = DefaultScreen(dpy);
149
261
    root = RootWindow(dpy, screen);
150
262
 
 
263
    display_width = DisplayWidth(dpy, screen); 
 
264
    display_height = DisplayHeight(dpy, screen);
 
265
    
151
266
    key_grab (tw);
152
267
 
153
 
    if (QUICK_STRCMP (tw->tc->s_down, "TRUE") == 0)
 
268
    if (cfg_getbool (tw->tc, "down"))
154
269
        pull (tw);
155
270
    else
156
271
    {
157
 
        /*gdk_threads_enter();
158
 
        gtk_widget_hide (tw->window);
159
 
        gdk_flush ();
160
 
        gdk_threads_leave();*/
 
272
        /*
 
273
         * Fixes bug that causes Tilda to eat up 100% of CPU 
 
274
         * if set to stay hidden when started
 
275
         */        
161
276
        pull (tw);
162
277
        pull (tw);
163
278
    }