2020-04-10 12:27 AM
Hi!
Simple program on board STM32MP157C-DK2
#include <gtk/gtk.h>
gint width = 400;
gint height = 200;
gint X = 20;
gint Y = 20;
gint x;
gint y;
GtkWidget *window;
int main (int argc, char *argv[])
{
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Hello");
gtk_window_set_default_size(GTK_WINDOW(window), width, height);
gtk_window_move (GTK_WINDOW (window), X, Y);
gtk_widget_show(window);
gtk_main();
return 0;
line gtk_window_move (GTK_WINDOW (window), X, Y); - not work :(
a window is created anywhere on the screen
how to control the position of the window?
Best regards
Alexander.
P.S. on PC (Ubuntu 16.04), this program works fine.
2020-04-14 06:44 AM
Hello Alexander,
from https://developer.gnome.org/gtk3/stable/GtkWindow.html#gtk-window-get-position >
The reliability of this function depends on the windowing system currently in use. Some windowing systems, such as Wayland, do not support a global coordinate system, and thus the position of the window will always be (0, 0). Others, like X11, do not have a reliable way to obtain the geometry of the decorations of a window if they are provided by the window manager. Additionally, on X11, window manager have been known to mismanage window gravity, which result in windows moving even if you use the coordinates of the current position as returned by this function.
When trying myself, I got always the same value of position (using gtk_window_get_position()), despite it's not a zero value.
BR,
Milan
2020-04-15 04:28 AM
Hello Milan!
Thanks for the quick response
I changed the program (highlighted in bold) :
#include <gtk/gtk.h>
gint width = 400;
gint height = 200;
gint X = 100;
gint Y = 100;
gint x;
gint y;
GtkWidget *window;
int main (int argc, char *argv[])
{
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Hello");
gtk_window_set_default_size(GTK_WINDOW(window), width, height);
gtk_window_get_position(GTK_WINDOW(window), &x, &y);
printf("current position is:\nx: %i\ny:%i\n", x, y);
gtk_widget_show(window);
gtk_window_move (GTK_WINDOW (window), X, Y);
gtk_window_get_position(GTK_WINDOW(window), &x, &y);
printf("new position is:\nx: %i\ny:%i\n", x, y);
gtk_main();
return 0;
}
program messages in the terminal :
root@stm32mp1:/usr/local# ./111
(111:5682): dbind-WARNING **: 11:16:30.484: Error retrieving accessibility bus address: org.a11y.Bus.Error: Failed to execute child process ?/usr/bin? (Permission denied)
current position is:
x: 26
y:23
new position is:
x: 26
y:23
Line: gtk_window_move (GTK_WINDOW (window), X, Y); - did not change the coordinates of the window :(
Window is created anywhere on the screen, but the coordinates do not change.
What am I doing wrong?
Best regards,
Alexander