Skip to content

Implement configuration profiles #128

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

Closed
wants to merge 4 commits into from
Closed

Conversation

foxharp
Copy link

@foxharp foxharp commented Oct 28, 2024

I really like the simplicity of lxterminal's text config file -- it makes it much easier to get going on a new machine if I can just copy the config into place, rather than having to configure multiple settings via menu or dconf. But I also have a need for several different configs (mostly font-size changes, and colors) for different styles of terminal. So this small patch implements terminal "profiles". It's very simple.

All instances of lxterminal invoked with the same "--profile=NAME" argument will share a config file (lxterminal-NAME.conf), and a socket (which is renamed in a similar way).

I'm happy to rework this, of course, if there are details that you'd prefer be changed.

Also, I included new versions of both lxterminal.xml and lxterminal.1, which I now realize was perhaps incorrect.

All instances of lxterminal invoked with the same --profile=NAME
argument will share a config file (lxterminal-NAME.conf), and socket.
@ib ib added the question label Oct 28, 2024
@ib
Copy link
Member

ib commented Oct 28, 2024

At a quick glance:

  • lxterminal-PROFILE.conf should probably read lxterminal-NAME.conf
  • gchar * profile isn't freed (should be NULL by default)
  • it is probably easier to set and use arguments->profile to create config_filename

@foxharp
Copy link
Author

foxharp commented Oct 28, 2024

Thanks for your comments.

Agreed on: lxterminal-PROFILE --> lxterminal-NAME. That was an oversight.

[Having written the following description, it's clear to me that the global "profile" should definitely be renamed, perhaps to "profile_string", to make it explicit that it's different than what was passed to the command-line argument.]

The default value of the profile global needs to be the empty string, i.e. "", not NULL. When set, it will contain the profile's name, plus an extra leading '-' character, due to the sprintf at lxterminal.c:1549. This makes the construction of the full config filename, and the full socket name, work easily with just a single sprintf -- e.g., the file name will be either "lxterminal.conf" or "lxterminal-myname.conf", without any extra logic. Using address->profile directly would involve extra conditionals to provide the '-' or not.

Also, because the socket name and file name may be needed repeatedly over the life of the process, I don't think profile should ever be freed. I think the only leak that can occur is if the --profile argument is given more than once. And I believe this is the case for any of the string-valued argments.

paul

Renamed variable, and added comments, to make its role more obvious.
@ib
Copy link
Member

ib commented Oct 28, 2024

The default value of the profile global needs to be the empty string, i.e. "", not NULL.

Of course, but you can't free it that way. Why not using profile_string ? profile_string : ""?

You don't need to add comments to make its role more obvious.

@foxharp
Copy link
Author

foxharp commented Oct 28, 2024

Why would I free it? Losing one byte of data because it's no longer pointed to is really not a big deal.

But this isn't my codebase, so I'm more than happy to change it. :-)

@foxharp
Copy link
Author

foxharp commented Oct 28, 2024

(and yes, I know that the static initializer can't be freed anyway)

@ib
Copy link
Member

ib commented Oct 29, 2024

We may be talking at cross purposes.

Why would I free it?

Because you are allocating memory with g_strdup_printf().

Instead of profile_string ? profile_string : "", it may be more straightforward to do profile_string = g_strdup("") if --profile isn't specified.

@foxharp
Copy link
Author

foxharp commented Oct 29, 2024

Just because I'm allocating it with g_strdup_printf() doesn't mean it will be freed. As I said earlier, that memory must never be freed, because the string it contains might be needed at any time. (At least, that's how I currently understand the code. Perhaps I've missed something?) But perhaps your concern is that the code will change and someone will then want to free it?

@foxharp
Copy link
Author

foxharp commented Oct 29, 2024

I think I will (after hearing from you) switch to using profile_string = g_strdup(""), since it will clean up the code a bit.

Is there anything else about the pull request that should change? Should I remove the change to lxterminal.1 ? I created it "by hand", so it may not match what the tools would produce, though I think it's syntactically correct. But I don't even know if that placeholder should be modified.

Once you approve, I'd prefer to create a new pull request (or, modify this one?) to collapse my changes into one commit. But I'll defer to your opinion on whether I should or not.

@ib
Copy link
Member

ib commented Oct 29, 2024

There is only a small diff to your lxterminal.1 after rebuilding from xml:

--- a/man/lxterminal.1
+++ b/man/lxterminal.1
@@ -75,7 +75,7 @@ Set the terminal\*(Aqs working directory\&.
 .PP
 \fB\-\-profile=\fR\fB\fINAME\fR\fR
 .RS 4
-If set, then all instances of lxterminal invoked in the same way will share a config file named lxterminal-NAME.conf\&.
+If set, then all instances of lxterminal invoked in the same way will share a config file named lxterminal\-NAME\&.conf\&.
 .RE
 .SH "AUTHOR"
 .PP
@@ -90,7 +90,7 @@ General Public License, Version 2 any later version published by the Free Softwa
 On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common\-licenses/GPL\&.
 .SH "FILES"
 .PP
-The configuration file can be found in ~/\&.config/lxterminal/lxterminal\&.conf, or lxterminal-NAME.conf\&.
+The configuration file can be found in ~/\&.config/lxterminal/lxterminal\&.conf, or lxterminal\-NAME\&.conf\&.
 .SH "AUTHOR"
 .PP
 \fBYing\-Chun Liu\fR

And yes, there should be a pre-generated man page.

Apart from that, please wait until I find time to get back to lxterminal.

@ib
Copy link
Member

ib commented Dec 10, 2024

Please take a look at this.

I think that the profile belongs to the terminal window instead of a global variable, so I put it in the LXTerminal structure where it can be freed after the window is closed. (Unlike the global variable, which is allocated new memory each time it is used.)

It also seems clearer to me to pass the profile as an argument to the setting functions and the socket creation function (even if it makes the commit a bit more complex).

What do you think?

@foxharp
Copy link
Author

foxharp commented Dec 10, 2024 via email

@ib
Copy link
Member

ib commented Dec 10, 2024

I'm a little confused by this: the profile is shared by all windows
that were started from the same process, correct? So it feels like
there's no reason for it to be copied into every window structure.

It seems to be the only way to get the profile in terminal_preferences_dialog() to save the settings. Or am I missing something?

@foxharp
Copy link
Author

foxharp commented Dec 10, 2024 via email

@ib ib removed the question label Dec 13, 2024
@ib
Copy link
Member

ib commented Dec 13, 2024

Although the implementation is a bit different now, thank you very much for your contribution.

@ib ib closed this Dec 13, 2024
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