Skip to content

Commit

Permalink
Added compact display mode.
Browse files Browse the repository at this point in the history
Use short names and icons to show keys in compact mode. Icons are chosen
based on @arielherself's idea.

See <https://github.com/AlynxZhou/showmethekey/pull/43/files>.

Closes <#42>.
  • Loading branch information
AlynxZhou committed May 2, 2024
1 parent 0bbd146 commit 1031f4b
Show file tree
Hide file tree
Showing 8 changed files with 383 additions and 162 deletions.
38 changes: 21 additions & 17 deletions showmethekey-gtk/po/showmethekey.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: showmethekey\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-11-10 17:15+0800\n"
"POT-Creation-Date: 2024-05-02 17:09+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand All @@ -17,7 +17,7 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: showmethekey-gtk/smtk-app.c:95 showmethekey-gtk/smtk-app-win.c:599
#: showmethekey-gtk/smtk-app.c:95 showmethekey-gtk/smtk-app-win.c:596
#: showmethekey-gtk/smtk-app-win.ui:9 showmethekey-gtk/smtk-app-win.ui:17
msgid "Show Me The Key"
msgstr ""
Expand All @@ -26,11 +26,11 @@ msgstr ""
msgid "Display version then exit."
msgstr ""

#: showmethekey-gtk/smtk-app-win.c:518
#: showmethekey-gtk/smtk-app-win.c:515
msgid "Usage"
msgstr ""

#: showmethekey-gtk/smtk-app-win.c:519
#: showmethekey-gtk/smtk-app-win.c:516
msgid ""
"1. Please input admin password after toggling the switch, because it needs "
"superuser permission to read input events, and Wayland does not allow "
Expand Down Expand Up @@ -68,19 +68,19 @@ msgid ""
"You can open this dialog again via menu icon on title bar -> \"Usage\"."
msgstr ""

#: showmethekey-gtk/smtk-app-win.c:560
#: showmethekey-gtk/smtk-app-win.c:557
msgid "Close"
msgstr ""

#: showmethekey-gtk/smtk-app-win.c:597
#: showmethekey-gtk/smtk-app-win.c:594
msgid "translator-credits"
msgstr ""

#: showmethekey-gtk/smtk-app-win.c:598
#: showmethekey-gtk/smtk-app-win.c:595
msgid "About Show Me The Key"
msgstr ""

#: showmethekey-gtk/smtk-app-win.c:600
#: showmethekey-gtk/smtk-app-win.c:597
msgid "Show keys you typed on screen."
msgstr ""

Expand Down Expand Up @@ -153,41 +153,45 @@ msgstr ""
msgid "Raw"
msgstr ""

#: showmethekey-gtk/smtk-app-win.ui:178
msgid "Timeout (ms)"
#: showmethekey-gtk/smtk-app-win.ui:165
msgid "Compact"
msgstr ""

#: showmethekey-gtk/smtk-app-win.ui:179
msgid "Timeout (ms)"
msgstr ""

#: showmethekey-gtk/smtk-app-win.ui:180
msgid ""
"Clear keys if no new key after how many miliscconds. Set to 0 to keep all "
"keys."
msgstr ""

#: showmethekey-gtk/smtk-app-win.ui:199
#: showmethekey-gtk/smtk-app-win.ui:200
msgid "Width (px)"
msgstr ""

#: showmethekey-gtk/smtk-app-win.ui:200
#: showmethekey-gtk/smtk-app-win.ui:201
msgid "Width of keys window."
msgstr ""

#: showmethekey-gtk/smtk-app-win.ui:215
#: showmethekey-gtk/smtk-app-win.ui:216
msgid "Height (px)"
msgstr ""

#: showmethekey-gtk/smtk-app-win.ui:216
#: showmethekey-gtk/smtk-app-win.ui:217
msgid "Height of keys window."
msgstr ""

#: showmethekey-gtk/smtk-app-win.ui:232
#: showmethekey-gtk/smtk-app-win.ui:233
msgid "Keyboard"
msgstr ""

#: showmethekey-gtk/smtk-app-win.ui:236
#: showmethekey-gtk/smtk-app-win.ui:237
msgid "Keymap"
msgstr ""

#: showmethekey-gtk/smtk-app-win.ui:237
#: showmethekey-gtk/smtk-app-win.ui:238
msgid "Choose your keyboard layout and variant."
msgstr ""

Expand Down
38 changes: 21 additions & 17 deletions showmethekey-gtk/po/zh_CN.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: showmethekey\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-11-10 17:15+0800\n"
"POT-Creation-Date: 2024-05-02 17:09+0800\n"
"PO-Revision-Date: 2021-04-21 15:16+0800\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
Expand All @@ -16,7 +16,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: showmethekey-gtk/smtk-app.c:95 showmethekey-gtk/smtk-app-win.c:599
#: showmethekey-gtk/smtk-app.c:95 showmethekey-gtk/smtk-app-win.c:596
#: showmethekey-gtk/smtk-app-win.ui:9 showmethekey-gtk/smtk-app-win.ui:17
msgid "Show Me The Key"
msgstr "让我看键"
Expand All @@ -25,11 +25,11 @@ msgstr "让我看键"
msgid "Display version then exit."
msgstr "显示版本号然后退出。"

