Setting up Primariy Monitor

Hello Friends,

after the introduction of lua to hyprland it made sense for me to finally start switching from gnome to hyprland (custom layouts). Now, I want to set up a monitor as my primary monitor, but I am not yet familiar on how to do it properly. I was thinking about moving the mouse on the event of hyprland.start to the primary monitor, because this is essentially all I need for it being sensibly set up.

If there is a more idiomatic version of achieving the same thing, I’d be happy to learn about it. My current attempt looks as follows, including my workspace and monitor configuration:

– LG OLED TV
hl.monitor({
output = “HDMI-A-1”,
mode = “3840x2160”,
position = “0x0”,
scale = 1,
})

– LG Monitor
hl.monitor({
output = “DP-1”,
mode = “3840x2160”,
position = “3840x0”,
scale = 1.6,
})

hl.workspace_rule({
workspace = “2”,
monitor = “HDMI-A-1”,
layout = “lua:6_zones”,
default = true,
})

hl.workspace_rule({
workspace = “1”,
monitor = “DP-1”,
layout = “lua:split_33_67”,
})
 – At Hyprland Start
hl.on(“hyprland.start”, function()
hl.dsp.exec_cmd(“ags run ~/.config/ags/app.ts”)
hl.timer(function()
hl.dsp.cursor.move({ x = 1920, y = 1080 })
hl.notification.create({
text = “mouse moved now”,
timeout = 10000,
icon = “ok”,
})
end, { timeout = 4000, type = “oneshot” })
end)

Even for the case that there is a better method to achieve the same, I’d be interested to know, why my cursor.move does not move my cursor at startup, also my ags does not trigger at hyprland start, but I checked with the notification that the code actually runs.

Thanks in advance

There is one small problem though, I’m not sure whether it affects or not, your config has UTF-8 text in the config please replace it with actual quotes.
You can use editor like vscode, kate or something like that to edit it if you are unfamiliar with vim, neovim, or nano make sure the config isn’t full of UTF-8 texts when assigning values.
Also it looks comments were missed with -, IG you didn’t copy it properly.
I recommend looking into lua docs.

I will rewrite the rules for you

-- LG OLED TV
	hl.monitor({
	output = "HDMI-A-1",
	mode = "3840x2160",
	position = "auto",
	scale = 1,
})

-- LG Monitor
	hl.monitor({
	output = "DP-1",
	mode = "3840x2160",
	position = "auto-right", -- you can use auto-right to automatically set it
	scale = 1.6,
})

Also send me output of hyprctl monitors all -j, and explain me their positions.

1 Like

Thank you very much. So using double quotation marks is a problem? I am writing using a German keyboard and I am more used to use double quotation marks, since it never really mattered whatever language I programmed it. If it is important to not do that, I will take care to change all double quotations to single quotations.

The comments were kind of destroyed when copying, idk, but in my file I actually commented out correctly.

This is the requested output:

[{
“id”: 0,
“name”: “DP-1”,
“description”: “LG Electronics LG Ultra HD 0x00005EE8”,
“make”: “LG Electronics”,
“model”: “LG Ultra HD”,
“serial”: “0x00005EE8”,
“width”: 3840,
“height”: 2160,
“physicalWidth”: 600,
“physicalHeight”: 340,
“refreshRate”: 59.99700,
“x”: 3840,
“y”: 0,
“activeWorkspace”: {
“id”: 1,
“name”: “1”
},
“specialWorkspace”: {
“id”: 0,
“name”: “”
},
“reserved”: [0, 54, 0, 0],
“scale”: 1.60,
“transform”: 0,
“focused”: false,
“dpmsStatus”: true,
“vrr”: false,
“solitary”: “0”,
“solitaryBlockedBy”: [“WINDOWED”,“CANDIDATE”],
“activelyTearing”: false,
“tearingBlockedBy”: [“NOT_TORN”,“USER”,“CANDIDATE”],
“directScanoutTo”: “0”,
“directScanoutBlockedBy”: [“USER”,“CANDIDATE”],
“disabled”: false,
“currentFormat”: “XRGB8888”,
“mirrorOf”: “none”,
“availableModes”: [“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”],
“colorManagementPreset”: “srgb”,
“sdrBrightness”: 1.00,
“sdrSaturation”: 1.00,
“sdrMinLuminance”: 0.20,
“sdrMaxLuminance”: 80,
“hardwareCursorsInUse”: true
},{
“id”: 1,
“name”: “HDMI-A-1”,
“description”: “LG Electronics LG TV SSCR2 0x01010101”,
“make”: “LG Electronics”,
“model”: “LG TV SSCR2”,
“serial”: “0x01010101”,
“width”: 3840,
“height”: 2160,
“physicalWidth”: 1600,
“physicalHeight”: 900,
“refreshRate”: 60.00000,
“x”: 0,
“y”: 0,
“activeWorkspace”: {
“id”: 2,
“name”: “2”
},
“specialWorkspace”: {
“id”: 0,
“name”: “”
},
“reserved”: [0, 54, 0, 0],
“scale”: 1.00,
“transform”: 0,
“focused”: true,
“dpmsStatus”: true,
“vrr”: false,
“solitary”: “0”,
“solitaryBlockedBy”: [“WINDOWED”,“CANDIDATE”],
“activelyTearing”: false,
“tearingBlockedBy”: [“NOT_TORN”,“USER”,“CANDIDATE”],
“directScanoutTo”: “0”,
“directScanoutBlockedBy”: [“USER”,“CANDIDATE”],
“disabled”: false,
“currentFormat”: “XRGB8888”,
“mirrorOf”: “none”,
“availableModes”: [“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”,“[email protected]”],
“colorManagementPreset”: “srgb”,
“sdrBrightness”: 1.00,
“sdrSaturation”: 1.00,
“sdrMinLuminance”: 0.20,
“sdrMaxLuminance”: 80,
“hardwareCursorsInUse”: true
}]

Also I recommend looking into this monitor page in hyprland wiki.

hl.monitor({
	output = "HDMI-A-1",
	-- output = "desc:LG Electronics LG TV SSCR2 0x01010101", -- use this if you want config only for this monitor
	mode = "[email protected]" -- highres -- use the highres for automatically selecting 4K
	position = "auto",
	scale = 1.6, -- change scale if you want to, I usually go with 2
})

hl.monitor({
	output = "DP-1",
	-- output = "desc:LG Electronics LG Ultra HD 0x00005EE8", -- use this if you want config only for this monitor
	mode = "[email protected]" -- highres -- use the highres for automatically selecting 4K
	position = "auto-right", -- don't hesitate to change positions
	scale = 1,
})

You can try dynamically setting rules like this

$ type hdmi_disable
hdmi_disable is an alias for hyprctl eval 'hl.monitor({ output = "HDMI-A-1", disabled = false })'

syntax is like this

hyprctl eval '-- the rule here'
1 Like

This unfortunately did not do the trick. It just switched the order of the monitors, weirdly enough conversly to what I expected, so the left monitor was right and vice versa.

Like the only thing I want to achieve is that the mouse is located at the HDMI-A-1 display, as if I would have set up a primary display in another distro. Such that I dont need to pickup the mouse to pull it over to the other display to only then use the keyboard to make use of the nice keybindings.

Maybe to explain a little more on my setup, I want to have fixed layout rules for monitors, that is why I fixed the workspaces to monitors. Idk if this is the best solution in the long run, but for now this gives me a good start and I am able to have my workflow I want to see.

can you just swap those positions, since you said they just were swapped, you can swap it back to normal change auto to auto-right and auto-right to auto

Try running hyprctl reload few times to reload config if it’s not working even after that try to logout and login.

1 Like

so choosing auto left for the HDMI display actually preserved the desired order. (using auto right anywhere did always arrange the monitors in the wrong order)

But the mouse issue is still there, so the mouse is not placed on my desired “primary” monitor

for setting up workspace I think use default = true under the monitor try adding that line to one of the monitor if it doesn’t work then remove it and add to the other one, you can refer this

1 Like

as far as I know the default option for the workspace rules just sets which workspace is the default one for a given monitor

I played around with that option, because it seemed intuitively to be the option to use, but its unfortunately not. Idk why its so difficult to set a primary display. Maybe I am getting something wrong?

Try this, it was already in your config try moving the to the monitor and get the position using sleep 10 ; hyprctl cursorpos then add those coordinates instead of x and y. you can divide monitor height and width by 2 get center position like this (offset_w + monitor_w / 2, offset_h + monitor_h / 2)

could you help me out a little on what was wrong with my approach to move the cursor? I added a sleep and it should do that at hyprland.start. But it does not actually do it

hl.on(“hyprland.start”, function()
    hl.dsp.exec_cmd(“ags run ~/.config/ags/app.ts”)
    hl.timer(function()
        hl.dsp.cursor.move({ x = 1920, y = 1080 })
        hl.notification.create({
            text = “mouse moved now”,
            timeout = 10000,
            icon = “ok”,
        })
    end, { timeout = 4000, type = “oneshot” })
end)

I can see the notifcation, but the cursor just wont move

hyprctl eval 'hl.timer(function() hl.dsp.cursor.move({x=0,y=0}) end,{timeout=1000, type="oneshot"})' # doesn't work
ok
~ $ hyprctl eval 'hl.timer(function() hl.dispatch(hl.dsp.cursor.move({x=0,y=0})) end,{timeout=1000, type="oneshot"})' # works

add hl.dispatch(hl.dsp.cursor.move({x = 1920, y=1080})) also you don’t need to keep value as 4000 it’s just for testing purpose by slowing down things.

you can test some configs by using hyprctl eval like this

hyprctl eval 'hl.timer(function() hl.dispatch(hl.dsp.exec_cmd("alacritty")) end,{timeout=2000, type="oneshot"})'
1 Like

Thanks for helping out, I figured it out. So here are my takeaways:

  • the cursor will move only within the focused window, thus I need to focus another window/workspace
  • when starting hyprland, the windows and workspaces are not really setup fully, so a timer is needed

my working solution is now the following:

hl.on("hyprland.start", function()
	hl.timer(function()
		hl.dsp.focus({ workspace = 2 })
		hl.dispatch(hl.dsp.cursor.move({ x = 1920, y = 1080 }))
	end, { timeout = 100, type = "oneshot" })
end)
1 Like