Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems when trying to handle GTK's OPEN signal #3

Closed
phntxx opened this issue Nov 28, 2022 · 2 comments
Closed

Problems when trying to handle GTK's OPEN signal #3

phntxx opened this issue Nov 28, 2022 · 2 comments

Comments

@phntxx
Copy link

phntxx commented Nov 28, 2022

Hi!

I'm fairly new to LISP and am currently using this library to create an image viewing program.
However, I've hit a roadblock when trying to handle the "open" signal.
According to the official GTK documentation, the type of files is GFile**, i.e. a pointer to an array of GFile elements.

I have tried the following:

(connect app "open"
  (lambda (app files n-files hint)
    ;; How do I use files here?
    (format T "~a~%" files)))
    ;; This prints "#.(SB-SYS:INT-SAP #X56334FB51140)"

I have not been able to figure out how to convert this into a LISP-usable list. Could you perhaps point me to a solution or documentation that might aid me in this?

@bohonghuang
Copy link
Owner

@phntxx It may boil down to the upstream library handling signal parameters incorrectly, for which I have opened issue #84. However, it's possible to address this problem via cffi currently. The solution may seem tricky, but it does work though:

(defpackage test-application-open
  (:use #:cl #:gtk4))

(in-package #:test-application-open)

(defun main ()
  (let ((app (make-application :application-id "org.bohonghuang.test-application-open"
                               :flags gio:+application-flags-handles-open+)))
    (connect app "activate" (lambda (app)
                              (gio:application-open app (list (gio:file-new-for-path "/home/coco24/.emacs.d/init.el")
                                                              (gio:file-new-for-path "/home/coco24/.emacs.d/local.el"))
                                                    "")))
    (connect app "open" (lambda (app files n-files hint)
                          (declare (ignore app hint))
                          (let ((files (loop :for i :below n-files
                                             :collect (make-instance 'gir::object-instance
                                                                     :class (gir:nget gio:*ns* "File")
                                                                     :this (cffi:mem-aref files :pointer i)))))
                            (print (mapcar #'gio:file-basename files))))) ;; This outputs ("init.el" "local.el")
    (gio:application-run app nil)))

@phntxx
Copy link
Author

phntxx commented Nov 29, 2022

Words cannot describe how thankful I am for your support in this. Thank you very much for the code example, I'll make sure to follow the progress of the issue in the upstream repository.

@phntxx phntxx closed this as completed Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants