aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/apprt/gtk/ui/1.2/surface.blp
blob: 010798ae571495a88025721def43d9c1785b9463 (plain)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
using Gtk 4.0;
using Gdk 4.0;
using Adw 1;

Adw.StatusPage error_page {
  icon-name: "computer-fail-symbolic";
  title: _("Oh, no.");
  description: _("Unable to acquire an OpenGL context for rendering.");

  child: LinkButton {
    label: "https://ghostty.org/docs/help/gtk-opengl-context";
    uri: "https://ghostty.org/docs/help/gtk-opengl-context";
  };
}

Overlay terminal_page {
  focusable: false;
  focus-on-click: false;

  child: Box {
    hexpand: true;
    vexpand: true;

    GLArea gl_area {
      realize => $gl_realize();
      unrealize => $gl_unrealize();
      map => $gl_map();
      unmap => $gl_unmap();
      render => $gl_render();
      resize => $gl_resize();
      hexpand: true;
      vexpand: true;
      focusable: true;
      focus-on-click: true;
      has-stencil-buffer: false;
      has-depth-buffer: false;
      allowed-apis: gl;
    }

    PopoverMenu context_menu {
      closed => $context_menu_closed();
      menu-model: context_menu_model;
      flags: nested;
      halign: start;
      has-arrow: false;
    }

    EventControllerFocus {
      enter => $focus_enter();
      leave => $focus_leave();
    }

    EventControllerKey {
      key-pressed => $key_pressed();
      key-released => $key_released();
    }

    EventControllerScroll {
      scroll => $scroll_vertical();
      scroll-begin => $scroll_vertical_begin();
      scroll-end => $scroll_vertical_end();
      flags: vertical;
    }

    EventControllerScroll {
      scroll => $scroll_horizontal();
      flags: horizontal;
    }

    EventControllerMotion {
      motion => $mouse_motion();
      leave => $mouse_leave();
    }

    GestureClick {
      pressed => $mouse_down();
      released => $mouse_up();
      button: 0;
    }
  };

  [overlay]
  Revealer {
    reveal-child: bind template.readonly;
    transition-type: crossfade;
    transition-duration: 500;
    // Revealers take up the full size, we need this to not capture events.
    can-focus: false;
    can-target: false;
    focusable: false;

    Box readonly_overlay {
      styles [
        "readonly_overlay",
      ]

      // TODO: the tooltip doesn't actually work, but keep it here for now so
      // that we can get the tooltip text translated.
      has-tooltip: true;
      tooltip-text: _(
        "This terminal is in read-only mode. You can still view, select, and scroll through the content, but no input events will be sent to the running application."
      );
      halign: end;
      valign: start;
      spacing: 6;

      Image {
        icon-name: "changes-prevent-symbolic";
      }

      Label {
        label: _("Read-only");
      }
    }
  }

  [overlay]
  ProgressBar progress_bar_overlay {
    styles [
      "osd",
    ]

    visible: false;
    halign: fill;
    valign: start;
  }

  [overlay]
  // The "border" bell feature is implemented here as an overlay rather than
  // just adding a border to the GLArea or other widget for two reasons.
  // First, adding a border to an existing widget causes a resize of the
  // widget which undesirable side effects. Second, we can make it reactive
  // here in the blueprint with relatively little code.
  Revealer {
    reveal-child: bind $should_border_be_shown(template.config, template.bell-ringing) as <bool>;
    transition-type: crossfade;
    transition-duration: 500;
    // Revealers take up the full size, we need this to not capture events.
    can-focus: false;
    can-target: false;
    focusable: false;

    Box bell_overlay {
      styles [
        "bell-overlay",
      ]

      halign: fill;
      valign: fill;
    }
  }

  [overlay]
  $GhosttySurfaceChildExited child_exited_overlay {
    visible: bind template.child-exited;
    close-request => $child_exited_close();
  }

  [overlay]
  $GhosttyResizeOverlay resize_overlay {}

  [overlay]
  Label url_left {
    styles [
      "background",
      "url-overlay",
    ]

    visible: false;
    halign: start;
    valign: end;
    label: bind template.mouse-hover-url;

    EventControllerMotion url_ec_motion {
      enter => $url_mouse_enter();
      leave => $url_mouse_leave();
    }
  }

  [overlay]
  Label url_right {
    styles [
      "background",
      "url-overlay",
    ]

    visible: false;
    halign: end;
    valign: end;
    label: bind template.mouse-hover-url;
  }

  [overlay]
  $GhosttySearchOverlay search_overlay {
    stop-search => $search_stop();
    search-changed => $search_changed();
    next-match => $search_next_match();
    previous-match => $search_previous_match();
  }

  [overlay]
  $GhosttyKeyStateOverlay key_state_overlay {
    tables: bind template.key-table;
    sequence: bind template.key-sequence;
  }

  [overlay]
  // Apply unfocused-split-fill and unfocused-split-opacity to current surface
  // this is only applied when a tab has more than one surface
  Revealer {
    reveal-child: bind $should_unfocused_split_be_shown(
      search_overlay.active,
      template.focused,
      template.is-split
      ) as <bool>;
    transition-duration: 0;
    // This is all necessary so that the Revealer itself doesn't override
    // any input events from the other overlays. Namely, if you don't have
    // these then the search overlay won't get mouse events.
    can-focus: false;
    can-target: false;
    focusable: false;

    DrawingArea {
      styles [
        "unfocused-split",
      ]
    }
  }

  [overlay]
  CenterBox drag_handle {
    halign: fill;
    valign: start;
    visible: bind $should_drag_handle_be_shown(template.config, template.is-split) as <bool>;

    styles [
      "drag-handle",
    ]

    [center]
    Image {
      icon-name: "view-more-horizontal-symbolic";
    }

    DragSource surface_drag_source {
      actions: move;
      prepare => $surface_drag_prepare();
      drag-begin => $surface_drag_begin();
    }
  }

  [overlay]
  DrawingArea drop_overlay {
    halign: fill;
    valign: fill;
    can-focus: false;
    can-target: false;
    focusable: false;

    styles [
      "drop-overlay",
    ]
  }

  DropTarget drop_target {
    drop => $drop();
    actions: copy | move;
  }

  DropTarget surface_drop_target {
    // Enabling preload is required since that lets us know
    // which surface is currently being dragged, and to turn off
    // the drop overlay if the source and target are the same
    preload: true;
    leave => $surface_drop_leave();
    motion => $surface_drop_motion();
    drop => $surface_drop();
    notify::value => $notify_drop_value();
    actions: move;
  }
}

