Skip to content

Commit

Permalink
Exposes monitor names (#706)
Browse files Browse the repository at this point in the history
This exposes monitor names to gobject introspection via MetaDisplay.
  • Loading branch information
Cobinja authored Nov 28, 2024
1 parent 02fce99 commit cc584a7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/core/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -3718,6 +3718,50 @@ meta_display_get_primary_monitor (MetaDisplay *display)
return 0;
}

/**
* meta_display_get_monitor_name:
* @display: a #MetaDisplay
* @monitor: the monitor number
*
* Return value: (transfer none): the monitor vendor name
*/
const gchar*
meta_display_get_monitor_name (MetaDisplay *display,
int monitor)
{
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
#ifndef G_DISABLE_CHECKS
int n_logical_monitors =
meta_monitor_manager_get_num_logical_monitors (monitor_manager);
#endif

g_return_val_if_fail (META_IS_DISPLAY (display), NULL);
g_return_val_if_fail (monitor >= 0 && monitor < n_logical_monitors, NULL);

GList *l;

for (l = monitor_manager->logical_monitors; l; l = l->next) {
MetaLogicalMonitor *other = l->data;

if (other->number != monitor) {
continue;
}

GList *m;
for (m = other->monitors; m; m = m->next)
{
MetaMonitor *monitor = m->data;
const char* name = meta_monitor_get_display_name (monitor);
if (name != NULL) {
return name;
}
}
}
return NULL;
}

/**
* meta_display_get_monitor_geometry:
* @display: a #MetaDisplay
Expand Down
4 changes: 4 additions & 0 deletions src/meta/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ int meta_display_get_primary_monitor (MetaDisplay *display);
META_EXPORT
int meta_display_get_current_monitor (MetaDisplay *display);

META_EXPORT
const gchar* meta_display_get_monitor_name (MetaDisplay *display,
int monitor);

META_EXPORT
void meta_display_get_monitor_geometry (MetaDisplay *display,
int monitor,
Expand Down

0 comments on commit cc584a7

Please sign in to comment.