tommie-lie
August 27th, 2005, 12:30 PM
Hi,
Some of you may know Windows applications with windows that don't have any border, but you can "grab" them by clicking somehwere in the window. For instance, winamp behaves this way, along with other multimedia applications.
I want to create such a window with Gtk+ (Gtkmm, to be exact) under Linux. I can remove the window decoration without any problem Gtk::window->set_decorated(false) does the job. However, moving the window does not work as I would expect it. Is attached two event handlers, one for the mouse button click event and one for the pointer motion event. The handlers look like this:
bool MainWindow::on_button_press_event(GdkEventButton *button)
{
if (button->button == 1) {
// set initial mouse position (relative to the widget)
this->last_x = button->x;
this->last_y = button->y;
return true;
}
return false;
}
bool MainWindow::on_motion_notify_event(GdkEventMotion *motion)
{
if ((motion->state & Gdk::BUTTON1_MASK) == Gdk::BUTTON1_MASK) {
int cur_pos_x, cur_pos_y;
this->get_position(cur_pos_x, cur_pos_y);
this->move(cur_pos_x + (motion->x - this->last_x), cur_pos_y + (motion->y - this->last_y));
return false;
}
return false;
}On pointer movement, I simply check if the first mouse button is pressed and, if this is the case, calculate the pointer movement difference and move the window by this difference. I would expect this to work fine, as I did such things under Windows with the exact same approach, but it does not. If I move the mouse slowly, the window seems to follow, but the longer I drag the window, the more unstable becomes the movement of the window (kind of "loses track"). If I move the mouse fast, the window becomes unstable almost immediately. This "instability" in movement goes that far that the window seems to become crazy, gonig backwards and jumps to weird positions where my mouse never was.
I hope some of you find some fatal mistake of mine or something else that I overlooked.
Thanks in advance
Thomas
Some of you may know Windows applications with windows that don't have any border, but you can "grab" them by clicking somehwere in the window. For instance, winamp behaves this way, along with other multimedia applications.
I want to create such a window with Gtk+ (Gtkmm, to be exact) under Linux. I can remove the window decoration without any problem Gtk::window->set_decorated(false) does the job. However, moving the window does not work as I would expect it. Is attached two event handlers, one for the mouse button click event and one for the pointer motion event. The handlers look like this:
bool MainWindow::on_button_press_event(GdkEventButton *button)
{
if (button->button == 1) {
// set initial mouse position (relative to the widget)
this->last_x = button->x;
this->last_y = button->y;
return true;
}
return false;
}
bool MainWindow::on_motion_notify_event(GdkEventMotion *motion)
{
if ((motion->state & Gdk::BUTTON1_MASK) == Gdk::BUTTON1_MASK) {
int cur_pos_x, cur_pos_y;
this->get_position(cur_pos_x, cur_pos_y);
this->move(cur_pos_x + (motion->x - this->last_x), cur_pos_y + (motion->y - this->last_y));
return false;
}
return false;
}On pointer movement, I simply check if the first mouse button is pressed and, if this is the case, calculate the pointer movement difference and move the window by this difference. I would expect this to work fine, as I did such things under Windows with the exact same approach, but it does not. If I move the mouse slowly, the window seems to follow, but the longer I drag the window, the more unstable becomes the movement of the window (kind of "loses track"). If I move the mouse fast, the window becomes unstable almost immediately. This "instability" in movement goes that far that the window seems to become crazy, gonig backwards and jumps to weird positions where my mouse never was.
I hope some of you find some fatal mistake of mine or something else that I overlooked.
Thanks in advance
Thomas