template $GhosttySurface: Adw.Bin {
  styles [
    "surface",
  ]

  notify::config => $notify_config();
  notify::error => $notify_error();
  notify::mouse-hover-url => $notify_mouse_hover_url();
  notify::mouse-hidden => $notify_mouse_hidden();
  notify::mouse-shape => $notify_mouse_shape();
  notify::vadjustment => $notify_vadjustment();
  // Some history: we used to use a Stack here and swap between the
  // terminal and error pages as needed. But a Stack doesn't play nice
  // with our SplitTree and Gtk.Paned usage[^1]. Replacing this with
  // a manual programmatic child swap fixed this. So if you ever change
  // this, be sure to test many splits!
  //
  // [^1]: https://github.com/ghostty-org/ghostty/issues/8533
  child: terminal_page;
}

IMMulticontext im_context {
  input-purpose: terminal;
  preedit-start => $im_preedit_start();
  preedit-changed => $im_preedit_changed();
  preedit-end => $im_preedit_end();
  commit => $im_commit();
}

menu context_menu_model {
  section {
    item {
      label: _("Copy");
      action: "win.copy";
    }

    item {
      label: _("Paste");
      action: "win.paste";
    }

    item {
      label: _("Notify on Next Command Finish");
      action: "surface.notify-on-next-command-finish";
    }
  }

  section {
    item {
      label: _("Clear");
      action: "win.clear";
    }

    item {
      label: _("Reset");
      action: "win.reset";
    }
  }

  section {
    submenu {
      label: _("Split");

      item {
        label: _("Change Title…");
        action: "surface.prompt-title";
      }

      item {
        label: _("Split Up");
        action: "split-tree.new-split";
        target: "up";
      }

      item {
        label: _("Split Down");
        action: "split-tree.new-split";
        target: "down";
      }

      item {
        label: _("Split Left");
        action: "split-tree.new-split";
        target: "left";
      }

      item {
        label: _("Split Right");
        action: "split-tree.new-split";
        target: "right";
      }

      item {
        label: _("Close Split");
        action: "split-tree.close-split";
      }
    }

    submenu {
      label: _("Tab");

      item {
        label: _("Change Tab Title…");
        action: "tab.prompt-tab-title";
      }

      item {
        label: _("New Tab");
        action: "win.new-tab";
      }

      item {
        label: _("Close Tab");
        action: "tab.close";
        target: "this";
      }
    }

    submenu {
      label: _("Window");

      item {
        label: _("Change Window Title…");
        action: "win.prompt-window-title";
      }

      item {
        label: _("New Window");
        action: "win.new-window";
      }

      item {
        label: _("Close Window");
        action: "win.close";
      }
    }
  }

  section {
    submenu {
      label: _("Config");

      item {
        label: _("Open Configuration in OS Editor");
        action: "app.open-config";
        target: "os-open";
      }

      item {
        label: _("Open Configuration in New Window");
        action: "app.open-config";
        target: "new-window";
      }

      item {
        label: _("Reload Configuration");
        action: "app.reload-config";
      }
    }
  }
}