Unable to move xlib window until app focus is changed - xlib

I create a single xlib window with the relevant code below. When I try to move the window, the cursor briefly changes to the grab cursor and I am unable to drag the window. However, if I change focus to another app, then return to my app, I am able to drag the window. I am new to xlib, and don't understand why I cannot drag the window after creation?
ms_display = XOpenDisplay(NULL);
int screen = DefaultScreen(ms_display);
Window rootWindow = RootWindow(ms_display,screen);
XSetWindowAttributes windowAttrib;
windowAttrib.background_pixel = 0;
windowAttrib.border_pixel = 0;
windowAttrib.colormap = XCreateColormap(ms_display,rootWindow,m_visual,AllocNone);
windowAttrib.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | PointerMotionMask | FocusChangeMask | EnterWindowMask | LeaveWindowMask;
int width = m_displayInfo.m_windowWidth;
int height = m_displayInfo.m_windowHeight;
unsigned long mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
ms_window = XCreateWindow(ms_display,rootWindow,0,0,width,height, 0, pVisInfo->depth,
InputOutput,pVisInfo->visual,mask,&windowAttrib);
XMapWindow(ms_display, ms_window);
XFlush(ms_display);
XSizeHints sizeHints;
sizeHints.x = (WidthOfScreen(ScreenOfDisplay(ms_display, screen)) - width) / 2;
sizeHints.y = (HeightOfScreen(ScreenOfDisplay(ms_display, screen)) - height) / 2;
sizeHints.width = width;
sizeHints.height = height;
sizeHints.flags = USPosition | USSize;
XSetWMSizeHints(ms_display,ms_window,&sizeHints,XInternAtom(ms_display,"WM_SIZE_HINTS",False));
XMoveResizeWindow(ms_display,ms_window,sizeHints.x,sizeHints.y,width,height);

I did run into a somewhat similar situation, where a newly created window would not get focus, receive mouse clicks or keyboard input until I called XSetWMHints(), even with a completely empty structure, e.g. the following was enough to get it working:
XWMHints xwmh;
xwmh.flags = 0;
XSetWMHints (m_display, m_window, &xwmh);
Weird, but it solved my problem.

Related

How to make Qt app visible on top on all screens?

How can I make a Qt window (keyboard launcher) show up on all spaces like e.g. Spotlight or iterm2 hotkey window.
I need to achieve the following: The launcher window has to be able to show up on every screen, even full screen apps, no dock item, not window switcher item, no main menu, this should work without any further implications (see below). Nice to have would be if the settings window would be still a regular window.
I tried to use qputenv("QT_MAC_DISABLE_FOREGROUND_APPLICATION_TRANSFORM", "1"); but using this the window accepts no keyboard input anymore. I also tried
WId windowObject = this->winId();
objc_object * nsviewObject = reinterpret_cast<objc_object *>(windowObject);
objc_object * nsWindowObject = ((objc_object* (*)(id, SEL))objc_msgSend)(nsviewObject, sel_registerName("window"));
int NSWindowCollectionBehaviorMoveToActiveSpace = 1 << 1;
int NSWindowCollectionBehaviorTransient = 1 << 3;
int NSWindowCollectionBehaviorFullScreenAuxiliary = 1 << 8;
int total = NSWindowCollectionBehaviorMoveToActiveSpace
|NSWindowCollectionBehaviorTransient
| NSWindowCollectionBehaviorFullScreenAuxiliary;
((objc_object* (*)(id, SEL, int))objc_msgSend)(nsWindowObject, sel_registerName("setCollectionBehavior:"), total);
but this way the window does not show over fullscreen apps and also has still a dock item and main menu.

cpp simulating mouseclick also moves the cursor

I have this following cpp script:
INPUT Inputs[3] = { 0 };
Inputs[0].type = INPUT_MOUSE;
Inputs[0].mi.dx = 0;
Inputs[0].mi.dy = 0;
Inputs[0].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
Inputs[1].type = INPUT_MOUSE;
Inputs[1].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
Inputs[2].type = INPUT_MOUSE;
Inputs[2].mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(3, Inputs, sizeof(INPUT));
which should simulate a mouse press, and it works, but it also always moves the cursor to a specific position, even if I dont have this
Inputs[0].mi.dx = 0;
Inputs[0].mi.dy = 0;
part. I want it just to click but not moving the cursor
The mouse cursor moves because you requested the mouse cursor to move by setting the MOUSEEVENTF_MOVE flag in the first INPUT structure.
If you don't want the mouse to move, remove the entire first INPUT structure. If, on the other hand, you want to inject a mouse move event, but not actually move the mouse, remove the MOUSEEVENTF_ABSOLUTE flag.

how to prevent drop-down menu disappearing after adding transparant layer

