GTK+ mouse automatic click problem.

Hi I wroted program in Ubuntu GTK+.
I am beginner GTK+ and have a problem.
I coded new app:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdlib.h>
#include <X11/Xlib.h>
#include <gtk/gtk.h>
#include <X11/extensions/XTest.h>

static void helloWorld (GtkWidget *wid, GtkWidget *win)
{
  GtkWidget *dialog = NULL;

  dialog = gtk_message_dialog_new (GTK_WINDOW (win), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, "Hello World!");
  gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
  gtk_dialog_run (GTK_DIALOG (dialog));
  gtk_widget_destroy (dialog);

}

void window1 (GtkWidget *wid, GtkWidget *win, Display *active_display)
{
    gint x, y, xadd=0, yadd=0;
    GdkDisplay *display = NULL;
    GdkDisplay *displey = NULL;
    GdkScreen *screen = NULL;
    GtkWidget *widget = NULL;
    GtkWindow *window = NULL;

   /* get default display and screen */
    display = gdk_display_get_default ();
    screen = gdk_display_get_default_screen (display);


    usleep(2*(1000*1000));

    /*
    |
                                             GDK_BUTTON_RELEASE_MASK |
                                             GDK_ENTER_NOTIFY_MASK |
                                             GDK_LEAVE_NOTIFY_MASK |
                                             GDK_POINTER_MOTION_MASK
    */

    //GdkEvent *event = gdk_event_new(GDK_BUTTON_PRESS);
    //event = gdk_event_new(GDK_BUTTON_PRESS);
    gdk_display_pointer_is_grabbed(display);
    gdk_display_pointer_ungrab(display, 1000);
    /*
    GdkEventType type;
    type = event->type = GDK_BUTTON_PRESS;
*/


    x=36; y=387;
    printf("start\n");
    usleep(1*(1000*1000));
    printf("a\n");

Problem is starting now.
When gdk_pointer_grab start on "int main" windows not problem.
But when mouse on no "int main" window I saw error:
- Gdk-CRITICAL **: gdk_pointer_grab: assertion `window != NULL` failed
- Gdk-CRITICAL **: gdk_pointer_grab: assertion `window != NULL` failed
How can write Click mouse button any window?
1
2
3
4
5
6
7
8
9
    gdk_display_warp_pointer (display, screen, x, y);

    usleep(1*(1000*1000));

    displey = gdk_display_get_default ();
    window = gdk_display_get_window_at_pointer(displey, &x, &y);

    gdk_pointer_grab(window, TRUE, (GdkEventMask)(GDK_BUTTON_PRESS_MASK ), (GdkWindow *)NULL, NULL, GDK_CURRENT_TIME);
    gdk_pointer_grab(window, TRUE, (GdkEventMask)(GDK_BUTTON_RELEASE_MASK), (GdkWindow *)NULL, NULL, GDK_CURRENT_TIME);


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
    window2();


/*
    //gtk_button_set_focus_on_click(, gpointer);

  char *display_name = getenv("DISPLAY");
  Display *dpy;
  Window root;
  long mask;
  XEvent event;

  dpy = XOpenDisplay(display_name);
*/


}





void window2 (GtkWidget *wid, GtkWidget *win)
{
    gint x, y, xadd=0, yadd=0;
    GdkDisplay *display = NULL;
    GdkScreen *screen = NULL;

   /* get default display and screen */
    display = gdk_display_get_default ();
    screen = gdk_display_get_default_screen (display);

    x=36; y=82;
    printf("b\n");
    gdk_display_warp_pointer (display, screen, x, y);
    gdk_display_pointer_ungrab(display, 10);
    usleep(1*(1000*1000));
    window3();
}

void window3(GtkWidget *wid, GtkWidget *win)
{
    gint x, y, xadd=0, yadd=0;
    GdkDisplay *display = NULL;
    GdkScreen *screen = NULL;
    GtkWidget *widget = NULL;

   /* get default display and screen */
    display = gdk_display_get_default ();
    screen = gdk_display_get_default_screen (display);

    x=36; y=7;
    printf("c\n");
    gdk_display_warp_pointer (display, screen, x, y);
    gdk_display_pointer_ungrab(display, 10);
    usleep(5*(1000*1000));
    //window4();
}


int main (int argc, char *argv[])
{
  GtkWidget *button = NULL;
  GtkWidget *win = NULL;
  GtkWidget *vbox = NULL;

  /* Initialize GTK+ */
  g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, (GLogFunc) gtk_false, NULL);
  gtk_init (&argc, &argv);
  g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, NULL);

  /* Create the main window */
  win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (win), 8);
  gtk_window_set_title (GTK_WINDOW (win), "Hello World");
  gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);
  gtk_widget_realize (win);
  g_signal_connect (win, "destroy", gtk_main_quit, NULL);

  /* Create a vertical box with buttons */
  vbox = gtk_vbox_new (TRUE, 6);
  gtk_container_add (GTK_CONTAINER (win), vbox);

  button = gtk_button_new_from_stock (GTK_STOCK_DIALOG_INFO);
  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (helloWorld), (gpointer) win);
  gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);


  button = gtk_button_new_from_stock ("Tıkla");
  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (window1), (gpointer) win);
  gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);

  button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
  g_signal_connect (button, "clicked", gtk_main_quit, NULL);
  gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);

  /* Enter the main loop */
  gtk_widget_show_all (win);
  gtk_main ();
  return 0;
}


I waiting your Help. Thanks.
Last edited on
Topic archived. No new replies allowed.