Skip to content

Instantly share code, notes, and snippets.

@Noitidart
Last active November 5, 2016 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Noitidart/80d00ae9147f1ab917099d43fbb012e9 to your computer and use it in GitHub Desktop.
Save Noitidart/80d00ae9147f1ab917099d43fbb012e9 to your computer and use it in GitHub Desktop.
trying to set window so it has stays on all screens, this is
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