Skip to content

Commit a7a684f

Browse files
committed
[GTK] move and resize event support
Fix nwjs#799
1 parent bad0e04 commit a7a684f

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/browser/native_window_gtk.cc

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ NativeWindowGtk::NativeWindowGtk(const base::WeakPtr<content::Shell>& shell,
5454
state_(GDK_WINDOW_STATE_WITHDRAWN),
5555
content_thinks_its_fullscreen_(false),
5656
frame_cursor_(NULL),
57-
resizable_(true) {
57+
resizable_(true),
58+
last_x_(-1), last_y_(-1),
59+
last_width_(-1), last_height_(-1)
60+
{
5861
window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
5962

6063
vbox_ = gtk_vbox_new(FALSE, 0);
@@ -94,6 +97,9 @@ NativeWindowGtk::NativeWindowGtk(const base::WeakPtr<content::Shell>& shell,
9497
gtk_window_set_default_size(window_, width, height);
9598
}
9699

100+
last_width_ = width;
101+
last_height_ = height;
102+
97103
// Hide titlebar when {frame: false} specified.
98104
if (!has_frame_)
99105
gtk_window_set_decorated(window_, false);
@@ -124,6 +130,8 @@ NativeWindowGtk::NativeWindowGtk(const base::WeakPtr<content::Shell>& shell,
124130
G_CALLBACK(OnWindowStateThunk), this);
125131
g_signal_connect(window_, "delete-event",
126132
G_CALLBACK(OnWindowDeleteEventThunk), this);
133+
g_signal_connect(window_, "configure-event",
134+
G_CALLBACK(OnWindowConfigureEventThunk), this);
127135
if (!has_frame_) {
128136
g_signal_connect(window_, "button-press-event",
129137
G_CALLBACK(OnButtonPressThunk), this);
@@ -579,6 +587,38 @@ gboolean NativeWindowGtk::OnWindowDeleteEvent(GtkWidget* widget,
579587
return FALSE;
580588
}
581589

590+
gboolean NativeWindowGtk::OnWindowConfigureEvent(GtkWidget* window,
591+
GdkEvent* event)
592+
{
593+
int x, y;
594+
int w, h;
595+
596+
x = event->configure.x;
597+
y = event->configure.y;
598+
if (x != last_x_ || y != last_y_) {
599+
last_x_ = x;
600+
last_y_ = y;
601+
base::ListValue args;
602+
args.AppendInteger(x);
603+
args.AppendInteger(y);
604+
if (shell())
605+
shell()->SendEvent("move", args);
606+
}
607+
608+
w = event->configure.width;
609+
h = event->configure.height;
610+
if (w != last_width_ || h != last_height_) {
611+
last_width_ = w;
612+
last_height_ = h;
613+
base::ListValue args;
614+
args.AppendInteger(w);
615+
args.AppendInteger(h);
616+
if (shell())
617+
shell()->SendEvent("resize", args);
618+
}
619+
return FALSE;
620+
}
621+
582622
bool NativeWindowGtk::GetWindowEdge(int x, int y, GdkWindowEdge* edge) {
583623
if (has_frame_)
584624
return false;

src/browser/native_window_gtk.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ class NativeWindowGtk : public NativeWindow {
116116
GdkEventButton*);
117117
CHROMEGTK_CALLBACK_1(NativeWindowGtk, gboolean, OnMouseMoveEvent,
118118
GdkEventMotion*);
119+
CHROMEGTK_CALLBACK_1(NativeWindowGtk, gboolean, OnWindowConfigureEvent,
120+
GdkEvent*);
119121

120122
GtkWindow* window_;
121123
GtkWidget* toolbar_;
@@ -147,6 +149,11 @@ class NativeWindowGtk : public NativeWindow {
147149
// True if the window should be resizable by the user.
148150
bool resizable_;
149151

152+
int last_x_;
153+
int last_y_;
154+
int last_width_;
155+
int last_height_;
156+
150157
DISALLOW_COPY_AND_ASSIGN(NativeWindowGtk);
151158
};
152159

0 commit comments

Comments
 (0)