Cu.import('resource://gre/modules/ctypes.jsm'); | |
var objc = ctypes.open(ctypes.libraryName('objc')); | |
// BASIC TYPES | |
var CHAR = ctypes.char; | |
var ID = ctypes.voidptr_t; | |
var SEL = ctypes.voidptr_t; | |
var BOOL = ctypes.signed_char; | |
var NSUINTEGER = ctypes.unsigned_long; | |
// COMMON FUNCTIONS | |
var objc_getClass = objc.declare('objc_getClass', ctypes.default_abi, ID, CHAR.ptr); | |
var objc_msgSend = objc.declare('objc_msgSend', ctypes.default_abi, ID, ID, SEL, '...'); | |
var sel_registerName = objc.declare('sel_registerName', ctypes.default_abi, SEL, CHAR.ptr); | |
function getNativeHandlePtrStr(domWindow) { | |
const baseWindow = domWindow.QueryInterface(Ci.nsIInterfaceRequestor) | |
.getInterface(Ci.nsIWebNavigation) | |
.QueryInterface(Ci.nsIDocShellTreeItem) | |
.treeOwner | |
.QueryInterface(Ci.nsIInterfaceRequestor) | |
.getInterface(Ci.nsIBaseWindow); | |
return baseWindow.nativeHandle; | |
} | |
function main() { | |
const NSWindowCollectionBehaviorDefault = 0; | |
const NSWindowCollectionBehaviorCanJoinAllSpaces = 1 << 0; | |
const NSWindowCollectionBehaviorMoveToActiveSpace = 1 << 1; | |
const NSWindowCollectionBehaviorManaged = 1 << 2 | |
const NSWindowCollectionBehaviorTransient = 1 << 3 | |
const NSWindowCollectionBehaviorStationary = 1 << 4 | |
const NSWindowCollectionBehaviorParticipatesInCycle = 1 << 5 | |
const NSWindowCollectionBehaviorIgnoresCycle = 1 << 6 | |
const NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7 | |
const NSWindowCollectionBehaviorFullScreenAllowsTiling = 1 << 11 | |
const NSWindowCollectionBehaviorFullScreenDisallowsTiling = 1 << 12 | |
var winptrstr = getNativeHandlePtrStr(Services.wm.getMostRecentWindow('navigator:browser')); | |
var winptr = ctypes.voidptr_t(ctypes.UInt64(winptrstr)); | |
var collectionBehavior = sel_registerName('collectionBehavior'); | |
var behavior = objc_msgSend(winptr, collectionBehavior); | |
behavior = ctypes.cast(behavior, ctypes.int).value; | |
console.log('behavior:', behavior.toString()); | |
behavior |= NSWindowCollectionBehaviorCanJoinAllSpaces; | |
console.log('behavior:', behavior.toString()); | |
var setCollectionBehavior = sel_registerName('setCollectionBehavior:'); | |
var rez = objc_msgSend(winptr, setCollectionBehavior, ctypes.unsigned_long(behavior)); | |
console.log('rez:', rez.toString()); | |
var setLevel = sel_registerName('setLevel:'); | |
var rez = objc_msgSend(winptr, setLevel, ctypes.unsigned_long(21)); | |
} | |
try { | |
main(); | |
} catch(ex) { | |
console.error('Exception Occoured:', ex); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment