Skip to content

Commit

Permalink
Merge pull request #59 from metacoma/fvwm-dock
Browse files Browse the repository at this point in the history
Fvwm dock
  • Loading branch information
metacoma authored Dec 1, 2023
2 parents a481528 + 966fdb2 commit d64224f
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 8 deletions.
34 changes: 28 additions & 6 deletions files/fvwm/rabbitmq-event-dock.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import base64
from collections import deque

FVWM_RESOURCES_PATH=os.getenv('FVWM_RESOURCES_PATH')

class FixedSizeQueue:
def __init__(self, max_size):
self.queue = deque(maxlen=max_size)
Expand Down Expand Up @@ -49,26 +51,46 @@ def updateFvwmDock():
*FvwmButtons: Padding 2 2
"""
fvwmBody = ""
i = 0
for element in my_queue.get_elements():
decoded_string = base64.b64decode(element['event']['clipboard']).decode("utf-8")
fvwmBody = fvwmBody + f"""
*FvwmButtons: (Title {decoded_string[:15]}, Icon /tmp/buttons/icon-clipboard-512.png, Action Resize)
"""
if element['event']['type'] == 'clipboard':
decoded_string = base64.b64decode(element['payload']['clipboard']).decode("utf-8")
with open(f"/tmp/buffer{i}.txt", 'w') as file:
file.write(decoded_string)
button_title = decoded_string[0:15].lstrip().replace('"', '\\"')
fvwmBody = fvwmBody + f"""
*FvwmButtons: (Title "{button_title}", Icon {FVWM_RESOURCES_PATH}/icons/copy.png, Action exec exec xterm -e "vim -R /tmp/buffer{i}.txt")
"""
if element['event']['type'] == 'mindwm-io-document-event':
input_cmd = element['payload']['input']
output = element['payload']['output']
with open(f"/tmp/buffer{i}.txt", 'w') as file:
file.write(input_cmd + "\n")
file.write(output)
button_title = input_cmd[0:15].lstrip().replace('"', '\\"')
fvwmBody = fvwmBody + f"""
*FvwmButtons: (Title "{button_title}", Icon {FVWM_RESOURCES_PATH}/icons/mindwm-io-document.png, Action exec exec xterm -e "vim -R /tmp/buffer{i}.txt")
"""
i = i + 1
fvwmDataEnd = """
KillModule FvwmButtons FvwmButtons
Module FvwmButtons FvwmButtons
Style FvwmButtons NoTitle
"""

fvwmData = fvwmDataHead + fvwmBody + fvwmDataEnd
print(fvwmData)

process = subprocess.Popen(["bash", "/home/bebebeko/mindwm/compiled/fvwm/bin/fvwm_send.sh"], stdin=subprocess.PIPE)
process.communicate(input = fvwmData.encode())
process.wait()

def callback(ch, method, properties, body):
global idx
pprint.pprint(body.decode())
print(json.loads(body.decode())['event'])
j = json.loads(body.decode())
pprint.pprint(j['payload'])
#pprint.pprint(body.decode())
#print(json.loads(body.decode())['event'])
my_queue.add_element(json.loads(body.decode()))
updateFvwmDock()

Expand Down
2 changes: 2 additions & 0 deletions files/fvwm/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pika
libtmux
1 change: 1 addition & 0 deletions files/neomodel/context-graph-model.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def callback(ch, method, properties, body):


pane.getActiveIoContext().io_document.connect(io_document)
rabbitmq_channel.basic_publish(exchange='mindwm-document', routing_key='mindwm-document', body=json.dumps(data))

rabbitmq_channel.basic_consume(queue=queue_name, on_message_callback=callback, auto_ack=True)
print("Waiting for messages. To exit, press Ctrl+C")
Expand Down
Binary file added files/resources/fvwm/icons/copy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added files/resources/fvwm/icons/mindwm-io-document.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions inventory/classes/util/files.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
parameters:
kapitan:
compile:
- input_paths:
- lib/jsonnet/files.jsonnet
output_path: .
input_type: jsonnet
output_type: plain

41 changes: 39 additions & 2 deletions inventory/targets/fvwm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ classes:
- common
- tmuxinator
- tmuxinator.kapitan
- util.files
- vector.common
- tmux.pipe-stream
parameters:
target_name: fvwm

fvwm_resources_path: "fvwm_resources"

bash:
functions:
aosd_show: |
Expand All @@ -23,7 +27,9 @@ parameters:
cat<<EOF | jq | curl -X POST -d@- http://`minikube ip`:${vector_http_server_port}/event
{
"event": {
"type": "clipboard",
"type": "clipboard"
},
"payload": {
"clipboard_type": "$clipboard_type",
"clipboard": "$(xclip -out -selection $clipboard_type | base64 -w0)"
}
Expand All @@ -43,12 +49,23 @@ parameters:
clipnotify_bin: ${clipnotify_path}/clipnotify

kapitan:
compile:
- input_type: copy
input_paths:
- files/resources/fvwm
# output_path: ${fvwm_resources_path}
output_path: fvwm_resources
dependencies:
- source: https://github.com/cdown/clipnotify
type: git
output_path: ${clipnotify_path}
ref: 25ba143c7da8ae0f196cb0db2797d30e6d04e15c

files:
- path: fvwm_config
body: |
Module FvwmMFL
tmuxinator:
windows:
fvwm:
Expand All @@ -72,9 +89,29 @@ parameters:
- clipnotify_secondary
-
- clipnotify_clipboard
fvwm-dock:
pre:
- cd ${kapitan_root}/files/fvwm
- . venv/bin/activate

panes:
-
- export FVWM_RESOURCES_PATH="${compiled_dir}/${fvwm_resources_path}"
- |
while :; do
python3 rabbitmq-event-dock.py
sleep 5
done
-
-
aosd-debug:
panes:
-
- cd ${kapitan_root}/files/fvwm/
- . venv/bin/activate
- python3 ./rabbitmq-osd-debug.py
- |
while :; do
python3 ./rabbitmq-osd-debug.py
sleep 5
done
11 changes: 11 additions & 0 deletions inventory/targets/vector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ parameters:
#

transforms:
mindwm-document-event:
type: "remap"
inputs:
- mindwm-document
source: |
msg, err = parse_json(.message)
.event.type = "mindwm-io-document-event"
.payload = .message
del(.message)
# kafka-io-context-to-elasticsearch:
# type: "remap"
# inputs:
Expand Down Expand Up @@ -320,6 +330,7 @@ parameters:
events:
type: amqp
inputs:
- mindwm-document-event
- http_server
connection:
connection_string: "amqp://${rabbitmq_user}:${rabbitmq_password}@${rabbitmq_release_name}.${rabbitmq_namespace}:5672/%2f?timeout=10"
Expand Down
10 changes: 10 additions & 0 deletions lib/jsonnet/files.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
local kap = import "lib/kapitan.libjsonnet";
local inventory = kap.inventory();
local p = inventory.parameters;

{
[file.path]: kap.jinja2_template("templates/file", {
data: file.body
}) for file in p.files
}

1 change: 1 addition & 0 deletions templates/file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ data }}

0 comments on commit d64224f

Please sign in to comment.