[vte/vte-next: 217/223] Make resize-window signal cell based



commit 0fb366508edaa95c83b03a2deb3bb066aee1d76e
Author: Christian Persch <chpe gnome org>
Date:   Wed Jun 22 20:39:35 2011 +0200

    Make resize-window signal cell based
    
    The buffer doesn't know anything about widgets, so it cannot use
    the char height, char width, or pixels size. Instead, use columns
    and rows, and report a fake char size back to the application.

 src/vte.c    |   11 +++++----
 src/vteapp.c |   15 +++++--------
 src/vteseq.c |   62 +++++++++++++++++++--------------------------------------
 3 files changed, 33 insertions(+), 55 deletions(-)
---
diff --git a/src/vte.c b/src/vte.c
index 76b9f8f..364774a 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -1152,15 +1152,16 @@ _vte_buffer_emit_move_window(VteBuffer *buffer, guint x, guint y)
         g_signal_emit(buffer, buffer_signals[BUFFER_MOVE_WINDOW], 0, x, y);
 }
 
-/* Emit a "resize-window" signal.  (Pixels.) */
+/* Emit a "resize-window" signal.  (cells.) */
 void
 _vte_buffer_emit_resize_window(VteBuffer *buffer,
-                                guint width, guint height)
+                               guint cols,
+                               guint rows)
 {
         _vte_debug_print(VTE_DEBUG_SIGNALS,
                         "Emitting `resize-window'.\n");
         g_signal_emit(buffer, buffer_signals[BUFFER_RESIZE_WINDOW], 0,
-                      width, height);
+                      cols, rows);
 }
 
 static void
@@ -14196,8 +14197,8 @@ vte_buffer_class_init(VteBufferClass *klass)
         /**
          * VteBuffer::resize-window:
          * @vtebuffer: the object which received the signal
-         * @width: the desired width in pixels, including padding
-         * @height: the desired height in pixels, including padding
+         * @width: the desired number of columns
+         * @height: the desired number of rows
          *
          * Emitted at the child application's request.
          */
diff --git a/src/vteapp.c b/src/vteapp.c
index 924e9bc..f04e627 100644
--- a/src/vteapp.c
+++ b/src/vteapp.c
@@ -244,15 +244,14 @@ refresh_window(VteBuffer *buffer, gpointer data)
 }
 
 static void
-resize_window(VteBuffer *buffer, guint width, guint height, VteView *terminal)
+resize_window(VteBuffer *buffer, guint columns, guint rows, VteView *terminal)
 {
         GtkWidget *widget = &terminal->widget;
         GtkWidget *window;
 
         window = gtk_widget_get_toplevel(GTK_WIDGET(terminal));
-	if (gtk_widget_is_toplevel(window) && (width >= 2) && (height >= 2)) {
+	if (gtk_widget_is_toplevel(window) && (columns >= 2) && (rows >= 2)) {
 		gint owidth, oheight, char_width, char_height, column_count, row_count;
-		GtkBorder padding;
 
 		gtk_window_get_size(GTK_WINDOW(window), &owidth, &oheight);
 
@@ -261,14 +260,12 @@ resize_window(VteBuffer *buffer, guint width, guint height, VteView *terminal)
 		char_height = vte_view_get_char_height (terminal);
 		column_count = vte_buffer_get_column_count (buffer);
 		row_count = vte_buffer_get_row_count (buffer);
-                gtk_style_context_get_padding(gtk_widget_get_style_context(widget),
-                                              gtk_widget_get_state_flags(widget),
-                                              &padding);
 
-                owidth -= char_width * column_count + padding.left + padding.right;
-                oheight -= char_height * row_count + padding.top + padding.bottom;
+                owidth += char_width * (columns - column_count);
+                oheight += char_height * (rows - row_count);
+
 		gtk_window_resize(GTK_WINDOW(window),
-				  width + owidth, height + oheight);
+				  owidth, oheight);
 	}
 }
 
diff --git a/src/vteseq.c b/src/vteseq.c
index 6fbb28d..f5bf3ff 100644
--- a/src/vteseq.c
+++ b/src/vteseq.c
@@ -32,6 +32,10 @@
 
 #define BEL "\007"
 
+/* A fake char cell size */
+#define CHAR_WIDTH (8)
+#define CHAR_HEIGHT (16)
+
 /* FUNCTIONS WE USE */
 
 static void
