00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00029
00030
00031
00032
00033
00034
00035 #include <config.h>
00036 #include <stdio.h>
00037 #include <unistd.h>
00038 #include <stdlib.h>
00039 #include <fcntl.h>
00040 #include <sys/ioctl.h>
00041
00042 #include <gtk/gtk.h>
00043 #include <libxml/parser.h>
00044 #include <libxml/tree.h>
00045
00046 #include <liberdm/display.h>
00047 #include <libermanifest/ermanifest.h>
00048
00049 #include "contentListerLog.h"
00050 #include "displayUpdate.h"
00051 #include "erConnect.h"
00052 #include "system.h"
00053 #include "gtkPincodeScreen.h"
00054 #include "control.h"
00055 #include "cursor.h"
00056 #include "lister.h"
00057
00058
00059
00060 static struct display_update_info updateinfo;
00061
00062 static ContentLister* g_contentLister = NULL;
00063
00064 static int g_framebuffer_device = -1;
00065 static gboolean g_cursor_needs_update = FALSE;
00066
00067 static guint g_cursor_num_blinking = 0;
00068 static guint g_cursor_blink_handler = 0;
00069
00070 static int g_cursor_x_pos;
00071 static int g_cursor_x_pos_alt;
00072 static int g_cursor_x_pos_blink;
00073
00074 static struct
00075 {
00076 int y_pos;
00077 cursor_state_t state;
00078 } cursor_info[MAX_ITEMS_ON_ONE_PAGE];
00079
00080
00081
00082 static gboolean cursor_blink(gpointer user_data);
00083 static void cursor_blink_handler_stop(void);
00084
00085
00086
00087
00088
00089 int cursor_init(ContentLister* theContentLister)
00090 {
00091 int i;
00092
00093 g_contentLister = theContentLister;
00094
00095
00096 g_framebuffer_device = open("/dev/fb0", O_RDWR);
00097 if (g_framebuffer_device == -1)
00098 {
00099 CL_ERRORPRINTF("Error opening framebufferdevice. # mknod /dev/fb0 c 29 0");
00100 return -1;
00101 }
00102
00103
00104 g_cursor_x_pos = CURSOR_X;
00105 g_cursor_x_pos_alt = g_cursor_x_pos - BLACK_CURSOR_SIZE_Y;
00106 if (g_cursor_x_pos_alt < BLACK_CURSOR_SIZE_Y + 3)
00107 {
00108 g_cursor_x_pos_alt = BLACK_CURSOR_SIZE_Y + 3;
00109 }
00110 g_cursor_x_pos_blink = g_cursor_x_pos;
00111
00112
00113 for (i = 0 ; i < MAX_ITEMS_ON_ONE_PAGE ; i++)
00114 {
00115 cursor_info[i].y_pos = CURSOR_START_Y + i * CURSOR_STEP;
00116 cursor_info[i].state = e_cursor_hide;
00117 }
00118
00119
00120 updateinfo.waveform = WAVEFORM_FAST_BLACK_WHITE;
00121 updateinfo.sequence = 0;
00122
00123 return 0;
00124 }
00125
00126
00127
00128
00129
00130 int cursor_set_state(const int pos, const cursor_state_t new_state)
00131 {
00132 int retVal = 0;
00133
00134 if (pos == -1)
00135 {
00136 return 0;
00137 }
00138 CL_CURSORPRINTF("entry: pos [%d] new_state [%d]", pos, new_state);
00139 g_return_val_if_fail((pos >= 0 && pos < MAX_ITEMS_ON_ONE_PAGE), -1);
00140
00141 int rc;
00142 struct brush_draw_info drawinfo;
00143 cursor_state_t old_state = cursor_info[pos].state;
00144 GtkWidget* listItem = lsGetListerItem(g_contentLister->lister, pos);
00145
00146 if (new_state == e_cursor_hide)
00147 {
00148 gtk_content_list_item_show_cursor(GTK_CONTENT_LIST_ITEM(listItem), FALSE);
00149
00150
00151 drawinfo.sourcex = WHITE_CURSOR_X;
00152 drawinfo.sourcey = WHITE_CURSOR_Y;
00153 drawinfo.sizex = WHITE_CURSOR_SIZE_X;
00154 drawinfo.sizey = WHITE_CURSOR_SIZE_Y;
00155 drawinfo.destx = cursor_info[pos].y_pos;
00156 drawinfo.desty = SCREEN_WIDTH - ((old_state == e_cursor_blink) ? g_cursor_x_pos_blink : g_cursor_x_pos);
00157 drawinfo.brushlsb = WHITE;
00158 }
00159 else
00160 {
00161 gtk_content_list_item_show_cursor(GTK_CONTENT_LIST_ITEM(listItem), TRUE);
00162
00163
00164 drawinfo.sourcex = BLACK_CURSOR_X;
00165 drawinfo.sourcey = BLACK_CURSOR_Y;
00166 drawinfo.sizex = BLACK_CURSOR_SIZE_X;
00167 drawinfo.sizey = BLACK_CURSOR_SIZE_Y;
00168 drawinfo.destx = cursor_info[pos].y_pos;
00169 drawinfo.desty = SCREEN_WIDTH - ((new_state == e_cursor_blink) ? g_cursor_x_pos_blink : g_cursor_x_pos);
00170 drawinfo.brushlsb = BLACK;
00171 }
00172 cursor_info[pos].state = new_state;
00173
00174
00175 if (display_update_get_level() < NO_DISPLAY_UPDATE_LEVEL)
00176 {
00177 CL_CURSORPRINTF("FBIO_DRAW_BRUSH location %dx%d color %d", drawinfo.desty, drawinfo.destx, drawinfo.brushlsb);
00178 rc = ioctl(g_framebuffer_device, FBIO_DRAW_BRUSH_GENERIC, &drawinfo);
00179 if (rc != 0)
00180 {
00181 CL_ERRORPRINTF("Error drawing brush (err=0x%x)", rc);
00182 retVal = -1;
00183 }
00184 }
00185
00186
00187
00188 if (old_state == e_cursor_blink && g_cursor_num_blinking > 0)
00189 {
00190 g_cursor_num_blinking--;
00191 }
00192 if (new_state == e_cursor_blink)
00193 {
00194 g_cursor_num_blinking++;
00195 }
00196 g_cursor_num_blinking = g_cursor_num_blinking;
00197
00198 if (g_cursor_num_blinking == 0)
00199 {
00200 if (g_cursor_blink_handler != 0)
00201 {
00202 cursor_blink_handler_stop();
00203 g_cursor_x_pos_blink = g_cursor_x_pos;
00204 }
00205 }
00206 else
00207 {
00208 if (g_cursor_blink_handler == 0)
00209 {
00210 g_cursor_blink_handler = g_timeout_add(800, cursor_blink, NULL);
00211 }
00212 }
00213
00214
00215 if ( (new_state == e_cursor_blink && g_cursor_num_blinking > 1)
00216 || (old_state == e_cursor_blink && g_cursor_num_blinking > 0) )
00217 {
00218
00219 }
00220 else
00221 {
00222
00223 g_cursor_needs_update = TRUE;
00224 }
00225
00226 return retVal;
00227 }
00228
00229 void cursor_hide_all(void)
00230 {
00231 int rc;
00232 int pos;
00233 struct brush_draw_info drawinfo;
00234 GtkWidget* listItem = NULL;
00235
00236 CL_CURSORPRINTF("entry");
00237
00238
00239 cursor_blink_handler_stop();
00240 g_cursor_num_blinking = 0;
00241 g_cursor_x_pos_blink = g_cursor_x_pos;
00242
00243
00244 drawinfo.sourcex = WHITE_CURSOR_X;
00245 drawinfo.sourcey = WHITE_CURSOR_Y;
00246 drawinfo.sizex = WHITE_CURSOR_SIZE_X;
00247 drawinfo.sizey = WHITE_CURSOR_SIZE_Y;
00248 drawinfo.brushlsb = WHITE;
00249 for (pos = 0 ; pos < MAX_ITEMS_ON_ONE_PAGE ; pos++)
00250 {
00251 drawinfo.destx = cursor_info[pos].y_pos;
00252
00253 cursor_info[pos].state = e_cursor_hide;
00254
00255
00256 listItem = lsGetListerItem(g_contentLister->lister, pos);
00257 gtk_content_list_item_show_cursor(GTK_CONTENT_LIST_ITEM(listItem), FALSE);
00258
00259
00260 drawinfo.desty = SCREEN_WIDTH - g_cursor_x_pos;
00261 if (display_update_get_level() < NO_DISPLAY_UPDATE_LEVEL)
00262 {
00263 CL_CURSORPRINTF("FBIO_DRAW_BRUSH location %dx%d color %d", drawinfo.desty, drawinfo.destx, drawinfo.brushlsb);
00264 rc = ioctl(g_framebuffer_device, FBIO_DRAW_BRUSH_GENERIC, &drawinfo);
00265 if (rc != 0)
00266 {
00267 CL_ERRORPRINTF("Error drawing brush (err=0x%x)", rc);
00268 }
00269 }
00270
00271
00272 drawinfo.desty = SCREEN_WIDTH - g_cursor_x_pos_alt;
00273 if (display_update_get_level() < NO_DISPLAY_UPDATE_LEVEL)
00274 {
00275 CL_CURSORPRINTF("FBIO_DRAW_BRUSH location %dx%d color %d", drawinfo.desty, drawinfo.destx, drawinfo.brushlsb);
00276 rc = ioctl(g_framebuffer_device, FBIO_DRAW_BRUSH_GENERIC, &drawinfo);
00277 if (rc != 0)
00278 {
00279 CL_ERRORPRINTF("Error drawing brush (err=0x%x)", rc);
00280 }
00281 }
00282 g_cursor_needs_update = TRUE;
00283 }
00284 }
00285
00286 void cursor_redraw()
00287 {
00288 CL_CURSORPRINTF("entry");
00289
00290 int rc;
00291
00292 if ( g_cursor_needs_update
00293 && display_update_get_level() < NO_DISPLAY_UPDATE_LEVEL )
00294 {
00295
00296 CL_CURSORPRINTF("FBIO_REDRAW waveform %d - sequence %d", updateinfo.waveform, updateinfo.sequence);
00297 rc = ioctl(g_framebuffer_device, FBIO_REDRAW, &updateinfo);
00298 if (rc != 0)
00299 {
00300 CL_ERRORPRINTF("Error sending FBIO_REDRAW: %x", rc);
00301 }
00302 g_cursor_needs_update = FALSE;
00303 }
00304 }
00305
00306 static void cursor_blink_handler_stop(void)
00307 {
00308 CL_CURSORPRINTF("entry: blink_handler [%d]", g_cursor_blink_handler);
00309
00310 if (g_cursor_blink_handler != 0)
00311 {
00312 g_source_remove(g_cursor_blink_handler);
00313 g_cursor_blink_handler = 0;
00314 }
00315 }
00316
00317 static gboolean cursor_blink(gpointer user_data)
00318 {
00319 int rc;
00320 int pos;
00321 gboolean call_me_again = FALSE;
00322 struct brush_draw_info drawinfo;
00323
00324 CL_CURSORPRINTF("entry");
00325
00326 if (g_cursor_num_blinking == 0)
00327 {
00328 CL_WARNPRINTF("Stop blink handler, because num_blinking is zero");
00329 g_cursor_blink_handler = 0;
00330 return call_me_again;
00331 }
00332
00333
00334 drawinfo.sourcex = WHITE_CURSOR_X;
00335 drawinfo.sourcey = WHITE_CURSOR_Y;
00336 drawinfo.sizex = WHITE_CURSOR_SIZE_X;
00337 drawinfo.sizey = WHITE_CURSOR_SIZE_Y;
00338 drawinfo.desty = SCREEN_WIDTH - g_cursor_x_pos_blink;
00339 drawinfo.brushlsb = WHITE;
00340 for (pos = 0 ; pos < MAX_ITEMS_ON_ONE_PAGE ; pos++)
00341 {
00342 if (cursor_info[pos].state == e_cursor_blink)
00343 {
00344 drawinfo.destx = cursor_info[pos].y_pos;
00345
00346
00347 if (display_update_get_level() < NO_DISPLAY_UPDATE_LEVEL)
00348 {
00349 CL_CURSORPRINTF("FBIO_DRAW_BRUSH location %dx%d color %d", drawinfo.desty, drawinfo.destx, drawinfo.brushlsb);
00350 rc = ioctl(g_framebuffer_device, FBIO_DRAW_BRUSH_GENERIC, &drawinfo);
00351 if (rc != 0)
00352 {
00353 CL_ERRORPRINTF("Error drawing brush (err=0x%x)", rc);
00354 }
00355 }
00356 }
00357 }
00358
00359
00360 if (g_cursor_x_pos_blink == g_cursor_x_pos)
00361 {
00362 g_cursor_x_pos_blink = g_cursor_x_pos_alt;
00363 }
00364 else
00365 {
00366 g_cursor_x_pos_blink = g_cursor_x_pos;
00367 }
00368
00369
00370 drawinfo.sourcex = BLACK_CURSOR_X;
00371 drawinfo.sourcey = BLACK_CURSOR_Y;
00372 drawinfo.sizex = BLACK_CURSOR_SIZE_X;
00373 drawinfo.sizey = BLACK_CURSOR_SIZE_Y;
00374 drawinfo.desty = SCREEN_WIDTH - g_cursor_x_pos_blink;
00375 drawinfo.brushlsb = BLACK;
00376 for (pos = 0 ; pos < MAX_ITEMS_ON_ONE_PAGE ; pos++)
00377 {
00378 if (cursor_info[pos].state == e_cursor_blink)
00379 {
00380 drawinfo.destx = cursor_info[pos].y_pos;
00381
00382
00383 if (display_update_get_level() < NO_DISPLAY_UPDATE_LEVEL)
00384 {
00385 CL_CURSORPRINTF("FBIO_DRAW_BRUSH location %dx%d color %d", drawinfo.desty, drawinfo.destx, drawinfo.brushlsb);
00386 rc = ioctl(g_framebuffer_device, FBIO_DRAW_BRUSH_GENERIC, &drawinfo);
00387 if (rc != 0)
00388 {
00389 CL_ERRORPRINTF("Error drawing brush (err=0x%x)", rc);
00390 }
00391 }
00392 }
00393 }
00394
00395
00396 g_cursor_needs_update = TRUE;
00397 cursor_redraw();
00398
00399
00400 call_me_again = TRUE;
00401 return call_me_again;
00402 }
00403
00404 void cursor_destroy()
00405 {
00406 close(g_framebuffer_device);
00407 }
00408
00409 void start_progress_indicator()
00410 {
00411 int framebuffer_device;
00412
00413
00414 if (display_update_get_level() < NO_DISPLAY_UPDATE_LEVEL)
00415 {
00416 framebuffer_device = open("/dev/fb0", O_RDWR);
00417 if ((ioctl(framebuffer_device, FBIO_START_PROGRESS_BAR)) != 0)
00418 {
00419 CL_ERRORPRINTF("einkfb IOCTL failed");
00420 }
00421 close(framebuffer_device);
00422 }
00423 }
00424