Skip to content

Commit

Permalink
Shuffle some more stuff around, prepare some more for NX.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed Aug 31, 2023
1 parent b9e97ff commit 294718d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 34 deletions.
3 changes: 3 additions & 0 deletions backends/nxgl/context.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@
(unwind-protect (finalize main)
(nxgl:shutdown)))))

(defun system-username ()
(nxgl:username))

(defmacro define-callback (name args &body body)
`(cffi:defcallback ,name :void ((context :pointer) (user :pointer) ,@args)
(declare (ignore context user))
Expand Down
36 changes: 7 additions & 29 deletions main.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,13 @@
(setf +main+ NIL)
(setf +input-source+ :keyboard))

#+windows
(cffi:define-foreign-library secur32
(T (:default "Secur32")))

(flet ((fallback-username ()
(or
#+windows
(cffi:with-foreign-objects ((size :ulong)
(name :uint16 128))
(unless (cffi:foreign-library-loaded-p 'secur32)
(cffi:load-foreign-library 'secur32))
(setf (cffi:mem-ref size :ulong) 128)
;; Constant 3 here specifies a "display name".
(cond ((< 0 (cffi:foreign-funcall "GetUserNameExW" :int 13 :pointer name :pointer size :int))
(org.shirakumo.com-on:wstring->string name (cffi:mem-ref size :ulong)))
(T
(setf (cffi:mem-ref size :ulong) 128)
(when (< 0 (cffi:foreign-funcall "GetUserNameW" :pointer name :pointer size :int))
(org.shirakumo.com-on:wstring->string name (cffi:mem-ref size :ulong))))))
#+unix
(cffi:foreign-funcall "getlogin" :string)
(pathname-utils:directory-name (user-homedir-pathname)))))
(defmethod username ((main main))
(fallback-username))

(defmethod username ((default (eql T)))
(if +main+
(username +main+)
(fallback-username))))
(defmethod username ((main main))
(system-username))

(defmethod username ((default (eql T)))
(if +main+
(username +main+)
(system-username)))

(defmethod scene ((default (eql T)))
(scene +main+))
Expand Down
22 changes: 22 additions & 0 deletions os-resources.lisp
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
(in-package #:org.shirakumo.fraf.trial)

#+windows
(cffi:define-foreign-library secur32
(T (:default "Secur32")))

(defun system-username ()
(or #+windows
(cffi:with-foreign-objects ((size :ulong)
(name :uint16 128))
(unless (cffi:foreign-library-loaded-p 'secur32)
(cffi:load-foreign-library 'secur32))
(setf (cffi:mem-ref size :ulong) 128)
;; Constant 3 here specifies a "display name".
(cond ((< 0 (cffi:foreign-funcall "GetUserNameExW" :int 13 :pointer name :pointer size :int))
(org.shirakumo.com-on:wstring->string name (cffi:mem-ref size :ulong)))
(T
(setf (cffi:mem-ref size :ulong) 128)
(when (< 0 (cffi:foreign-funcall "GetUserNameW" :pointer name :pointer size :int))
(org.shirakumo.com-on:wstring->string name (cffi:mem-ref size :ulong))))))
#+unix
(cffi:foreign-funcall "getlogin" :string)
(pathname-utils:directory-name (user-homedir-pathname))))

(defvar *open-in-browser-hook* (constantly NIL))
(defun open-in-browser (url)
(or (funcall *open-in-browser-hook* url)
Expand Down
8 changes: 5 additions & 3 deletions package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,11 @@
#:update-action-mappings)
;; os-resources.lisp
(:export
#:*open-in-browser-hook*
#:system-username
#:open-in-browser
#:open-in-file-manager
#:rename-thread
#:cpu-time
#:io-bytes
#:gpu-room
Expand Down Expand Up @@ -1579,8 +1584,6 @@
#:finalize
#:gl-property
#:current-time
#:open-in-browser
#:open-in-file-manager
#:kw
#:enlist
#:unlist
Expand All @@ -1604,7 +1607,6 @@
#:logfile
#:config-directory
#:standalone-logging-handler
#:rename-thread
#:make-thread
#:with-thread
#:thread-did-not-exit
Expand Down
4 changes: 2 additions & 2 deletions toolkit.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,10 @@
(defun config-directory (&rest app-path)
(apply #'pathname-utils:subdirectory
(or (envvar-directory "TRIAL_CONFIG_HOME")
#+(or windows win32)
#+windows
(or (envvar-directory "AppData")
(pathname-utils:subdirectory (user-homedir-pathname) "AppData" "Roaming"))
#-(or windows win32)
#+nx #p"save:/"
(or (envvar-directory "XDG_CONFIG_HOME")
(pathname-utils:subdirectory (user-homedir-pathname) ".config")))
(or app-path (list +app-vendor+ +app-system+))))
Expand Down

0 comments on commit 294718d

Please sign in to comment.