* rework patches
[navit-package] / debian / patches / screen_unblank.patch
1 Index: navit/configure.in
2 ===================================================================
3 --- navit.orig/configure.in     2010-01-17 03:57:45.000000000 +0100
4 +++ navit/configure.in  2010-01-17 03:58:01.441732498 +0100
5 @@ -211,6 +211,13 @@
6                 ], [
7                 AC_MSG_RESULT(no)
8         ])
9 +       PKG_CHECK_MODULES(LIBOSSO, libosso, [
10 +               AC_DEFINE(HAVE_OSSO, 1, [Have the osso library])
11 +               AC_SUBST(OSSO_CFLAGS)
12 +               AC_SUBST(OSSO_LIBS)
13 +               ], [
14 +               AC_MSG_RESULT(no)
15 +       ])
16         if test x"${enable_hildon}" = xyes ; then
17                 AC_DEFINE(USE_HILDON, 1, [Build with maemo/hildon support])
18                 AC_SUBST(HILDON_CFLAGS)
19 Index: navit/navit/Makefile.am
20 ===================================================================
21 --- navit.orig/navit/Makefile.am        2010-01-17 03:57:45.000000000 +0100
22 +++ navit/navit/Makefile.am     2010-01-17 03:58:01.441732498 +0100
23 @@ -18,7 +18,7 @@
24  endif
25  
26  
27 -AM_CPPFLAGS = -I$(top_srcdir)/navit/fib-1.1 @NAVIT_CFLAGS@ @ZLIB_CFLAGS@ -DPREFIX=\"@prefix@\" -DLIBDIR=\"@libdir@\" -DMODULE=navit
28 +AM_CPPFLAGS = -I$(top_srcdir)/navit/fib-1.1 @NAVIT_CFLAGS@ @LIBOSSO_CFLAGS@ @ZLIB_CFLAGS@ -DPREFIX=\"@prefix@\" -DLIBDIR=\"@libdir@\" -DMODULE=navit
29  BUILT_SOURCES = version.h navit_config.h
30  
31  if BIN_NAVIT
32 @@ -88,7 +88,7 @@
33  
34  else
35  navit_SOURCES = start.c
36 -navit_LDADD = libnavit.la @NAVIT_LIBS@ @WORDEXP_LIBS@ @ZLIB_LIBS@ @INTLLIBS@ -Lfib-1.1 -lfib
37 +navit_LDADD = libnavit.la @NAVIT_LIBS@ @WORDEXP_LIBS@ @LIBOSSO_LIBS@ @ZLIB_LIBS@ @INTLLIBS@ -Lfib-1.1 -lfib
38  
39  endif
40  
41 Index: navit/navit/attr_def.h
42 ===================================================================
43 --- navit.orig/navit/attr_def.h 2010-01-17 03:57:45.000000000 +0100
44 +++ navit/navit/attr_def.h      2010-01-17 03:58:01.441732498 +0100
45 @@ -276,6 +276,7 @@
46  ATTR(filter)
47  ATTR(daylayout)
48  ATTR(nightlayout)
49 +ATTR(screen_unblank)   /*  for N8x0 */
50  ATTR(xml_text)
51  ATTR(layout_name)
52  ATTR(user_name)
53 Index: navit/navit/gui/internal/gui_internal.c
54 ===================================================================
55 --- navit.orig/navit/gui/internal/gui_internal.c        2010-01-17 03:56:03.000000000 +0100
56 +++ navit/navit/gui/internal/gui_internal.c     2010-01-17 03:58:01.441732498 +0100
57 @@ -4365,6 +4365,9 @@
58                         graphics_draw_mode(this->gra, draw_mode_end);
59                         this->win->fullscreen(this->win, attr->u.num > 0);
60                         graphics_draw_mode(this->gra, draw_mode_begin);
61 +#ifdef HAVE_OSSO
62 +                       navit_osso_fullscreen(this->nav, attr->u.num > 0);
63 +#endif
64                 }
65                 this->fullscreen=attr->u.num;
66                 return 1;
67 Index: navit/navit/navit.h
68 ===================================================================
69 --- navit.orig/navit/navit.h    2010-01-17 03:56:03.000000000 +0100
70 +++ navit/navit/navit.h 2010-01-17 03:58:01.445071550 +0100
71 @@ -61,6 +61,10 @@
72  void navit_ignore_graphics_events(struct navit *this_, int ignore);
73  int navit_handle_button(struct navit *this_, int pressed, int button, struct point *p, struct callback *popup_callback);
74  void navit_handle_motion(struct navit *this_, struct point *p);
75 +#ifdef HAVE_OSSO
76 +void navit_osso_display_on(struct navit *this_);
77 +void navit_osso_fullscreen(struct navit *this_, int fullscreen);
78 +#endif
79  void navit_zoom_in(struct navit *this_, int factor, struct point *p);
80  void navit_zoom_out(struct navit *this_, int factor, struct point *p);
81  struct navit *navit_new(struct attr *parent, struct attr **attrs);
82 Index: navit/navit/xpm/Makefile.am
83 ===================================================================
84 --- navit.orig/navit/xpm/Makefile.am    2010-01-17 03:56:03.000000000 +0100
85 +++ navit/navit/xpm/Makefile.am 2010-01-17 03:58:01.445071550 +0100
86 @@ -205,7 +205,11 @@
87  endif
88  
89  DESKTOPFILEdir=$(datadir)/applications
90 +if USE_HILDON
91 +DESKTOPFILE_DATA = desktop_icons/navit.desktop, desktop_icons/org.navit-project.Navit.service
92 +else
93  DESKTOPFILE_DATA = desktop_icons/navit.desktop
94 +endif
95  
96  ICON128dir=$(datadir)/icons/hicolor/128x128/apps
97  ICON128_DATA = desktop_icons/128x128/navit.png
98 diff --git a/navit/navit.c b/navit/navit.c
99 index eb92e8b..83a3b88 100644
100 --- a/navit/navit.c
101 +++ b/navit/navit.c
102 @@ -61,7 +61,9 @@
103  #include "messages.h"
104  #include "vehicleprofile.h"
105  #include "sunriset.h"
106 -
107 +#ifdef HAVE_OSSO
108 +#include "libosso.h"
109 +#endif
110  /**
111   * @defgroup navit the navit core instance. navit is the object containing nearly everything: A set of maps, one or more vehicle, a graphics object for rendering the map, a gui object for displaying the user interface, a route object, a navigation object and so on. Be warned that it is theoretically possible to have more than one navit object
112   * @{
113 @@ -138,8 +140,15 @@ struct navit {
114         int prevTs;
115         int graphics_flags;
116         int zoom_min, zoom_max;
117 +#ifdef HAVE_OSSO
118 +       osso_context_t *osso_context;
119 +       gboolean fullscreen;    // True=fullscreen
120 +       int screen_unblank; // 0=never, 1=GPS event, 2=fullscreen
121 +#endif
122  };
123  
124 +struct navit *global_navit;
125 +
126  struct gui *main_loop_gui;
127  
128  struct attr_iter {
129 @@ -160,6 +169,102 @@ static void navit_cmd_set_center_cursor(struct navit *this_);
130  static void navit_cmd_announcer_toggle(struct navit *this_);
131  static void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv);
132  
133 +#ifdef HAVE_OSSO
134 +/**
135 + * Remember state of Fullscreen
136 + *
137 + * @param navit our context
138 + * @param fullscreen indicates whether we have full screen
139 + * @returns nothing
140 + */
141 +void
142 +navit_osso_fullscreen(struct navit *this_, int fullscreen)
143 +{
144 +       dbg(2,"setting fullscreen to %s\n", fullscreen == 0 ? "no":"yes");
145 +       this_->fullscreen = (fullscreen == 1);
146 +}
147 +        
148 +/**
149 + * * Tell osso to unblank the screen
150 + * *
151 + * * @param navit our context
152 + * * @returns nothing
153 + **/
154 +void
155 +navit_osso_display_on(struct navit *this_)
156 +{
157 +       osso_return_t err;
158 +       dbg(2,"unblank screen: fs=%d, unblank on: %d\n", this_->fullscreen, this_->screen_unblank);
159 +        switch (this_->screen_unblank) {
160 +        case 0: // never
161 +               break;
162 +        case 1: // GPS event
163 +               //osso_display_state_on(this_->osso_context);
164 +               err=osso_display_blanking_pause(this_->osso_context);
165 +               dbg(1,"Unblank result: ", err == OSSO_OK ? "Ok" : (err == OSSO_ERROR ? "Error" : "Invalid context"));
166 +               break;
167 +        case 2: // fullscreen
168 +               if (this_->fullscreen) {
169 +                       //osso_display_state_on(this_->osso_context);
170 +                       err=osso_display_blanking_pause(this_->osso_context);
171 +                      dbg(1,"Unblank result: ", err == OSSO_OK ? "Ok" : (err == OSSO_ERROR ? "Error" : "Invalid context"));
172 +               }
173 +               break;
174 +        default:
175 +               break;
176 +        }
177 +}
178 +/**
179 + * * Act on Osso event
180 + * * @param state The oss  hardware state
181 + * * @returns FALSE
182 + * */
183 +static gboolean
184 +osso_cb_hw_state_idle(osso_hw_state_t *state)
185 +{
186 +    dbg(0,"(inact=%d, save=%d, shut=%d, memlow=%d, state=%d)\n",
187 +            state->system_inactivity_ind,
188 +            state->save_unsaved_data_ind, state->shutdown_ind,
189 +            state->memory_low_ind, state->sig_device_mode_ind);
190 +
191 +    if(state->shutdown_ind)
192 +    {
193 +       /* we  are going  down, down,  down */
194 +        navit_destroy(global_navit);
195 +        exit(1);
196 +    }
197 +/* figure this out later
198 +    if(state->save_unsaved_data_ind)
199 +    {
200 +    // save all our data, if any
201 +    }
202 +
203 +    if(state->memory_low_ind)
204 +    {
205 +    // do something to reduce memory needs
206 +    }
207 +*/
208 +    g_free(state);
209 +
210 +    return FALSE;
211 +}
212 +
213 +/**
214 + * * Handle osso events
215 + * * @param state Osso hardware state
216 + * * @param  data ptr to private data
217 + * * @returns nothing
218 + **/
219 +static void
220 +osso_cb_hw_state(osso_hw_state_t *state, gpointer data)
221 +{
222 +     osso_hw_state_t *state_copy = g_new(osso_hw_state_t, 1);
223 +     memcpy(state_copy, state, sizeof(osso_hw_state_t));
224 +     g_idle_add((GSourceFunc)osso_cb_hw_state_idle, state_copy);
225 +}
226 +#endif
227 +
228 +
229  void
230  navit_add_mapset(struct navit *this_, struct mapset *ms)
231  {
232 @@ -681,6 +786,10 @@ navit_new(struct attr *parent, struct attr **attrs)
233         
234         this_->prevTs=0;
235  
236 +#ifdef HAVE_OSSO
237 +       this_->screen_unblank = 1;      // 1=GPS
238 +#endif
239 +
240         transform_setup(this_->trans, &center, zoom, (this_->orientation != -1) ? this_->orientation : 0);
241         for (;*attrs; attrs++) {
242                 navit_set_attr_do(this_, *attrs, 1);
243 @@ -1031,8 +1140,6 @@ navit_add_bookmark(struct navit *this_, struct pcoord *c, const char *descriptio
244         callback_list_call_attr_0(this_->attr_cbl, attr_bookmark_map);
245  }
246  
247 -struct navit *global_navit;
248 -
249  static void
250  navit_add_bookmarks_from_file(struct navit *this_)
251  {
252 @@ -1395,6 +1502,19 @@ navit_init(struct navit *this_)
253         navit_window_items_new(this_);
254  #endif
255  
256 +#ifdef HAVE_OSSO
257 +      dbg(1,"Installing osso context for org.navit-project.navit\n");
258 +      this_->osso_context = osso_initialize("org.navit-project.navit",
259 +                 VERSION, TRUE, NULL);
260 +      if(this_->osso_context == NULL) {
261 +                dbg(0, "error initiating osso context\n");
262 +      }
263 +      osso_hw_set_event_cb(this_->osso_context, NULL, osso_cb_hw_state, NULL);
264 +      
265 +      /* add callback to unblank screen on gps event */
266 +      navit_add_callback(this_, callback_new_attr_1(callback_cast(navit_osso_display_on), attr_position_coord_geo, this_));
267 +#endif
268 +
269         messagelist_init(this_->messages);
270  
271         navit_set_cursors(this_);
272 @@ -1746,6 +1866,14 @@ navit_set_attr_do(struct navit *this_, struct attr *attr, int init)
273                 attr_updated=(this_->center_timeout != attr->u.num);
274                 this_->center_timeout = attr->u.num;
275                 break;
276 +       // screen  unblank for Nokia N8x0
277 +       case attr_screen_unblank:
278 +                if (!strcmp(attr->u.str,"GPS"))
279 +                   this_->screen_unblank = 1;
280 +                if (!strcmp(attr->u.str, "fullscreen"))
281 +                   this_->screen_unblank  = 2;
282 +                dbg(1,"screen_unblank set to %d\n",this_->screen_unblank);
283 +                break;
284         case attr_tracking:
285                 attr_updated=(this_->tracking_flag != !!attr->u.num);
286                 this_->tracking_flag=!!attr->u.num;
287 @@ -2447,6 +2575,12 @@ navit_block(struct navit *this_, int block)
288  void
289  navit_destroy(struct navit *this_)
290  {
291 +
292 +#ifdef HAVE_OSSO
293 +       dbg(1,"Disconnecting from osso\n");
294 +       osso_deinitialize(this_->osso_context);
295 +#endif 
296 +
297         /* TODO: destroy objects contained in this_ */
298         if (this_->vehicle)
299                 vehicle_destroy(this_->vehicle->vehicle);