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

Background image not showing #68

Open
hidraulicChicken opened this issue Apr 30, 2024 · 7 comments
Open

Background image not showing #68

hidraulicChicken opened this issue Apr 30, 2024 · 7 comments
Labels
question Further information is requested

Comments

@hidraulicChicken
Copy link

hidraulicChicken commented Apr 30, 2024

Hey folks,
I'm on NixOS 23.11 with sway and tried everything to get the background showing, but never ever shows up.
Here are my configs:
/etc/greetd/regreet.toml

[GTK]
application_prefer_dark_theme = true
cursor_theme_name = "Adwaita"
font_name = "JetBrainsMonoNerdFontMono-Regular"
icon_theme_name = "Adwaita"
theme_name = "Adwaita"

[background]
path = "/tmp/fallout_loading.jpg"

[commands]
poweroff = ["systemctl", "poweroff"]
reboot = ["systemctl", "reboot"] 
swayConfig = pkgs.writeText "greetd-sway-config" ''
    # `-l` activates layer-shell mode. Notice that `swaymsg exit` will run after gtkgreet.
    exec "${pkgs.greetd.regreet}/bin/regreet -l debug  &> /tmp/regreet.log; swaymsg exit"
    bindsym Mod4+shift+e exec swaynag \
	-t warning \
	-m 'What do you want to do?' \
	-b 'Poweroff' 'systemctl poweroff' \
	-b 'Reboot' 'systemctl reboot'
    include /home/gergoe/.config/sway/config
  '';

greetd command:
dbus-run-session ${pkgs.sway}/bin/sway --config ${swayConfig}

regreet.log

background:
-rwxrwxrwx 1 myuser users 275K 2024-04-30 14:02 /tmp/fallout_loading.jpg

Sadly the I couldn't decipher the error message: Gtk-WARNING **: 14:27:41.009: Theme parser warning: :6:17-18: Empty declaration

Please let me know what else I could check/set.

@rtgiskard
Copy link
Contributor

the error message seems to be caused by the inline_css in the code, can be ignored at the time.

@hidraulicChicken
Copy link
Author

Ok, thanks for the input, but the problem still remains, no background.
Additionally the keyboard layout is different from the one set in sway.

@rharish101
Copy link
Owner

Your background path seems to be in /tmp. Are you sure that the image exists there? Could you also try with a different path?

@rharish101 rharish101 added the question Further information is requested label Aug 3, 2024
@hidraulicChicken
Copy link
Author

hidraulicChicken commented Aug 3, 2024 via email

@rharish101
Copy link
Owner

Well, in the codebase, I just pass the path to GTK, and it should automatically pick it up. I'll try to write a minimal GTK app for displaying an image, and then you can see if it works.

@hidraulicChicken
Copy link
Author

hidraulicChicken commented Aug 3, 2024 via email

@rharish101
Copy link
Owner

rharish101 commented Aug 3, 2024

Can you run this file:

use gtk::glib::clone;
use gtk::prelude::{BoxExt, ButtonExt, GtkWindowExt};
use relm4::{gtk, ComponentParts, ComponentSender, RelmApp, RelmWidgetExt, SimpleComponent};

struct AppModel {
    counter: u8,
}

#[derive(Debug)]
enum AppInput {
    Increment,
    Decrement,
}

struct AppWidgets {
    label: gtk::Label,
}

impl SimpleComponent for AppModel {
    /// The type of the messages that this component can receive.
    type Input = AppInput;
    /// The type of the messages that this component can send.
    type Output = ();
    /// The type of data with which this component will be initialized.
    type Init = u8;
    /// The root GTK widget that this component will create.
    type Root = gtk::Window;
    /// A data structure that contains the widgets that you will need to update.
    type Widgets = AppWidgets;

    fn init_root() -> Self::Root {
        gtk::Window::builder()
            .title("Simple app")
            .default_width(300)
            .default_height(100)
            .build()
    }

    /// Initialize the UI and model.
    fn init(
        counter: Self::Init,
        window: &Self::Root,
        sender: ComponentSender<Self>,
    ) -> relm4::ComponentParts<Self> {
        let model = AppModel { counter };

        let vbox = gtk::Box::builder()
            .orientation(gtk::Orientation::Vertical)
            .spacing(5)
            .build();

        let inc_button = gtk::Button::with_label("Increment");
        let dec_button = gtk::Button::with_label("Decrement");

        let label = gtk::Label::new(Some(&format!("Counter: {}", model.counter)));
        label.set_margin_all(5);

        let mut args = std::env::args();
        args.next();
        let picture = gtk::Picture::for_filename(args.next().unwrap());

        window.set_child(Some(&vbox));
        vbox.set_margin_all(5);
        vbox.append(&inc_button);
        vbox.append(&dec_button);
        vbox.append(&label);
        vbox.append(&picture);

        inc_button.connect_clicked(clone!(@strong sender => move |_| {
            sender.input(AppInput::Increment);
        }));

        dec_button.connect_clicked(clone!(@strong sender => move |_| {
            sender.input(AppInput::Decrement);
        }));

        let widgets = AppWidgets { label };

        ComponentParts { model, widgets }
    }

    fn update(&mut self, message: Self::Input, _sender: ComponentSender<Self>) {
        match message {
            AppInput::Increment => {
                self.counter = self.counter.wrapping_add(1);
            }
            AppInput::Decrement => {
                self.counter = self.counter.wrapping_sub(1);
            }
        }
    }

    /// Update the view to represent the updated model.
    fn update_view(&self, widgets: &mut Self::Widgets, _sender: ComponentSender<Self>) {
        widgets
            .label
            .set_label(&format!("Counter: {}", self.counter));
    }
}

fn main() {
    let app = RelmApp::new("relm4.test.simple_manual");
    app.run::<AppModel>(0);
}

All you have to do is:

  1. Install Rust.
  2. Create a directory, say, dummy.
  3. Enter this directory and run cargo init.
  4. Add dependencies: cargo add [email protected] [email protected].
  5. Replace src/main.rs with the above code.
  6. Run cargo run /path/to/your/image.jpg, using the path to any image.

See if you can see your image in this example GTK app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants