I've created simple application that monitors X11's _NET_CLIENT_LIST. It prints me info when window ( including conky,tint2,... ) opens or closes. It works fine, except when i create menu (RMB-click or front Menu-Bar) it won't print anything - that means they aren't new windows, but they can be drawn out of window they are created from, so what is it?
I'd like create my own context menu in my app and i don't want to use any toolkit ( GTK, QT,... ). So i need to know how do they work.
Adding another answer because the old one is for a different question entirely :)
Pop-up menus (whether RMB-activated or from a menu-bar) are perfectly normal X11 windows. The reason that you don't see them in your monitoring program is that you are monitoring changes caused by the window manager. Pop-up menus normally bypass the WM entirely, so WM doesn't know about them.
This is achieved by setting the override_redirect window attribute XSetWindowAttributes structure. Set it for your pop-up menus (and only for pop-up menus) and you should be all set.
Menus are not managed by a WM and don't have any WM-specific properties.
To watch windows, catch XMapNotify and XUnmapNotify events on the root window, using SubstructureNotifyMask. Here's a very simple program that does something:
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
int main () {
Display* d = XOpenDisplay(0);
if (!d) {
printf ("Oops...!\n");
exit (EXIT_FAILURE);
}
XSelectInput(d, DefaultRootWindow(d), SubstructureNotifyMask);
for(;;) {
XEvent e;
XNextEvent(d, &e);
if (e.type == MapNotify) {
printf ("Window %lx mapped!\n", e.xmap.window);
}
if (e.type == UnmapNotify) {
printf ("Window %lx unmapped!\n", e.xunmap.window);
}
}
}
It reports spurious Unmap events which can be simply ignored.
A more complete program should probably watch all events selected by SubstructureNotifyMask and SubstructureRedirectMask.
Related
I want to create a GUI toolkit for my desktop environment (because neither gtk nor qt don't fit to my needs) but I don't know how to start. I don't want a cross-platform or display-server independent library, theming options, configurable icons etc. just a few basic widgets for making wayland clients. (widgets like button, entry, label, window and images... and I want to use CSD if it's important)
My problem is that I can't understand how graphics work in wayland (in X you only need to create a window and use XDrawLine etc. right?) also I don't know how to write a graphical toolkit. Can you give me some articles or recommendations on how can I do this?
The easiest way to create a wayland client is to use the wayland-client library. Basically, it abstracts the wire format.
example:
#include <stdio.h>
#include <wayland-client.h>
int main(void)
{
struct wl_display *display = wl_display_connect(NULL);
if (display) {
printf("Connected!\n");
} else {
printf("Error connecting ;(\n");
return 1;
}
wl_display_disconnect(display);
return 0;
}
I'm currently making a C++ GUI application, but I have the following problem. In the program I have one MyForm.cpp and one Myform.h (just one button). When the application starts the console and the form opens. Is this default? Or how can I disable it? The code in the main is:
#include "MyForm.h"
using namespace System;
using namespace System::Windows::Forms;
[STAThread]
int main(array<String^>^ args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Namespace::MyForm form;
Application::Run(%form);
}
Hope that someone can help?
Add this in your .pro file :
ENTRY = mainCRTStartup
OR
in VS, right click on your project -> properties -> linker -> system
And select "Windows (/SUBSYSTEM:WINDOWS)" for SubSystem.
If you are using a CRT build and there is no WinMain function you can use this:
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")//hide console window
to hide the console.
I've got a Qt application that has two main windows. On Linux, when one main window brings up a modal dialog, it comes up behind the other main window. What can I do to cause the dialog to always come up on top of ALL main windows?
NOTE: This only happens on Linux. We build this app on MacOSX as well, and the problem does not occur there.
Here's the code that brings up the dialog. The stuff in the #if is all the things I've tried to bring the window forward. I've tried various combinations and orders of these things.
QMessageBox dialog;
dialog.setIcon( QMessageBox::Information );
dialog.setWindowTitle( _documentName );
dialog.setText( tr("This document has unsaved changes. Do you want to save before closing?") );
dialog.setInformativeText( tr("Your changes will be lost if you don't save them.") );
dialog.setStandardButtons( QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel );
dialog.setDefaultButton( QMessageBox::Save );
dialog.setFixedSize( dialog.size() ); // non-resizable window
#if STUFF_I_TRIED
dialog.show();
dialog.setVisible(true);
dialog.open();
dialog.activateWindow();
dialog.raise();
#endif
int result = dialog.exec();
I realize that exec() should be all I need to show the window. My idea in calling show() or open() was just to allow activateWindow() or raise() to take affect. Just foolin' around trying to get that damn dialog to come forward.
TIA for any help!
All the sequcence between #if 1_ and #endif looks pretty weird to me.
Normally, to show modal dialog, only exec() is needed:
QMessageBox msgBox;
msgBox.setText("They killed Kenny, again.");
int ret = msgBox.exec();
Reference.
You are doing quite a bit of things between your #if 1, that is likely confusing X11.
You need only ONE of those. Since you are working with Mac and X11, I suspect you want to use open() and get a sheet.
IIRC, show() vs. open() causes different window flags to be set, so
calling them right after each other may get the window into a strange
state. Also calling show() or open() should always activate or raise the window if it is a dialog, which QMessageBox is.
Try only using one of these and seeing what happens.
I have an application in Visual c++ (Win32 API). In my application the main window boarder is displayed in old windows styled. I have tried changing the wndWc.style values to WS_OVERLAPPED,WS_POPUP and other which are given in WinUser.h but there is no change in the appearance of the main window were as all my pop-up window are displayed in windows 7 style how this can be rectified. Any help in this regards will be highly appreciated. I have attached both the images the main window and the pop up window.
Code :
// our window class
WNDCLASS wndWc;
// ---------------------------------------------------------
// fill window class members
// ---------------------------------------------------------
wndWc.style = CS_GLOBALCLASS;
wndWc.lpfnWndProc = (WNDPROC) WndProc;
wndWc.cbClsExtra = 0;
wndWc.cbWndExtra = 0;
wndWc.hInstance = GetModuleHandle(NULL);
wndWc.hIcon = NULL;
wndWc.hCursor = LoadCursor(0, IDC_ARROW);
wndWc.hbrBackground = (HBRUSH)GetStockObject(0);
wndWc.lpszMenuName = NULL;
wndWc.lpszClassName = "XYZ";
// register class
if (!RegisterClass(&wndWc)) return false;
// ---------------------------------------------------------
// get actual screen resolution
int iSw = (WORD)GetSystemMetrics(SM_CXSCREEN); // height
int iSh = (WORD)GetSystemMetrics(SM_CYSCREEN); // height
// make a rectangle on the center of the screen
RECT rc = {(iSw - iWidth)/2, (iSh - iHeight)/2, width, height};
// create the window. the spaces on the window title
// are just to make sure this will be visible when the region
// is active. just run the app and you'll understand. =)
hWnd = CreateWindow("XYZ", "XYZ",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT, width,height,
NULL, NULL, GetModuleHandle(NULL), NULL);
It could be that your EXE has been flagged to run in compatibility mode for a previous OS version. Right-click the EXE, choose Properties, then ensure everything is switched off on the Compatibility tab. (Especially "Disable visual themes" and "run this program in compatibility mode for...")
Failing that...
It's unusual to need to do anything at all, but try this at the start of the app:
SetThemeAppProperties(STAP_ALLOW_NONCLIENT|STAP_ALLOW_CONTROLS)
If that doesn't work, try explicitly setting the theme for your window:
SetWindowTheme(hWnd, "WINDOW", NULL);
FWIW, I pasted your code in to a new Visual Studio 2008 project created using the "Win32 project" wizard, and it came out with a Windows 7 border. You usually have to go out of your way not to get the border, in fact.
There could be something unusual about the EXE you are building, like a flag in the EXE's header being set incorrectly. e.g. If it isn't specifying that it is a Windows GUI app, or maybe there are some version fields...
The EXE's manifest may also play a part, but I just tried deleting the manifest completely and my program still got a themed window, so it's probably not that.
If you look closely, you'll see that it's not just the border. The close button also uses the old visual style. Therefore, it's not sufficient that you change the window style. You must indicate that your app is Vista- and Aero-aware
In our RCP application, we need to resort to using a global key event handler (via Display.addFilter()) for more advanced key event handling/routing irrespective of current focus. We need to be able to determine if a dialog box is currently open for some of the routing logic.
Seems like a fairly trivial question but I keep hitting dead ends going off Widget hierarchy, Shells, WindowManagers.
I am looking for a robust solution that would not require any extra work on the part of Dialog implementers or client code that uses standard framework dialogs.
In the example below, shell is a defined Shell in the scope. You could modify the code to compare activeShell with a list of Shells.
shell.getDisplay().addFilter(SWT.KeyDown, new Listener() {
public void handleEvent(final Event event) {
if (shell.isDisposed()) {
return;
}
final Shell activeShell = shell.getDisplay().getActiveShell();
if (activeShell != null && activeShell.equals(shell)) {
if (event.stateMask == SWT.MOD1 && event.character == 'w') {
shell.dispose();
}
}
}
});
This example code will close shell when ⌘+W is pressed on Mac.