I have built an application that adds on-screen application help in context of an windows desktop application. When the object of help relates to a drop-down menu I am encountering problems that the drop-down menu disappears when adding a transparant overlay. What attributes should I use to keep the drop-down menu visible? Please see the following code where I define the window to draw on top of the current foreground window:
exStyle = win32con.WS_EX_COMPOSITED | win32con.WS_EX_LAYERED | win32con.WS_EX_NOACTIVATE | win32con.WS_EX_TOPMOST | win32con.WS_EX_TRANSPARENT
style = win32con.WS_DISABLED | win32con.WS_POPUP | win32con.WS_VISIBLE
oWindow = win32gui.CreateWindowEx(
exStyle,
owndClassAtom,
'Per52Overlay', # WindowName
style,
winX1, # x
winY1, # y
#win32api.GetSystemMetrics(win32con.SM_CXSCREEN), # width
#win32api.GetSystemMetrics(win32con.SM_CYSCREEN), # height
winWidth, #width
winHeight, #height
hwnd, # hWndParent
None, # hMenu
hInstance,
None # lpParam
)
oWindowHndl = oWindow
# //msdn.microsoft.com/en-us/library/windows/desktop/ms633540(v=vs.85).aspx
win32gui.SetLayeredWindowAttributes(oWindow, 0x00ffffff, 255, win32con.LWA_COLORKEY | win32con.LWA_ALPHA)
hdc, paintStruct = win32gui.BeginPaint(oWindow)
hPen = win32gui.CreatePen(win32con.PS_SOLID,3, win32api.RGB(0,255,0))
win32gui.SelectObject(hdc, hPen)
win32gui.Rectangle(hdc, objX1, objY1, objX2, objY2)
win32gui.EndPaint(oWindow, paintStruct)
win32gui.SetWindowPos(oWindow, win32con.HWND_TOPMOST, winX1, winY1, winWidth, winHeight, win32con.SWP_DRAWFRAME | win32con.SWP_NOACTIVATE | win32con.SWP_NOSIZE | win32con.SWP_SHOWWINDOW)
win32gui.ShowWindow(oWindow, win32con.SW_SHOW)
win32gui.UpdateWindow(oWindow)
At some stage the window shall be drawn:
winCrd = win32gui.GetWindowRect(activeWindow)
objCrd = (startX, startY, endX, endY)
drawOnApp(activeWindow, winCrd, objCrd, message)
win32gui.BringWindowToTop(activeWindow)
My guess is that I am doing something wrong with the attributes in combination with what window should be on top / activated / to foreground etc. etc.
Can you give me some clues to dive more in this matter?

Firefox Extension: Get page offset inside main Firefox window

Is it possible to get the offset of the page/window in the main Firefox window from inside an extension? To make things clear: It's not a DOM related question, I think it's an XPCOM question. I'll try to give an idea of what I need:
[Firefox]------------------------------------------------[ - # X ]
| Tab1 Title | Tab2 Title | |
------------------------------------------------------------------
| http://address.com/ | > |
------------------------------------------------------------------
* <- (X, Y) Offset of the page inside the main Firefox window |
| |
| |
| Page contents... |
| |
. .
. .
. .
Examples of basic bootstrap:
https://gist.github.com/Noitidart/9025999
This one has some extra stuff like the Services module imported, you need to import this module to use Services.wm; But to import Services you need the component Cu. see the top of the gist here:
https://gist.github.com/Noitidart/9026493
Now Services.wm.getMostRecentWindow('navigator:browser') gets only one window. If you want to iterate through all browser windows copy paste this. I include how to iterate over each each HTML window in the tabs in each browser as well.
const {interfaces: Ci, utils: Cu} = Components;
Cu.import('resource://gre/modules/Services.jsm');
//on this line can do Services.wm.getMostRecentBrowser('navigator:browser').gBrowser.contentDocument to get the currently focused tab document of the most recent browser window OR or continue to the loop below and it will do all windows and all tabs.
let XULWindows = Services.wm.getXULWindowEnumerator(null);
while (XULWindows.hasMoreElements()) {
let aXULWindow = XULWindows.getNext();
let aDOMWindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
//aDOMWindow.gBrowser can be accesed here
//to go through all tabs in the gBrowser do this:
if (aDOMWindow.gBrowser && aDOMWindow.gBrowser.tabContainer) {
var tabs = aDOMWindow.gBrowser.tabContainer.childNodes;
for (var i = 0; i < tabs.length; i++) {
Cu.reportError('DOING tab: ' + i);
var tabBrowser = tabs[i].linkedBrowser;
var aHTMLWindow = tabBrowser.contentWindow;
var aHTMLDocument = aHTMLWindow.document;
}
}
}
yes run this code to get the offset, you mean page offset right?
gBrowser.contentDocument.getBoundingClientRect().left
you just access the dom of the main page and you can do anything there

Creating X11 window to span multiple displays

I'm having the exact problem described here. How to make X11 window span multiple monitors
I have six monitors and am trying to create a window larger than the size of one of the monitors. It keeps getting resized by the window manager.
Apologize if I should post within that thread, the etiquette is not clear to me.
Anhow, I do the following in my code:
/* Pass some information along to the window manager to size the window */
sizeHints.flags = USSize; // | PMinSize;
sizeHints.width = sizeHints.base_width = width;
sizeHints.height = sizeHints.base_height = height;
// sizeHints.min_width = width;
// sizeHints.min_height = height;
// sizeHints.max_width = mScreenWidth;
// sizeHints.max_height = mScreenHeight;
if (geometry->x != DONT_CARE && geometry->y != DONT_CARE) {
sizeHints.x = geometry->x;
sizeHints.y = geometry->y;
sizeHints.flags |= USPosition;
}
XSetNormalHints(mDisplay, mWindow, &sizeHints);
SetTitle(suggestedName);
XSetStandardProperties(mDisplay, mWindow,
suggestedName.toAscii(), suggestedName.toAscii(),
None, (char **)NULL, 0, &sizeHints);
/* Bring it up; then wait for it to actually get here. */
XMapWindow(mDisplay, mWindow);
The problem I'm having is that if I set min_width and min_height, the user cannot resize the window, which is not what I want. But if I don't, then when I do any X11 call later, such as
XGetWindowAttributes(mDisplay, mWindow, &win_attributes);
the window manager resizes my window to fit into one monitor instead of being larger than the monitor. I cannot just get a window of the desired size for some reason. Note that WidthOfScreen and HeightOfScreen give me the combined width and height of all monitors as expected.
Can anyone help? I hope I'm explaining myself clearly enough.

Resources