-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathos-resources.lisp
50 lines (46 loc) · 2.1 KB
/
os-resources.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(in-package #:org.shirakumo.fraf.trial)
(defun system-username ()
(or #+windows
(cffi:with-foreign-objects ((size :ulong)
(name :uint16 128))
(unless (cffi:foreign-library-loaded-p 'org.shirakumo.machine-state::secur32)
(cffi:load-foreign-library 'org.shirakumo.machine-state::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))))))
#+nx
(cffi:with-foreign-object (nick :char 33)
(when (cffi:foreign-funcall "nxgl_username" :pointer nick :int 33 :bool)
(cffi:foreign-string-to-lisp nick :max-chars 33)))
#+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)
(org.shirakumo.open-with:open url)))
(defun open-in-file-manager (path)
(org.shirakumo.open-with:open (pathname path)))
(defun rename-thread (name)
(ignore-errors
#+windows
(com:with-wstring (name name)
(cffi:foreign-funcall "SetThreadDescription"
:size (cffi:foreign-funcall "GetCurrentThread" :size)
:string name
:size))
#+nx
(cffi:foreign-funcall "nxgl_set_thread_name"
:pointer (cffi:null-pointer)
:string name
:int)
#+unix
(cffi:foreign-funcall "pthread_setname_np"
:size (cffi:foreign-funcall "pthread_self" :size)
:string name
:int)))