Tomas-M / xlunch

Graphical app launcher for X with minimal dependencies
http://xlunch.org
GNU General Public License v3.0
219 stars 37 forks source link

Center the icons #58

Closed Tomas-M closed 6 years ago

Tomas-M commented 6 years ago

I would like to use xlunch also as a confirmation dialog for the user to select Logout/Shutdown/Restart option. In this scenario, there are only 3 icons and no prompt. I would like to be able to center the icons in the center of the screen, but I do not know the screen dimmensions of the user's monitor.

I could possibly use xrandr in a script to find out the current dimmensions of current screen resolution, and add proper border, so after I specify --columns 3, it would be at the center. But I am wondering, would it be somehow reasonably simple to make xlunch do the calculation, in order to center the specified columns of icons (plus their leastmargin) by calculating the border?

So user would specify --center --columns 3 --rows 1 --leastmargin 20 and xlunch would compute proper border, overiding possible border value specified by the user.

As a side effect, if the user for example prefers to have the icons slightly up, he can specify --rows 2 and it would calculate the border as like if there were two rows, putting the icons halfway up, while only showing one row. This could be very powerfull.

@PMunch, are you in the mood of trying this? :-) It is way too complicated for me to do it right :) This would bring xlunch to yet another level since it could be used for different types of dialogs.

PMunch commented 6 years ago

Hmm, I think maybe --center <ratio>,<ratio> might be better. So for normal centering you would do --center 0.5,0.5, or if you wanted it a bit higher up --center 0.5,0.4. That way it would be customisable without an unintuitive hack.

Tomas-M commented 6 years ago

I would rather separate the two ratios then.

Use --hcenter and --vcenter to set horizontal and vertical center point (given as number 1-100). I don't like fractions like 0.5

And --center could affect both sides, so for example --center 50 would mean middle of the screen.

PMunch commented 6 years ago

That would be a bit strange though as --center 30 would be 30% from both left and top. --center could be a simpler way to do --hcenter 50 --vcenter 50, but without a short option (we're running out of those :P)

Tomas-M commented 6 years ago

Yeah you are completely right, --center alone as a shorthand for --hcenter 50 --vcenter 50 is perfect :) You going implement it? I am still afraid to do that myself :)

PMunch commented 6 years ago

I'll look into it. If it doesn't require a complete rewrite of the system I'll do it :)

Tomas-M commented 6 years ago

Thank you very much! hope you could find some time this week :)

Tomas-M commented 6 years ago

Instead of the complicated method we discussed earlier, I would suggest different solution. What if we change default behavior of xlunch when --leastmargin is specified? So, if user specifies both leastmargin and columns or rows, we can consider that as if the user wanted to center things.

Like this:

diff --git a/xlunch.c b/xlunch.c
index f5a6c7f..896f9e1 100644
--- a/xlunch.c
+++ b/xlunch.c
@@ -196,11 +196,19 @@ void recalc_cells()
         columns = usable_width/margined_cell_width;
     } else{
         columns = ucolumns;
+        if (least_margin > 0) {
+           side_border = (screen_width - margined_cell_width*columns - least_margin)/2;
+           usable_width = screen_width - side_border*2;
+        }
     }
     if (urows == 0){
         rows = usable_height/margined_cell_height;
     } else{
         rows = urows;
+        if (least_margin > 0) {
+           border = (screen_height - margined_cell_height*rows - least_margin)/2;
+           usable_height = screen_height - border*2;
+        }
     }
     // If we don't have space for a single column or row, force it.
     if (columns == 0) { 

What do you think? I'm ready to commit this.

PMunch commented 6 years ago

Hmm, not a huge fan. First off I don't like having one option mean two things, makes things less obvious. The name leastmargin doesn't imply anything about centering. Plus it would be cool to have the possibility to specify where to put the icons with a ratio. I was also thinking about what to do if we had more than one row of icons, should the next row also be centered? I'm thinking yes, that's what seems most natural to me.

Tomas-M commented 6 years ago

My problem is that I need some solution asap. I agree with your arguments, so i'll make a separate parameter for my behavior.

PMunch commented 6 years ago

Yeah, just make it center and then we can adjust the behaviour later :)

Tomas-M commented 6 years ago

Implemented in 7e0de253faf3edecb0defa0c5d2eefbdebc23311