Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"focus-out-event" crashes application #333

Open
CapitaineJSparrow opened this issue Oct 4, 2022 · 0 comments · May be fixed by #334
Open

"focus-out-event" crashes application #333

CapitaineJSparrow opened this issue Oct 4, 2022 · 0 comments · May be fixed by #334

Comments

@CapitaineJSparrow
Copy link

CapitaineJSparrow commented Oct 4, 2022

I tried to add a "focus-out-event" on a "GtkSearchEntry" but application is crashing from native code.

[INFO] loop.cc: QuitLoopStack: 173: calling (anonymous)
/home/sparrow/projects/app/node_modules/node-gtk/lib/overrides/Gtk-3.0.js:37
        originalMain()
        ^

TypeError: Cannot convert value "undefined" to type gboolean in signal "focus-out-event"
    at Function.main (/home/sparrow/projects/app/node_modules/node-gtk/lib/overrides/Gtk-3.0.js:37:9)
    at Object.<anonymous> (/home/sparrow/projects/app/app.js:40:5)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47

Here is the index (crashing when onSearchBarFocusOut is triggered in handlers)

const gi = require('node-gtk')
const path = require('path');
gi.startLoop();

const Gtk = gi.require('Gtk', '3.0');
const Gdk = gi.require('Gdk', '3.0');
Gtk.init();

// Load custom theme
const css_provider = new Gtk.CssProvider()
css_provider.loadFromPath(path.join(__dirname, 'resources', 'test.css'));
const context = Gtk.StyleContext
const screen = Gdk.Screen.getDefault();
context.addProviderForScreen(screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);

// Load UI file to GtkBuilder
const gladeFile = path.join(__dirname, 'resources', 'test.ui');
const builder = Gtk.Builder.newFromFile(gladeFile);
const win = builder.getObject('mainWindow');

// Animations
const searchButton = builder.getObject('searchButton');
const search = builder.getObject('search');

const handlers = {
    onSearchBtnClick: () => {
        searchButton.getStyleContext().addClass("search-button-open")
        search.getStyleContext().removeClass("search-hide")
        search.getStyleContext().addClass("search-open")
    },
    onSearchBarFocusOut: () => {
        console.log("Crash here")
    }
}

builder.connectSignals(handlers)

win.on('show', Gtk.main);
win.on('destroy', () => Gtk.mainQuit())
win.showAll();

here is glade file for reference

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
  <requires lib="gtk+" version="3.24"/>
  <object class="GtkImage" id="image1">
    <property name="visible">True</property>
    <property name="can-focus">False</property>
    <property name="icon-name">go-previous</property>
  </object>
  <object class="GtkImage" id="image2">
    <property name="visible">True</property>
    <property name="can-focus">False</property>
    <property name="icon-name">go-next</property>
  </object>
  <object class="GtkImage" id="image3">
    <property name="visible">True</property>
    <property name="can-focus">False</property>
    <property name="icon-name">system-search</property>
  </object>
  <object class="GtkWindow" id="mainWindow">
    <property name="can-focus">True</property>
    <property name="title">dqsdsdsq</property>
    <property name="window-position">center</property>
    <property name="default-width">1280</property>
    <property name="default-height">720</property>
    <child>
      <object class="GtkBox">
        <property name="visible">True</property>
        <property name="can-focus">False</property>
        <property name="valign">start</property>
        <property name="margin-start">8</property>
        <property name="margin-end">8</property>
        <property name="margin-top">8</property>
        <property name="margin-bottom">8</property>
        <child>
          <object class="GtkButton" id="backButton">
            <property name="name">backButton</property>
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="receives-default">True</property>
            <property name="image">image1</property>
            <property name="always-show-image">True</property>
            <style>
              <class name="no-round-right"/>
            </style>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="position">0</property>
          </packing>
        </child>
        <child>
          <object class="GtkButton">
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="receives-default">True</property>
            <property name="image">image2</property>
            <property name="always-show-image">True</property>
            <style>
              <class name="no-round-left"/>
            </style>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="position">1</property>
          </packing>
        </child>
        <child>
          <object class="GtkButton" id="searchButton">
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="receives-default">True</property>
            <property name="margin-start">8</property>
            <property name="image">image3</property>
            <property name="always-show-image">True</property>
            <signal name="clicked" handler="onSearchBtnClick" swapped="no"/>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="position">2</property>
          </packing>
        </child>
        <child>
          <object class="GtkSearchEntry" id="search">
            <property name="can-focus">True</property>
            <property name="hexpand">True</property>
            <property name="primary-icon-name">edit-find-symbolic</property>
            <property name="primary-icon-activatable">False</property>
            <property name="primary-icon-sensitive">False</property>
            <property name="placeholder-text" translatable="yes">Search for an application</property>
            <signal name="focus-out-event" handler="onSearchBarFocusOut" swapped="no"/>
            <style>
              <class name="search-hide"/>
            </style>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="position">3</property>
          </packing>
        </child>
      </object>
    </child>
  </object>
</interface>
@CapitaineJSparrow CapitaineJSparrow linked a pull request Oct 4, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant