summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/action.c55
-rw-r--r--apps/menus/display_menu.c2
-rw-r--r--apps/settings.c2
-rw-r--r--firmware/drivers/button.c38
-rw-r--r--firmware/export/button.h5
-rw-r--r--uisimulator/common/stubs.c2
6 files changed, 47 insertions, 57 deletions
diff --git a/apps/action.c b/apps/action.c
index cde57441e7..055171174b 100644
--- a/apps/action.c
+++ b/apps/action.c
@@ -59,20 +59,6 @@ static int unlock_combo = BUTTON_NONE;
59static bool screen_has_lock = false; 59static bool screen_has_lock = false;
60#endif /* HAVE_SOFTWARE_KEYLOCK */ 60#endif /* HAVE_SOFTWARE_KEYLOCK */
61 61
62#if defined(HAVE_LCD_BITMAP) && !defined(BOOTLOADER)
63/*
64 * checks whether the given language and context combination require that the
65 * button is horizontally inverted to support RTL language
66 *
67 */
68static bool rtl_button_flip_needed(int context)
69{
70 return lang_is_rtl() && ((context == CONTEXT_STD) ||
71 (context & CONTEXT_TREE) || (context & CONTEXT_MAINMENU) ||
72 (context & CONTEXT_TREE));
73}
74#endif
75
76/* 62/*
77 * do_button_check is the worker function for get_default_action. 63 * do_button_check is the worker function for get_default_action.
78 * returns ACTION_UNKNOWN or the requested return value from the list. 64 * returns ACTION_UNKNOWN or the requested return value from the list.
@@ -100,6 +86,44 @@ static inline int do_button_check(const struct button_mapping *items,
100 return ret; 86 return ret;
101} 87}
102 88
89#if defined(HAVE_LCD_BITMAP) && !defined(BOOTLOADER)
90/*
91 * button is horizontally inverted to support RTL language if the given language
92 * and context combination require that
93 */
94static int button_flip_horizontally(int context, int button)
95{
96 int newbutton;
97
98 if (!(lang_is_rtl() && ((context == CONTEXT_STD) ||
99 (context & CONTEXT_TREE) || (context & CONTEXT_MAINMENU) ||
100 (context & CONTEXT_TREE))))
101 {
102 return button;
103 }
104
105 newbutton = button &
106 ~(BUTTON_LEFT | BUTTON_RIGHT
107#if defined(BUTTON_SCROLL_BACK) && defined(BUTTON_SCROLL_FWD)
108 | BUTTON_SCROLL_BACK | BUTTON_SCROLL_FWD
109#endif
110 );
111
112 if (button & BUTTON_LEFT)
113 newbutton |= BUTTON_RIGHT;
114 if (button & BUTTON_RIGHT)
115 newbutton |= BUTTON_LEFT;
116#if defined(BUTTON_SCROLL_BACK) && defined(BUTTON_SCROLL_FWD)
117 if (button & BUTTON_SCROLL_BACK)
118 newbutton |= BUTTON_SCROLL_FWD;
119 if (button & BUTTON_SCROLL_FWD)
120 newbutton |= BUTTON_SCROLL_BACK;
121#endif
122
123 return newbutton;
124}
125#endif
126
103static inline int get_next_context(const struct button_mapping *items, int i) 127static inline int get_next_context(const struct button_mapping *items, int i)
104{ 128{
105 while (items[i].button_code != BUTTON_NONE) 129 while (items[i].button_code != BUTTON_NONE)
@@ -219,8 +243,7 @@ static int get_action_worker(int context, int timeout,
219#endif /* HAS_BUTTON_HOLD */ 243#endif /* HAS_BUTTON_HOLD */
220 244
221#if defined(HAVE_LCD_BITMAP) && !defined(BOOTLOADER) 245#if defined(HAVE_LCD_BITMAP) && !defined(BOOTLOADER)
222 if (rtl_button_flip_needed(context)) 246 button = button_flip_horizontally(context, button);
223 button = button_flip_horizontally(button);
224#endif 247#endif
225 248
226 /* logf("%x,%x",last_button,button); */ 249 /* logf("%x,%x",last_button,button); */
diff --git a/apps/menus/display_menu.c b/apps/menus/display_menu.c
index afbb19c60d..5559ecebe7 100644
--- a/apps/menus/display_menu.c
+++ b/apps/menus/display_menu.c
@@ -67,7 +67,7 @@ static int flipdisplay_callback(int action,const struct menu_item_ex *this_item)
67 switch (action) 67 switch (action)
68 { 68 {
69 case ACTION_EXIT_MENUITEM: 69 case ACTION_EXIT_MENUITEM:
70 button_set_flip_vertically(global_settings.flip_display); 70 button_set_flip(global_settings.flip_display);
71 lcd_set_flip(global_settings.flip_display); 71 lcd_set_flip(global_settings.flip_display);
72 lcd_update(); 72 lcd_update();
73#ifdef HAVE_REMOTE_LCD 73#ifdef HAVE_REMOTE_LCD
diff --git a/apps/settings.c b/apps/settings.c
index ac80d12492..ce1ee07054 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -846,7 +846,7 @@ void settings_apply(bool read_disk)
846#endif 846#endif
847#ifdef HAVE_LCD_FLIP 847#ifdef HAVE_LCD_FLIP
848 lcd_set_flip(global_settings.flip_display); 848 lcd_set_flip(global_settings.flip_display);
849 button_set_flip_vertically(global_settings.flip_display); 849 button_set_flip(global_settings.flip_display);
850#endif 850#endif
851 lcd_update(); /* refresh after flipping the screen */ 851 lcd_update(); /* refresh after flipping the screen */
852 settings_apply_pm_range(); 852 settings_apply_pm_range();
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c
index 7f37087783..71cd4726cc 100644
--- a/firmware/drivers/button.c
+++ b/firmware/drivers/button.c
@@ -437,7 +437,7 @@ void button_close(void)
437/* 437/*
438 * helper function to swap LEFT/RIGHT, UP/DOWN (if present), and F1/F3 (Recorder) 438 * helper function to swap LEFT/RIGHT, UP/DOWN (if present), and F1/F3 (Recorder)
439 */ 439 */
440static int button_flip_vertically(int button) 440static int button_flip(int button)
441{ 441{
442 int newbutton; 442 int newbutton;
443 443
@@ -507,49 +507,19 @@ static int button_flip_vertically(int button)
507 * set the flip attribute 507 * set the flip attribute
508 * better only call this when the queue is empty 508 * better only call this when the queue is empty
509 */ 509 */
510void button_set_flip_vertically(bool flip) 510void button_set_flip(bool flip)
511{ 511{
512 if (flip != flipped) /* not the current setting */ 512 if (flip != flipped) /* not the current setting */
513 { 513 {
514 /* avoid race condition with the button_tick() */ 514 /* avoid race condition with the button_tick() */
515 int oldlevel = disable_irq_save(); 515 int oldlevel = disable_irq_save();
516 lastbtn = button_flip_vertically(lastbtn); 516 lastbtn = button_flip(lastbtn);
517 flipped = flip; 517 flipped = flip;
518 restore_irq(oldlevel); 518 restore_irq(oldlevel);
519 } 519 }
520} 520}
521#endif /* HAVE_LCD_FLIP */ 521#endif /* HAVE_LCD_FLIP */
522 522
523#if defined(HAVE_LCD_BITMAP) && !defined(BOOTLOADER)
524/*
525 * helper function to swap LEFT/RIGHT sides (for RTL mode)
526 */
527int button_flip_horizontally(int button)
528{
529 int newbutton;
530
531 newbutton = button &
532 ~(BUTTON_LEFT | BUTTON_RIGHT
533#if defined(BUTTON_SCROLL_BACK) && defined(BUTTON_SCROLL_FWD)
534 | BUTTON_SCROLL_BACK | BUTTON_SCROLL_FWD
535#endif
536 );
537
538 if (button & BUTTON_LEFT)
539 newbutton |= BUTTON_RIGHT;
540 if (button & BUTTON_RIGHT)
541 newbutton |= BUTTON_LEFT;
542#if defined(BUTTON_SCROLL_BACK) && defined(BUTTON_SCROLL_FWD)
543 if (button & BUTTON_SCROLL_BACK)
544 newbutton |= BUTTON_SCROLL_FWD;
545 if (button & BUTTON_SCROLL_FWD)
546 newbutton |= BUTTON_SCROLL_BACK;
547#endif
548
549 return newbutton;
550}
551#endif
552
553#ifdef HAVE_BACKLIGHT 523#ifdef HAVE_BACKLIGHT
554void set_backlight_filter_keypress(bool value) 524void set_backlight_filter_keypress(bool value)
555{ 525{
@@ -580,7 +550,7 @@ static int button_read(void)
580 550
581#ifdef HAVE_LCD_FLIP 551#ifdef HAVE_LCD_FLIP
582 if (btn && flipped) 552 if (btn && flipped)
583 btn = button_flip_vertically(btn); /* swap upside down */ 553 btn = button_flip(btn); /* swap upside down */
584#endif /* HAVE_LCD_FLIP */ 554#endif /* HAVE_LCD_FLIP */
585 555
586#ifdef HAVE_TOUCHSCREEN 556#ifdef HAVE_TOUCHSCREEN
diff --git a/firmware/export/button.h b/firmware/export/button.h
index 2e75c573df..3aac1af9d6 100644
--- a/firmware/export/button.h
+++ b/firmware/export/button.h
@@ -42,10 +42,7 @@ int button_status_wdata(int *pdata);
42#endif 42#endif
43void button_clear_queue(void); 43void button_clear_queue(void);
44#ifdef HAVE_LCD_BITMAP 44#ifdef HAVE_LCD_BITMAP
45void button_set_flip_vertically(bool flip); /* turn 180 degrees */ 45void button_set_flip(bool flip); /* turn 180 degrees */
46#ifndef BOOTLOADER
47int button_flip_horizontally(int button); /* for RTL mode */
48#endif
49#endif 46#endif
50#ifdef HAVE_BACKLIGHT 47#ifdef HAVE_BACKLIGHT
51void set_backlight_filter_keypress(bool value); 48void set_backlight_filter_keypress(bool value);
diff --git a/uisimulator/common/stubs.c b/uisimulator/common/stubs.c
index cd9e7b8ad9..2218c497f8 100644
--- a/uisimulator/common/stubs.c
+++ b/uisimulator/common/stubs.c
@@ -312,7 +312,7 @@ void cpu_sleep(bool enabled)
312 (void)enabled; 312 (void)enabled;
313} 313}
314 314
315void button_set_flip_vertically(bool yesno) 315void button_set_flip(bool yesno)
316{ 316{
317 (void)yesno; 317 (void)yesno;
318} 318}