From b1e9b313f6810afbadde0f8079326ecf04c89817 Mon Sep 17 00:00:00 2001

From: =?UTF-8?q?Jaakko=20Ker=C3=A4nen?= jaakko.keranen@iki.fi

Date: Fri, 30 Oct 2020 09:08:09 +0200

Subject: [PATCH 1/1] Added a key binding mechanism

The document scrolling keys are now handled via bindings.


CMakeLists.txt | 1 +

src/app.c | 10 ++-

src/ui/documentwidget.c | 75 +++++++++----------

src/ui/keys.c | 154 ++++++++++++++++++++++++++++++++++++++++

src/ui/keys.h | 17 ++++-

5 files changed, 215 insertions(+), 42 deletions(-)

create mode 100644 src/ui/keys.c

diff --git a/CMakeLists.txt b/CMakeLists.txt

index 20def6a7..7d73956d 100644

--- a/CMakeLists.txt

+++ b/CMakeLists.txt

@@ -135,6 +135,7 @@ set (SOURCES

 src/ui/listwidget.h

 src/ui/lookupwidget.c

 src/ui/lookupwidget.h

 src/ui/keys.h

 src/ui/metrics.c

 src/ui/metrics.h

diff --git a/src/app.c b/src/app.c

index e4c31eaf..10f5f0d2 100644

--- a/src/app.c

+++ b/src/app.c

@@ -32,6 +32,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */

#include "ui/command.h"

#include "ui/documentwidget.h"

#include "ui/inputwidget.h"

+#include "ui/keys.h"

#include "ui/labelwidget.h"

#include "ui/sidebarwidget.h"

#include "ui/text.h"

@@ -357,9 +358,11 @@ static void init_App_(iApp *d, int argc, char **argv) {

#if defined (iPlatformApple)

 setupApplication_MacOS();

#endif

 loadPrefs_App_(d);

 load_Visited(d->visited, dataDir_App_);

 if (isFirstRun) {

     /* Create the default bookmarks for a quick start. */

     add_Bookmarks(d->bookmarks,

@@ -426,6 +429,7 @@ static void init_App_(iApp *d, int argc, char **argv) {

static void deinit_App(iApp *d) {

 saveState_App_(d);

 savePrefs_App_(d);

 deinit_Prefs(&d->prefs);

 save_Bookmarks(d->bookmarks, dataDir_App_);

@@ -501,6 +505,10 @@ void processEvents_App(enum iAppEventMode eventMode) {

         }

         default: {

             iBool wasUsed = processEvent_Window(d->window, &ev);

             if (ev.type == SDL_USEREVENT && ev.user.code == command_UserEventCode) {

#if defined (iPlatformApple) && !defined (iPlatformIOS)

                 handleCommand_MacOS(command_UserEvent(&ev));

diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c

index 5c6780d1..a2bea17b 100644

--- a/src/ui/documentwidget.c

+++ b/src/ui/documentwidget.c

@@ -1536,7 +1536,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)

     updateVisible_DocumentWidget_(d);

     return iTrue;

 }

     if (argLabel_Command(cmd, "repeat")) {

         /* TODO: Adjust scroll animation to be linear during repeated scroll? */

     }

@@ -1547,6 +1547,40 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)

                                  smoothDuration_DocumentWidget_);

     return iTrue;

 }

+#if 0

+#endif

 else if (equal_Command(cmd, "document.goto") && document_App() == d) {

     const iRangecc heading = range_Command(cmd, "heading");

     if (heading.start) {

@@ -1790,45 +1824,6 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e

                 refresh_Widget(w);

             }

             break;

-// if (!d->smoothContinue) {

-// d->smoothContinue = iTrue;

-// }

-// else return iTrue;

#if 1

         case SDLK_KP_1:

         case '`': {

diff --git a/src/ui/keys.c b/src/ui/keys.c

new file mode 100644

index 00000000..d46d20bf

--- /dev/null

+++ b/src/ui/keys.c

@@ -0,0 +1,154 @@

+/* Copyright 2020 Jaakko Keränen jaakko.keranen@iki.fi

+Redistribution and use in source and binary forms, with or without

+modification, are permitted provided that the following conditions are met:

+1. Redistributions of source code must retain the above copyright notice, this

+2. Redistributions in binary form must reproduce the above copyright notice,

+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND

+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED

+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE

+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR

+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES

+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;

+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON

+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS

+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */

+#include "keys.h"

+#include "util.h"

+#include "app.h"

+#include <the_Foundation/sortedarray.h>

+iDeclareType(Keys)

+iDeclareType(Binding)

+struct Impl_Binding {

+};

+static int cmp_Binding_(const void *a, const void *b) {

+}

+struct Impl_Keys {

+};

+static iKeys keys_;

+static void clear_Keys_(iKeys *d) {

+}

+static void bindDefaults_(void) {

+}

+static iBinding *find_Keys_(iKeys *d, int key, int mods) {

+}

+static iBinding *findCommand_Keys_(iKeys *d, const char *command) {

+}

+/----------------------------------------------------------------------------------------------/

+void init_Keys(void) {

+}

+void deinit_Keys(void) {

+}

+void load_Keys(const char *saveDir) {

+}

+void save_Keys(const char *saveDir) {

+}

+void bind_Keys(const char *command, int key, int mods) {

+}

+void setLabel_Keys(const char *command, const char *label) {

+}

+//const iString *label_Keys(const char *command) {

+//}

+//const char *shortcutLabel_Keys(const char *command) {}

+iBool processEvent_Keys(const SDL_Event *ev) {

+}

diff --git a/src/ui/keys.h b/src/ui/keys.h

index a9b13df3..157ddea5 100644

--- a/src/ui/keys.h

+++ b/src/ui/keys.h

@@ -22,7 +22,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */

#pragma once

-#include <the_Foundation/defs.h>

+#include <the_Foundation/string.h>

+#include <SDL_events.h>

#if defined (iPlatformApple)

define reload_KeyShortcut SDLK_r, KMOD_PRIMARY

@@ -41,3 +42,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */

define byWord_KeyModifier KMOD_CTRL

define byLine_KeyModifier 0

#endif

+void init_Keys (void);

+void deinit_Keys (void);

+void load_Keys (const char *saveDir);

+void save_Keys (const char *saveDir);

+void bind_Keys (const char *command, int key, int mods);

+void setLabel_Keys (const char *command, const char *label);

+//const iString * label_Keys (const char *command);

+//const char * shortcutLabel_Keys (const char *command);

+iBool processEvent_Keys (const SDL_Event *);

--

2.25.1

Proxy Information
Original URL
gemini://git.skyjake.fi/lagrange/work%2Fv1.7/patch/b1e9b313f6810afbadde0f8079326ecf04c89817.patch
Status Code
Success (20)
Meta
text/plain
Capsule Response Time
228.026802 milliseconds
Gemini-to-HTML Time
5.239556 milliseconds

This content has been proxied by September (ba2dc).