#: showmethekey-gtk/smtk-app-win.c:518
#: showmethekey-gtk/smtk-app-win.c:515
msgid "Usage"
msgstr "使用说明(_U)"

#: showmethekey-gtk/smtk-app-win.c:519
#: showmethekey-gtk/smtk-app-win.c:516
msgid ""
"1. Please input admin password after toggling the switch, because it needs "
"superuser permission to read input events, and Wayland does not allow "
Expand Down Expand Up @@ -95,19 +95,19 @@ msgstr ""
"\n"
"您可以通过标题栏上的菜单按钮 ->“使用说明”来再次访问此对话框。"

#: showmethekey-gtk/smtk-app-win.c:560
#: showmethekey-gtk/smtk-app-win.c:557
msgid "Close"
msgstr "关闭"

#: showmethekey-gtk/smtk-app-win.c:597
#: showmethekey-gtk/smtk-app-win.c:594
msgid "translator-credits"
msgstr "Alynx Zhou"

#: showmethekey-gtk/smtk-app-win.c:598
#: showmethekey-gtk/smtk-app-win.c:595
msgid "About Show Me The Key"
msgstr "关于让我看键"

#: showmethekey-gtk/smtk-app-win.c:600
#: showmethekey-gtk/smtk-app-win.c:597
msgid "Show keys you typed on screen."
msgstr "在屏幕上显示你按的键。"

Expand Down Expand Up @@ -180,41 +180,45 @@ msgstr "组合键"
msgid "Raw"
msgstr "按键名"

#: showmethekey-gtk/smtk-app-win.ui:178
#: showmethekey-gtk/smtk-app-win.ui:165
msgid "Compact"
msgstr "紧凑"

#: showmethekey-gtk/smtk-app-win.ui:179
msgid "Timeout (ms)"
msgstr "超时(毫秒)"

#: showmethekey-gtk/smtk-app-win.ui:179
#: showmethekey-gtk/smtk-app-win.ui:180
msgid ""
"Clear keys if no new key after how many miliscconds. Set to 0 to keep all "
"keys."
msgstr "多少毫秒没有新按键之后清除已有的按键。设置为 0 保留所有按键。"

#: showmethekey-gtk/smtk-app-win.ui:199
#: showmethekey-gtk/smtk-app-win.ui:200
msgid "Width (px)"
msgstr "宽度(像素)"

#: showmethekey-gtk/smtk-app-win.ui:200
#: showmethekey-gtk/smtk-app-win.ui:201
msgid "Width of keys window."
msgstr "按键窗口的宽度。"

#: showmethekey-gtk/smtk-app-win.ui:215
#: showmethekey-gtk/smtk-app-win.ui:216
msgid "Height (px)"
msgstr "高度(像素)"

#: showmethekey-gtk/smtk-app-win.ui:216
#: showmethekey-gtk/smtk-app-win.ui:217
msgid "Height of keys window."
msgstr "按键窗口的高度。"

#: showmethekey-gtk/smtk-app-win.ui:232
#: showmethekey-gtk/smtk-app-win.ui:233
msgid "Keyboard"
msgstr "键盘"

#: showmethekey-gtk/smtk-app-win.ui:236
#: showmethekey-gtk/smtk-app-win.ui:237
msgid "Keymap"
msgstr "键位"

#: showmethekey-gtk/smtk-app-win.ui:237
#: showmethekey-gtk/smtk-app-win.ui:238
msgid "Choose your keyboard layout and variant."
msgstr "选择您的键盘布局和变体。"

Expand Down
45 changes: 21 additions & 24 deletions showmethekey-gtk/smtk-app-win.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "smtk-app.h"
#include "smtk-app-win.h"
#include "smtk-keys-win.h"
#include "smtk-keys-emitter.h"
#include "smtk-keys-mapper.h"
#include "smtk-keymap-list.h"

struct _SmtkAppWin {
Expand All @@ -30,6 +30,23 @@ struct _SmtkAppWin {
};
G_DEFINE_TYPE(SmtkAppWin, smtk_app_win, ADW_TYPE_APPLICATION_WINDOW)

static SmtkKeyMode smtk_app_win_get_mode(SmtkAppWin *win)
{
int mode_id =
adw_combo_row_get_selected(ADW_COMBO_ROW(win->mode_selector));
g_debug("Mode: %d.", mode_id);
switch (mode_id) {
case 0:
return SMTK_KEY_MODE_COMPOSED;
case 1:
return SMTK_KEY_MODE_RAW;
case 2:
return SMTK_KEY_MODE_COMPACT;
default:
return SMTK_KEY_MODE_COMPOSED;
}
}

static void smtk_app_win_enable(SmtkAppWin *win)
{
gtk_widget_set_sensitive(win->clickable_switch, false);
Expand Down Expand Up @@ -77,17 +94,7 @@ static void smtk_app_win_on_keys_win_switch_active(SmtkAppWin *win,
GTK_SWITCH(win->mouse_switch));
const bool draw_border = gtk_switch_get_active(
GTK_SWITCH(win->border_switch));
// See <https://docs.gtk.org/gtk4/class.StringObject.html>.
//
// We actually get a GObject from GtkDropDown, for
// GtkStringList as a model, the type of item is
// GtkStringObject.
int mode_id = adw_combo_row_get_selected(
ADW_COMBO_ROW(win->mode_selector));
g_debug("Mode: %d.", mode_id);
SmtkKeyMode mode = SMTK_KEY_MODE_COMPOSED;
if (mode_id == 1)
mode = SMTK_KEY_MODE_RAW;
SmtkKeyMode mode = smtk_app_win_get_mode(win);
int timeout = gtk_spin_button_get_value_as_int(
GTK_SPIN_BUTTON(win->timeout_entry));
g_debug("Timeout: %d.", timeout);
Expand Down Expand Up @@ -210,18 +217,8 @@ static void smtk_app_win_on_mode_selector_selected(SmtkAppWin *win,
if (win->keys_win == NULL)
return;

// See <https://docs.gtk.org/gtk4/class.StringObject.html>.
//
// We actually get a GObject from GtkDropDown, for GtkStringList as a
// model, the type of item is GtkStringObject.
int mode_id =
adw_combo_row_get_selected(ADW_COMBO_ROW(win->mode_selector));
g_debug("Mode: %d.", mode_id);
SmtkKeyMode mode = SMTK_KEY_MODE_COMPOSED;
if (mode_id == 1)
mode = SMTK_KEY_MODE_RAW;

smtk_keys_win_set_mode(SMTK_KEYS_WIN(win->keys_win), mode);
smtk_keys_win_set_mode(SMTK_KEYS_WIN(win->keys_win),
smtk_app_win_get_mode(win));
}

static void smtk_app_win_on_timeout_value(SmtkAppWin *win, GParamSpec *prop,
Expand Down
15 changes: 8 additions & 7 deletions showmethekey-gtk/smtk-app-win.ui
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@
<property name="activatable-widget">border_switch</property>
<child>
<object class="GtkSwitch" id="border_switch">
<property name="valign">center</property>
<property name="active">true</property>
<signal
name="notify::active"
handler="smtk_app_win_on_border_switch_active"
object="SmtkAppWin"
swapped="yes" />
<property name="valign">center</property>
<property name="active">true</property>
<signal
name="notify::active"
handler="smtk_app_win_on_border_switch_active"
object="SmtkAppWin"
swapped="yes" />
</object>
</child>
</object>
Expand All @@ -162,6 +162,7 @@
<items>
<item translatable="yes">Composed</item>
<item translatable="yes">Raw</item>
<item translatable="yes">Compact</item>
</items>
</object>
</property>
Expand Down
4 changes: 4 additions & 0 deletions showmethekey-gtk/smtk-keys-emitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ static gpointer poller_function(gpointer user_data)
case SMTK_KEY_MODE_RAW:
key = smtk_keys_mapper_get_raw(emitter->mapper, event);
break;
case SMTK_KEY_MODE_COMPACT:
key = smtk_keys_mapper_get_compact(emitter->mapper,
event);
break;
default:
// Should never be here.
g_warn_if_reached();
Expand Down
11 changes: 2 additions & 9 deletions showmethekey-gtk/smtk-keys-emitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@
#include <stdbool.h>
#include <glib-object.h>

#include "smtk-keys-mapper.h"

G_BEGIN_DECLS

#define SMTK_TYPE_KEYS_EMITTER smtk_keys_emitter_get_type()
G_DECLARE_FINAL_TYPE(SmtkKeysEmitter, smtk_keys_emitter, SMTK, KEYS_EMITTER,
GObject)

// It looks like glib-mkenums cannot make enums
// if clang-format make this in one line. But why???
// clang-format off
typedef enum {
SMTK_KEY_MODE_COMPOSED,
SMTK_KEY_MODE_RAW
} SmtkKeyMode;
// clang-format on

SmtkKeysEmitter *smtk_keys_emitter_new(bool show_shift, bool show_mouse,
SmtkKeyMode mode, const char *layout,
const char *variant, GError **error);
Expand Down

0 comments on commit 1031f4b

Please sign in to comment.