A bit tied up with the IP issue (and maybe a bigger one) is how time accounting works: anything you are required to do as part of teaching your courses, such as actually teaching them and preparing materials for them, must generally be budgeted as "teaching time". This must usually be paid by the institution's own budget (not by grants), and the % teaching time is also a headline figure people use to compare job offers. Things not part of the official teaching duties generally fall into either "research time" (perform experiments, write papers & books, present results) or "service" (serve on committees, review papers, etc.).
Currently writing textbooks is classified as "research", considered entirely the professor's own initiative, and therefore done either as part of a regular year's research time, or during a sabbatical (which is a period of 100% research time). If you reclassified textbook writing to be part of "teaching", i.e. your official teaching duties when assigned to teach a course involve not only teaching the course but also writing a textbook for it, you'd need to budget sufficient time to write the book into the teaching budget. This would typically require either reducing the number of courses the professor teaches per semester, or increasing the % of their time which is budgeted as teaching. Institutions are generally reluctant to do either of those, for a mixture of budgetary reasons (teaching is usually paid internally) and recruiting reasons (if you have an 80% teaching load at your university, you will have trouble recruiting researchers who have offers from 50%-teaching-load institutions, or from corporate research labs).
'preparing materials for them, must generally be budgeted as "teaching time". This must usually be paid by the institution's own budget (not by grants)'
So, do teaching materials prepared during 'teaching time' become the IP of the employer?
Currently writing textbooks is classified as "research", considered entirely the professor's own initiative, and therefore done either as part of a regular year's research time, or during a sabbatical (which is a period of 100% research time). If you reclassified textbook writing to be part of "teaching", i.e. your official teaching duties when assigned to teach a course involve not only teaching the course but also writing a textbook for it, you'd need to budget sufficient time to write the book into the teaching budget. This would typically require either reducing the number of courses the professor teaches per semester, or increasing the % of their time which is budgeted as teaching. Institutions are generally reluctant to do either of those, for a mixture of budgetary reasons (teaching is usually paid internally) and recruiting reasons (if you have an 80% teaching load at your university, you will have trouble recruiting researchers who have offers from 50%-teaching-load institutions, or from corporate research labs).