Skip to content

Conversation

@bv-saketha-rama
Copy link

Solves #1906

Changes

  1. Added Settings Constant (SettingNames.cs)
    internal const string SINGLE_INSTANCE_MODE = "single-instance-mode";

  2. Conditional Application Flags (Main.cs)
    `// Check if single-instance mode is enabled
    var settings = new SettingsManager ();
    bool singleInstance = settings.GetSetting (SettingNames.SINGLE_INSTANCE_MODE, false);

// Use appropriate flags based on preference
var flags = singleInstance ? Gio.ApplicationFlags.HandlesOpen
: Gio.ApplicationFlags.NonUnique;
var app = Adw.Application.New (PintaCore.ApplicationId, flags);`

  1. OnOpen Event Handler (Main.cs)
    // Handle file opening in existing instance if (singleInstance) { app.OnOpen += (_, args) => { main_window.Activate (); foreach (var file in args.Files) PintaCore.Workspace.OpenFile (file); }; }

Behaviour

  • Disabled (default): Multiple windows, backward compatible
  • Enabled: All files open as tabs in one window
  • Configuration: Edit ~/.config/Pinta/settings.xml:
    <setting name="single-instance-mode" type="System.Boolean">True</setting>

var app = Adw.Application.New (PintaCore.ApplicationId, Gio.ApplicationFlags.NonUnique);

// Check if single-instance mode is enabled
var settings = new SettingsManager ();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this could use PintaCore.Settings instead to avoid creating another SettingsManager (and reloading the settings from disk again)

The line below uses PintaCore.ApplicationId so it should be safe to run the static constructors at this point


// Check if single-instance mode is enabled
var settings = new SettingsManager ();
bool singleInstance = settings.GetSetting (SettingNames.SINGLE_INSTANCE_MODE, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'd need to find some way of configuring this setting in the GUI. If it requires editing the xml settings then it may as well not exist for the vast majority of users :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's right

};

// Handle file opening in existing instance when single-instance mode is enabled
if (singleInstance) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing on macOS the single-instance mode didn't seem to work, and multiple instances were launched. I'm not sure if this is a GTK limitation ..
Which platform(s) were you testing on?

Copy link
Author

@bv-saketha-rama bv-saketha-rama Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it on linux system. I will check it again if I made any mistake.

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 this pull request may close these issues.

2 participants