Root/src/main_window.cc

1/***************************************************************************
2 * Copyright (C) 2009 by Mirko Lindner,,, *
3 * vegyraupe@mira *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21
22// newer (non customized) versions of this file go to main_window.cc_new
23
24// This file is for your program, I won't touch it again!
25
26#include "config.h"
27#include "main_window.hh"
28#include "vido.hh"
29#include <cxxtools/log.h>
30
31// extern "C" {
32// #include <directfb/directfb.h>
33// #include <gtk-2.0/gdk/gdkdisplay-directfb.h>
34// #include <gtk-2.0/gdk/gdkdirectfb.h>
35// }
36
37log_define("vido.main_window");
38int x=-1, y=-1;
39int ctrl_state;
40main_window::main_window()
41{
42    sigc::connection press_id;
43    sigc::connection release_id;
44
45}
46
47void main_window::connect_all()
48{
49        (*this).add_events( Gdk::ALL_EVENTS_MASK ) ;
50        log_debug("connecting all");
51// (*this).press_id = signal_key_press_event().connect(sigc::mem_fun(*this,&main_window::on_my_key_press_event));
52// (*this).release_id = signal_key_release_event().connect(sigc::mem_fun(*this,&main_window::on_my_key_release_event));
53// (*this).press_id =
54        (*this).press_id = (*this).signal_key_press_event().connect_notify(sigc::mem_fun(*this,&main_window::on_notify_key_press_event));
55    (*this).release_id = (*this).signal_key_release_event().connect_notify(sigc::mem_fun(*this,&main_window::on_notify_key_release_event));
56        (*this).motion_id = (*this).signal_event().connect_notify(sigc::mem_fun(*this,&main_window::motion_notify_event));
57        log_debug((*this).press_id << " " << (*this).release_id);
58}
59
60void main_window::disconnect_all()
61{
62        log_debug("disconnecting all");
63        (*this).press_id.disconnect();
64    (*this).release_id.disconnect();
65        log_debug((*this).press_id << " " << (*this).release_id);
66}
67
68void main_window::motion_notify_event ( GdkEvent *event)
69{
70// gdouble x, y;
71// gdouble pressure;
72// GdkModifierType state;
73//
74// if (event->is_hint)
75// gdk_input_window_get_pointer (event->window, event->deviceid,
76// &x, &y, &pressure, NULL, NULL, &state);
77// else
78// {
79// x = event->x;
80// y = event->y;
81// pressure = event->pressure;
82// state = event->state;
83// }
84//
85// if (state & GDK_BUTTON1_MASK && pixmap != NULL)
86// draw_brush (widget, event->source, x, y, pressure);
87//
88    log_debug("event here " << event->type);
89// return TRUE;
90}
91
92
93void main_window::move_cursor(int direction){
94    
95        int xadd=0, yadd=0;
96    Glib::RefPtr<Gdk::Display> display;
97// display = display->get_default();
98    Glib::RefPtr<Gdk::Screen> screen = this->get_screen();
99        display = screen->get_display();
100   log_debug("display: " << display);
101     log_debug("screen: " << screen);
102    /* check for up/down/left/right arrow key press */
103        log_debug("moving " << direction);
104    switch (direction)
105    {
106        case 65361:
107            xadd -= 5;
108            break;
109        case 65363:
110            xadd += 5;
111            break;
112        case 65362:
113            yadd -= 5;
114            break;
115        case 65364:
116            yadd += 5;
117            break;
118        default:
119                        log_debug("unknown direction");
120                        break;
121// return FALSE; /* propogate event */
122    }
123   
124    /* get default display and screen */
125// display = Gdk::Display::get_default();
126// screen =Gdk::Display::get_default_screen();
127// screen = gdk_display_get_default_screen (display);
128   
129    /* get cursor position */
130// GdkWindow* ;
131// IDirectFBWindow *gdk_directfb_window_lookup(gtk_widget_get_root_window(scrolled_window2));
132// GdkDisplay gdk_display_open((const gchar) display->get_name());
133        Gdk::ModifierType mask;
134// display->get_pointer(x, y, mask);
135// log_debug("unknown direction 2");
136   
137    /* set new cusor position */
138// x += xadd;
139// y += yadd;
140// IDirectFB *directfb;
141// log_debug("unknown direction 3");
142        
143        
144// GType _gdk_display = g_object_new (GDK_TYPE_DISPLAY_DFB, NULL);
145// display->directfb = directfb;
146        
147// IDirectFBDisplayLayer *layer;
148// int ret = directfb->GetDisplayLayer (directfb, DLID_PRIMARY, &layer);
149// log_debug("unknown direction 4");
150        
151// int ret = directfb->GetDisplayLayer (directfb, DLID_PRIMARY, &layer);
152        
153        
154// DFBResult result;
155// log_debug("unknown direction 5");
156//
157// result = layer->WarpCursor(layer, x, y);
158// log_debug("unknown direction 6");
159
160// Gdk::ModifierType mask;
161// if ((x==-1) && (y==-1)){
162            this->get_pointer(x, y, mask);
163// }
164    
165        log_debug("pointer x: " << x << "pointer y: " << y );
166    
167// display->warp_pointer( screen, x, y);
168
169        GdkEvent *event1 = display->peek_event();
170        if (event1 != NULL){
171            log_debug("event type: " << event1->type);
172        }else{
173            log_debug("no event");
174        }
175        
176
177// // get_window_and_coordinates(event->button.window, event->button.x, event->button.y, event->button.x_root, event->button.y_root);
178// GdkEventType type;
179// GdkWindow *window;
180// gint8 send_event;
181// guint32 time;
182// gdouble x;
183// gdouble y;
184// gdouble *axes;
185// guint state;
186// gint16 is_hint;
187// GdkDevice *device;
188// gdouble x_root, y_root;
189        
190// event->type = Gdk::MOTION_NOTIFY;
191
192        
193// event.y = y;
194// /* set new cusor position */
195        
196        
197    x += xadd;
198    y += yadd;
199// // event->button.button = Button;
200// // event->button.device = gdk_device_get_core_pointer();
201//
202// // g_object_ref(event->screen.window);
203// event.put();
204// handle_pending_events();
205// gdk_event_free(event);
206// Glib::RefPtr<Gdk::Device> pointer = display->get_core_pointer();
207// log_debug("type cursor: " << pointer->type);
208        log_debug("pointer xadd: " << xadd << "pointer yadd: " << yadd );
209    if ((screen != 0) && (display!= 0)){
210            display->warp_pointer( screen, x, y);
211// GdkEvent *event = gdk_event_new(GDK_MOTION_NOTIFY);
212// Glib::RefPtr<Gdk::Window> window = display->get_window_at_pointer(x, y);
213// Glib::RefPtr<Gdk::Device> pointer = display->get_core_pointer ();
214// event->motion.window = window->gobj();
215// event->motion.send_event = 1;
216// event->motion.time = GDK_CURRENT_TIME;
217// event->motion.x = xadd;
218// event->motion.y = yadd;
219// event->motion.axes = 0;
220// event->motion.state = 0;
221// event->motion.is_hint = 0;
222// event->motion.device = pointer->gobj();
223// event->motion.x_root = xadd;
224// event->motion.y_root = yadd;
225// display->put_event(event);
226// this->signal_motion_notify_event();
227        }
228}
229
230bool main_window::actions(int key)
231{
232        log_debug("in actions " << (*this).press_id << " " << (*this).release_id << "control state " << ctrl_state);
233    static int key_b = 98;
234    static int key_f = 102;
235    static int key_h = 104;
236    static int key_q = 113;
237    static int key_r = 114;
238    static int key_s = 115;
239    static int key_t = 116;
240        static int key_f1 = 65470;
241        static int key_left = 65361;
242        static int key_up = 65362;
243        static int key_right = 65363;
244        static int key_down = 65364;
245        
246        
247        // key commands only available if ctrl pressed
248        if ((ctrl_state == 1) && ((*this).press_id == 1))
249        {
250                (*this).disconnect_all();
251                if (key == key_q)
252                {
253// log_debug("quit requested");
254                        (*this).quit();
255                }
256                else if(key == key_r)
257                {
258                        log_debug("random");
259                        show_random();
260                }
261                else if(key == key_s)
262                {
263                        log_debug("search");
264                        search_window(this);
265                }else if(key == key_t){
266                        GoToTop();
267                }else if(key == key_h){
268                        show_history();
269                }else if(key == key_f){
270                        history_jump(1);
271                }else if(key == key_b){
272                        history_jump(-1);
273                }
274                else{
275                    (*this).connect_all();
276// log_debug("key pressed: " << key);
277                }
278        // other commands
279        }else{
280            if(key == key_f1){
281                (*this).disconnect_all();
282                show_help();
283            }else if(key == 65361){
284                        log_debug("key is left");
285                        (*this).move_cursor(key);
286                }else if(key == key_right){
287                        (*this).move_cursor(key);
288                }else if(key == key_up){
289                        (*this).move_cursor(key);
290                }else if(key == key_down){
291                        (*this).move_cursor(key);
292                }
293        }
294        
295        return true;
296
297}
298
299void main_window::on_notify_key_press_event(GdkEventKey *Key)
300{
301        
302    if (Key->keyval == 65508)
303    {
304                log_debug("setting ctrl state 1");
305        ctrl_state = 1;
306    }
307    else
308    {
309            (*this).actions(Key->keyval);
310    }
311    log_debug("Key Presssed is " << Key->keyval);
312}
313
314void main_window::on_notify_key_release_event(GdkEventKey *Key)
315{
316    if (Key->keyval == 65508)
317    {
318        log_debug("setting ctrl state 0");
319                ctrl_state = 0;
320    }
321
322}
323
324// bool main_window::on_my_key_press_event(GdkEventKey *Key)
325// {
326// if (Key->keyval == gdk_keyval_from_name("Control_R"))
327// {
328// ctrl_state = 1;
329// }
330// else
331// {
332// actions(Key->keyval);
333// }
334// log_debug("Key Presssed is " << Key->keyval);
335// return true;
336// }
337
338// bool main_window::on_my_key_release_event(GdkEventKey *Key)
339// {
340// if (Key->keyval == gdk_keyval_from_name("Control_R"))
341// {
342// ctrl_state = 0;
343// }
344//
345// return true;
346// }
347
348bool main_window::quit()
349{
350    (*this).destroy_();
351    return false;
352}
353

Archive Download this file

Branches:
development
master



interactive