@@ -746,14 +750,8 @@ vte_sequence_handler_decset_internal(VteBuffer *buffer,
 #if 0		/* 3: disallowed, window size is set by user. */
 	case 3:
 		_vte_buffer_emit_resize_window(buffer,
-						(set ? 132 : 80) *
-						terminal->pvt->char_width +
-						terminal->pvt->padding.left +
-                                                terminal->pvt->padding.right,
-						buffer->pvt->row_count *
-						terminal->pvt->char_height +
-						terminal->pvt->padding.top +
-                                                terminal->pvt->padding.bottom);
+						set ? 132 : 80,
+						buffer->pvt->row_count);
 		/* Request a resize and redraw. */
 		_vte_buffer_view_invalidate_all(buffer);
 		break;
@@ -2970,7 +2968,6 @@ vte_sequence_handler_window_manipulation (VteBuffer *buffer, GValueArray *params
 	long param, arg1, arg2;
 	gint width, height;
 	guint i;
-	GtkAllocation allocation;
 
         terminal = buffer->pvt->terminal;
         /* FIXMEchpe cope with NULL terminal */
@@ -3025,12 +3022,8 @@ vte_sequence_handler_window_manipulation (VteBuffer *buffer, GValueArray *params
 						"(to %ldx%ld pixels).\n",
 						arg2, arg1);
 				_vte_buffer_emit_resize_window(buffer,
-								arg2 +
-								terminal->pvt->padding.left +
-								terminal->pvt->padding.right,
-								arg1 +
-								terminal->pvt->padding.top +
-								terminal->pvt->padding.bottom);
+								arg2 / CHAR_WIDTH,
+								arg1 / CHAR_HEIGHT);
 				i += 2;
 			}
 			break;
@@ -3055,12 +3048,8 @@ vte_sequence_handler_window_manipulation (VteBuffer *buffer, GValueArray *params
 						"(to %ld columns, %ld rows).\n",
 						arg2, arg1);
 				_vte_buffer_emit_resize_window(buffer,
-								arg2 * terminal->pvt->char_width +
-								terminal->pvt->padding.left +
-								terminal->pvt->padding.right,
-								arg1 * terminal->pvt->char_height +
-								terminal->pvt->padding.top +
-								terminal->pvt->padding.bottom);
+								arg2,
+								arg1);
 				i += 2;
 			}
 			break;
@@ -3108,21 +3097,16 @@ vte_sequence_handler_window_manipulation (VteBuffer *buffer, GValueArray *params
 			break;
 		case 14:
 			/* Send window size, in pixels. */
-			gtk_widget_get_allocation(widget, &allocation);
 			g_snprintf(buf, sizeof(buf),
-				   _VTE_CAP_CSI "4;%d;%dt",
-				   allocation.height -
-                                       (terminal->pvt->padding.top +
-                                        terminal->pvt->padding.bottom),
-				   allocation.width -
-                                       (terminal->pvt->padding.left +
-                                        terminal->pvt->padding.right));
+				   _VTE_CAP_CSI "4;%ld;%ldt",
+				   buffer->pvt->row_count * CHAR_HEIGHT,
+                                   buffer->pvt->column_count * CHAR_WIDTH);
 			_vte_debug_print(VTE_DEBUG_PARSE,
 					"Reporting window size "
-					"(%dx%dn",
-					width - (terminal->pvt->padding.left + terminal->pvt->padding.right),
-					height - (terminal->pvt->padding.top + terminal->pvt->padding.bottom));
-			vte_buffer_feed_child(buffer, buf, -1);
+					"(%ldx%ldn",
+                                         buffer->pvt->row_count * CHAR_HEIGHT,
+                                         buffer->pvt->column_count * CHAR_WIDTH);
+                        vte_buffer_feed_child(buffer, buf, -1);
 			break;
 		case 18:
 			/* Send widget size, in cells. */
@@ -3142,8 +3126,8 @@ vte_sequence_handler_window_manipulation (VteBuffer *buffer, GValueArray *params
 			width = gdk_screen_get_width(gscreen);
 			g_snprintf(buf, sizeof(buf),
 				   _VTE_CAP_CSI "9;%ld;%ldt",
-				   height / terminal->pvt->char_height,
-				   width / terminal->pvt->char_width);
+				   (glong)height / CHAR_HEIGHT,
+				   (glong)width / CHAR_WIDTH);
 			vte_buffer_feed_child(buffer, buf, -1);
 			break;
 		case 20:
@@ -3180,12 +3164,8 @@ vte_sequence_handler_window_manipulation (VteBuffer *buffer, GValueArray *params
 				/* Resize to the specified number of
 				 * rows. */
 				_vte_buffer_emit_resize_window(buffer,
-								buffer->pvt->column_count * terminal->pvt->char_width +
-                                                                terminal->pvt->padding.left +
-                                                                terminal->pvt->padding.right,
-								param * terminal->pvt->char_height +
-								terminal->pvt->padding.top +
-                                                                terminal->pvt->padding.bottom);
+								buffer->pvt->column_count,
+								param);
 			}
 			break;
 		}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]