Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 4 files changed
  • 0 comments
  • 1 contributor
BIN  ext/test.dylib
Binary file not shown
6  scratch-jvm.clj
@@ -35,4 +35,8 @@
35 35
 ;;   }
36 36
 ;;  }
37 37
 
38  
-;; Interception.DestroyContext(context);
  38
+;; Interception.DestroyContext(context);
  39
+
  40
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  41
+
  42
+(System/setProperty "jna.library.path" "ext")
56  src/clj/kchordr/core.clj
... ...
@@ -1,9 +1,9 @@
1 1
 (ns kchordr.core)
2 2
 
3 3
 (def ^{:private true
4  
-       :doc "Map of keys to classes. Absense from this list means it's a normal key."}
  4
+       :doc "Map of keys to classes. Absence from this list means it's a normal key."}
5 5
   key-classes
6  
-  {:j :modifier-alias})
  6
+  {:j [:modifier-alias :lshift]})
7 7
 
8 8
 (defn key-state
9 9
   "Returns a new key-state object."
@@ -20,8 +20,8 @@
20 20
 ;;       )
21 21
 ;;   )
22 22
 
23  
-(defmulti next-state
24  
-  "Given the current state, a Return a new key state ")
  23
+;; (defmulti next-state
  24
+;;   "Given the current state, a Return a new key state ")
25 25
 
26 26
 (def ^{:private true
27 27
        :doc "Maps the current state a key class and a direction to a
@@ -29,18 +29,52 @@
29 29
   state-transitions
30 30
   {[:ground :normal :up] :ground
31 31
    [:ground :normal :dn] :ground
32  
-   [:ground :modifier :dn] :mod-pending
33  
-   [:ground :modifier :up] :error})
  32
+   [:ground :modifier-alias :dn] :mod-pending
  33
+   [:ground :modifier-alias :up] :error})
  34
+
  35
+;; State looks something like
  36
+;; {:to-send [] :keystate {:j :pending, :k :lcontrol}}
  37
+
  38
+(defn pending-modifier?
  39
+  "Return true when the key state contains a pending modifier key."
  40
+  [state]
  41
+  (some #(= :pending %) (vals (:keystate state))))
  42
+
  43
+(defn pending-modifier-downs
  44
+  "Return a seq of keypresses for the pending modifiers."
  45
+  [state]
  46
+  (throw (NotImplmentedException.)))
  47
+
  48
+;; {:j :pending :k :lcontrol} => {:j :lshift :k :lcontrol}
  49
+(defn decide-pending-modifiers
  50
+  "Return a sequence of key events for pending modifiers, deciding
  51
+  them to be their aliased equivalents."
  52
+  [state]
  53
+  (into {} (map (fn [[k v]] (if (= :pending v)
  54
+                              [k (second (k (key-classes)))]
  55
+                              [k v])))))
  56
+
34 57
 
35 58
 (defn process
36 59
   "Given the current key state and a key event, return an updated key
37 60
   state."
38 61
   [state key direction]
39  
-  (let [cls (get key-classes key :normal)
40  
-        new-state (get state-transitions [cls direction])]
41  
-    (if (= cls :modifier)
42  
-      state
43  
-      (update-in state [:to-send] #(conj % [key direction])))))
  62
+  (let [cls (get key-classes key :normal)]
  63
+    (cond
  64
+     (and (= cls :modifier-alias) (= :dn direction))
  65
+     (update-in state [:keystate key] (constantly :pending))
  66
+
  67
+     (and (pending-modifier? state)
  68
+          (regular-keydown? key direction))
  69
+     (assoc state
  70
+       :to-send (concat (:to-send state)
  71
+                        (pending-modifier-downs state)
  72
+                        [key :dn])
  73
+       :keystate (apply assoc (:keystate state)
  74
+                   (decide-pending-modifiers state)))
  75
+
  76
+     :else
  77
+     (update-in state [:to-send] #(conj % [key direction])))))
44 78
 
45 79
 (defn to-send
46 80
   "Given a key state, return any pending key events, in the form of
17  src/java/interception/TestLibrary.java
... ...
@@ -0,0 +1,17 @@
  1
+package interception;
  2
+import com.ochafik.lang.jnaerator.runtime.LibraryExtractor;
  3
+import com.ochafik.lang.jnaerator.runtime.MangledFunctionMapper;
  4
+import com.sun.jna.Callback;
  5
+import com.sun.jna.Library;
  6
+import com.sun.jna.Native;
  7
+import com.sun.jna.NativeLibrary;
  8
+import com.sun.jna.NativeLong;
  9
+import com.sun.jna.Pointer;
  10
+
  11
+public interface TestLibrary extends Library {
  12
+    public static final String JNA_LIBRARY_NAME = LibraryExtractor.getLibraryPath("test", true, TestLibrary.class);
  13
+    public static final NativeLibrary JNA_NATIVE_LIB = NativeLibrary.getInstance(TestLibrary.JNA_LIBRARY_NAME, MangledFunctionMapper.DEFAULT_OPTIONS);
  14
+    public static final TestLibrary INSTANCE = (TestLibrary)Native.loadLibrary(TestLibrary.JNA_LIBRARY_NAME, TestLibrary.class, MangledFunctionMapper.DEFAULT_OPTIONS);
  15
+
  16
+    int DoSomething(int x);
  17
+}

No commit comments for this range

Something went wrong with that request. Please try again.